MBLogic for an open world in automation
The Cascadas HMI protocol can also be used to access data from other applications such as custom web applications, or MRP/ERP systems. Typical applications are:
The Cascadas protocol is an open web services protocol based on JSON. Details of the protocol (including a copy of the complete specification) can be found in the "HMI" section (see "HMI" in the menu above).
Most modern programming languages have JSON parsers as part of their standard libraries, or as a freely available third party library. JSON is widely used as a standard data format and offers advantages over XML in being simpler, more compact, faster, and easier to parse.
The following example shows how to read data associated with 5 "tags". This example uses Python, but most other modern programming languages will offer similar capabilities.
#!/usr/bin/python # This shows a basic demo for a Cascadas client. # This will work with the standard HMI demo. # 29-Mar-2010. import json import urllib2 # This is the data we are going to send to the server. # We need a client id, and a message id. In addition, if we want to # read data, we need to include a list of the tags we want to read. If we want to # write data, we need to include a dictionary with the tags and values that we # want to write. basicdemo = { 'id' : 'CasDemo', 'msgid' : 0, 'read' : ['PL1', 'PL2', 'PL3', 'PL4', 'Tank1Level'], 'write' : {'PumpSpeedCmd' : -2} } # Encode the dictionary into JSON format using the standard Python library. JsonOut = json.dumps(basicdemo) # Send the data using POST. req = urllib2.Request(url = 'http://localhost:8082/', data = '', headers = {'Cascadas': JsonOut}) f = urllib2.urlopen(req) # Read the response. response = f.read() # Get the response data. We look for the blank line between the headers and # the body and assume that everything after the first blank is the data. # This is a feature of HTTP, and not something which is part of the Cascadas # protocol itself. resplist = response.splitlines() JsonIn = ''.join(resplist[resplist.index('') + 1:]) # Convert from JSON into a dictionary. respdata = json.loads(JsonIn) # We will iterate through the 'read' response and show the values that we read. # The dictionary will also contain other data (such as errors) which are not # showing here. print('Read response was') for tag, value in respdata['read'].items(): print('Tag: %s Value: %s' % (tag, value))