Publish/Subscribe Python Example

Remote temperature data acquisition

Pub Sub Python Temp Data

import time
import os
import sys
na_python_dir = os.environ.get("NAWCTDIR") + "\\Python"
sys.path.append(na_python_dir)

from NaException import NaException
from NA_Server import NA_Server
from NA_Credentials import NA_Credentials
from NA_Connection import NA_Connection
from NA_Subscription import NA_Subscription

def main(argv):

server = NA_Server("netacquirehost")
sub = NaServer.GetSubscription("reactor_temperature")

# can now access real-time decommutated data as a regular Python variable!
print ("Temperature: " + sub)

if __name__ == "__main__":
sys.exit(main(sys.argv))

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 server. The second line retrieves an object that represents a specific data subscription. Subscriptions can be given convenient names on the NetAcquire server. In this case, the subscription represents an analog voltage from a reactor temperature sensor. Once a subscription is obtained, the current value of the subscription can be displayed at any time as illustrated by the final print line.

When using the subscription object directly in an output stream as done here the implementation displays all the information associated with the subscription (name, type, raw value, timestamp, etc.). For more control over the display of the raw data 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.

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.

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

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