NetAcquire Publish/Subscribe C Example
Remote temperature data acquisition
netacquire1 = naps_open("na1");
reactor_temperature = naps_subscribe(netacquire1, "reactor_temperature");
printf("Reactor temperature: %lf\n", temperature);
The main function declares two variables to represent a data publisher and a specific data subscription, respectively. 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; 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 by the printf statement.
In the example, the value of the subscription is retrieved using an accessor that returns a 64 bit real value. Accessors with different return types are also available, integers of width 8, 16, 32, and 64 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.
In addition to keeping subscriptions automatically up-to-date, NetAcquire Publish/Subscribe can also notify applications when the value of a subscription changes (see the C notification example).