NetAcquire Publish/Subscribe Visual Basic Example
Remote temperature data acquisition
Private Sub cmbRun_Click()
Dim NAPSConnection As Long
Dim NAPSSubscription As Long
Dim temperature As Double
NAPSConnection = naps_open("na1")
NAPSSubscription = naps_subscribe(NAPSConnection, "reactor_temperature") Err = naps_as_real64(NAPSSubscription, temperature)
Debug.Print "Reactor temperature: " + CStr(temperature)
naps_close (NAPSSubscription)
naps_close (NAPSConnection)
End Sub
The above cmbRun_Click() Subroutine will be invoked when the Run button on the main form is clicked. First, it declares two variables to represent a data publisher and a specific data subscription, respectively. The third variable is used to store the subscription’s value. The first executable line opens a connection to the data publisher named “na1”. The next line creates an object that represents a specific data subscription. Subscriptions can be given convenient names on the NetAcquire server; in this case the subscription represents an analog voltage from a reactor temperature sensor. Once a subscription is created, the current value of the subscription can be displayed at any time, as illustrated in the Debug.Print statement. In the example, the value of the subscription is retrieved using an accessor that returns a 64 bit real value in the parameter. Accessors with different return types are also available, integers of width 8, 16, and 32 bits, as well as 32 and 64 bit floating point types are supported. The application can also query the subscription for the most appropriate data type.