====Python Live Data API==== This API allows you to create Python applications that utilise ARDI live data. ===Usage Example=== from ardi.api import core, subscription server = "myardisiteurl" ardi = core.ARDICore(server) ardi.Connect() sub = subscription.ARDISubscription(ardi) sub.AddCode('20:22:measurement') def ProcessNewValues(code,value): echo ' ' + code + ' = ' + str(value) sub.SetCallback(ProcessNewValues,False) sub.Connect() ===How It Works=== This is a quick breakdown of how the above example operates. 1) Create an **ARDICore** object and connect it to the ARDI server. ardi = core.ARDICore(server) ardi.Connect() This loads all of the settings of your ARDI server, including the location of the consolidator. 2) Create an **ARDISubscription** for live data, passing the ARDICore we just created. sub = subscription.ARDISubscription(ardi) This prepares the subscription by telling it the consolidator details. It does //not// connect to the server yet. 3) Add all of the [[data points|data points]] that you need to monitor sub.AddCode('20:22:measurement') You can add as many data points as you need. 4) Define and Set the Callback Function def ProcessNewValues(code,value): echo ' ' + code + ' = ' + str(value) sub.SetCallback(ProcessNewValues,False) The callback function is invoked every time a value changes. Create the function (it can be a class member if you're implementing this in a class) and call **SetCallback** on the **ARDISubscription**. 5) Start the Subscription sub.Connect() Note that the **Connect** function is a //blocking// function - it will stop the code from proceeding. If you'd like to continue with other tasks, we suggest running this function in a separate thread. If you'd like to be able to stop the function in a timely manner, we suggest installing a //signal handler//. In the handler, you can call **Disconnect** on the subscription - this will stop the subscription after a short delay and allow you to terminate the program gracefully.