Remote temperature data acquisition
na_python_dir = os.environ.get("NAWCTDIR") + "\\Python"
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
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__":
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.