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# .NET Notification Example

Remote temperature data acquisition 

Publisher and Subscriber Hardware Diagram

The example below uses the event-driven variant of the NetAcquire .NET Publish/Subscribe API. Instead of explicitly calling the subscription to obtain its latest value as was done in the simpler example, here the flow of control is reversed and the subscription calls a user-defined callback method whenever the subscription's value changes.

using System;
using netacquire.ClientToolkit.NAPS;
using netacquire.ClientToolkit;

namespace SubscribeNotificationExample
	class Example
		static void Main(string[] args)
			NAServer server = NAServer.GetServer("netacquirehost");
			Subscription sub = server.GetSubscription("reactor_temperature");
			sub.SubscriptionReceived += new SubscriptionReceivedHandler(UpdateReceived);
			sub.ListenerRemoved += new ListenerRemovedHandler(ListenerRemoved);
			sub.ConnectionLost += new ConnectionLostHandler(ConnectionLost);
			Console.ReadLine(); // wait until user presses <Enter>
		private static void ConnectionLost(Subscription sub)
			Console.WriteLine(sub.PublicationName + " lost its connection");
		private static void ListenerRemoved(Subscription sub)
			Console.WriteLine("Removed from " + sub.PublicationName);
		private static void UpdateReceived(SubscriptionEventArgs evt, Subscription sub)
			Console.WriteLine(evt.Timestamp + " : " + evt.AsReal32);

The user delegates handling of each event to one of three listener methods: UpdateReceived, ListenerRemoved, and ConnectionLost.

Note how the UpdateReceived listener method accesses the event's timestamp. Note also that an explicit accessor is used to retrieve the subscription's value in the form of a 32-bit float. One can also insert the event directly into an output stream, in which case the implementation would display all the information associated with the event (name, type, raw value, etc.).

The first and second lines of the main method represent a server and a specific data subscription. They are created exactly as in the simpler example. Then the three listeners are registered with the subscription. From this point on, the UpdateReceived method 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.