Pub Sub C Example

NetAcquire Publish/Subscribe C Example

Remote temperature data acquisition

NetAcquire Pub Sub Example Code

#include
#include "naps.h"
int main(void)
{
NAPS_Connection netacquire1;
NAPS_Subscription reactor_temperature;
Real_64 temperature;

netacquire1 = naps_open("na1");
reactor_temperature = naps_subscribe(netacquire1, "reactor_temperature");
naps_as_real64(reactor_temperature, &temperature);
printf("Reactor temperature: %lf\n", temperature);

naps_close(reactor_temperature);
naps_close(netacquire1);
return 0;
}

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).

Is NetAcquire a good fit for your project?

Our applications engineers will discuss your needs and offer advice and pricing for the solutions we can provide.
NetAcquire provides quick responses to phone and email queries during Pacific Time business hours.

Call us toll free: 888-675-1122 or email [email protected]

For Employment, Business Affairs and other NetAcquire Contacts, CONTACT US

NetAcquire Corporation