|
|
|
NetAcquire Publish/Subscribe C Notification Example Remote temperature data acquisition
The example below uses the event-driven variant of the NetAcquire Publish/Subscribe API. Instead of explicitly retrieving the subscription's latest value as was done in the simpler example, here the flow of control is reversed and the Publish/Subscribe framework calls a user-defined callback function whenever the subscription's value changes.
The user defines a customized callback function, here called temperature_changed. Note, how the callback function accesses the event's timestamp. In the main function a connection to the data publisher named "na1" is opened and an object that represents a specific data subscription is created. this is identical to the simpler example. Then the callback function is registered with the subscription. From this point on the temperature_changed function will be called whenever the physical quantity that corresponds to the subscription changes. The application's main thread can now continue with other chores, in this example it simply waits for the user to press the <Enter> key. |
|