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++ Example

Remote temperature data acquisition 

Publisher and Subscriber Hardware Diagram


   #include <iostream>
   #include "naps.hpp"

   int main()
   {
     NA_Connection netacquire1("na1");
     NA_Subscription reactor_temperature(netacquire1, "reactor_temperature");

     cout << "Reactor temperature: " << reactor_temperature << endl;
   }

This fully functional example illustrates a complete application requiring only three lines of publish/subscribe executable code.

The first line of the main program creates an object that represents a data publisher. The second 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 final cout line.

When inserting a subscription object directly into an output stream as done here the implementation formats the value using the most suitable type for the published quantity. For more application control over the data type one can retrieve the subscription's value using an explicit accessor. Integers of width 8, 16, 32, and 64 bits as well as 32 and 64 bit floating point types are supported.

Notice that there is no "clean-up" code at the end of this example; NetAcquire Publish/Subscribe automatically handles all memory and buffer deallocation and network shutdown.

The above example illustrates that NetAcquire Publish/Subscribe automatically keeps the value of the variable reactor_temperature up-to-date without any coding on the application's part. In fact, NetAcquire subscriptions can be used just like regular C++ variables and the "value" of these variables always reflects the remote measurement on the NetAcquire. In the following example two subscription variables are used as if they were variables of type double.


   #include <iostream>
   #include "naps.hpp"

   int main()
   {
     NA_Connection netacquire1("na1");
     NA_DoubleSubscription reactor_temp1(netacquire1, "reactor_temperature1");
     NA_DoubleSubscription reactor_temp2(netacquire1, "reactor_temperature2");

     // can perform other activities here...

     // compute the average temperature based on the most recent acquired data
     double average_temp = (reactor_temp1+reactor_temp2)/2.0;
   }

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


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.
webmaster@netacquire.com