NetAcquire Corporation Logo Image Image Image Image Image Image Image Image
NetAcquire Corporation Logo Home Search Products News Services Careers Support Contact

NetAcquire Publish/Subscribe C Notification Example

Remote temperature data acquisition 

Publisher and Subscriber Hardware Diagram

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.

 #include <stdio,h>
 #include "naps.h"

 /* callback function */
 void temperature_changed(NAPS_Event event)
    Time_stamp time;
    Real_64 temperature;

    naps_event_get_timestamp(event, &time);
    naps_event_as_real64(event, &temperature);

    printf("%I64d: %lf\n", time, temperature);

 int main(void)
    NAPS_Connection netacquire1;
    NAPS_Subscription reactor_temperature;

    netacquire1 = naps_open("na1");
    reactor_temperature = naps_subscribe(netacquire1, "reactor_temperature");
    naps_add_listener(reactor_temperature, temperature_changed);

    getchar(); /* wait until user presses <Enter> */

    return 0;

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.

Home | Search | Products | News | Services | Careers | Support | Contact | Telemetry | Range/Radar | Avionics
Aerospace Test | Communication | Remote Monitoring | Industrial Automation | Extreme | Protocol Conversion
Simulation | Hardware Overview | Analog I/O | Digital I/O | GPIB/IEEE 488 | SpaceWire | FPGA
Source Selection
| High Availability | Software Overview | WWW | Storage | Publish/Subscribe
Java | Windows | Data Flow | Time | Extensions | Decom | CCSDS | Mux/Demux | Demos

Last modified 12/2/2016
Copyright 1996 - 2016
NetAcquire Corporation
All rights reserved.