Reading Live Data

ARDI uses a subscription model for live data.

Instead of re-reading a list of points continuously, you subscribe to the specific set of data points you are interested in.

Then ARDI will send you responses when these values have changed.

This is handled by the Session class, which manages a subscription to one or more points of live information.

Creating a Session

Once you're connected to the ARDI server, you'll need to create a Session.

sess = ardi.Session(server)

Then, you can add Channels to your session, which represent the individual measurements you want to subscribe to.

You can subscribe to channels individually using AddChannel, like below…

pumptemp = sess.AddChannel("Main Pump","Temperature")

The code above creates a single channel containing the Temperature of the Main Pump

…or you can subscribe to multiple channels using an AQL query, using AddChannels.

temps = sess.AddChannels("'Pump' OFTYPE 'Temperature' PROPERTY VALUES')

The code above creates an array of temperature channels for every asset in your ARDI system with the type 'Pump'.

Provide a Callback Function

Since the subscription system is asynchronous, you'll need to provide a callback function that will be called every time there are new values for one or more channels.

This callback function takes a single parameter - an array of the channels that have been modified.

def DataChanged(channels):
    if pumptemp in channels:
        print("The new pump temperature is " + pumptemp.AsText())
        
sess.Callback(DataChanged)

Start the Session

Finally, the last step is to start your session.

Call Start to begin your session, which will immediately begin by calling your Callback function with the current values of your points.

Note that this is a blocking function. If you'd like to continue to perform other actions, we suggest calling Start in a different thread.

You can stop a running session by calling Stop at any time.

Complete Code

import ardi
import sys

#Setup ARDI Connection
svr = ardi.Server("demo.optrix.com.au","long")

#Connect to ARDI Server
connected = False
try:
    connected = svr.Connect()
except:
    pass

#Verify if we connected
if connected == False:
    print("Unable to Connect to ARDI Server")
    sys.exit(-1)

#Setup the session
sess = ardi.Session(svr)
closest = sess.AddChannel("Shearer","Closest Support")

#Create the callback function
def DataUpdates(updated):    
    if closest in updated:        
        print("Closest Support: " + closest.AsText())

#Start the session
sess.Callback(DataUpdates)
sess.Start()

Alternatives

You can also use the lower-level Subscription interface to subscribe to live ARDI data (which the Session object uses internally).