Escolar Documentos
Profissional Documentos
Cultura Documentos
Demo Application
Visual Basic 6 source code is provided that demonstrates all read and write requests.
Requests
The communications is divided into two categories: 1. Read Request. A developer would use this to read a value from the controller. 2. Write Request. A developer would use this to write a value to the controller. The requests are simple but must be formatted properly for the API to understand them. Each message starts with an STX (start of text character) and ends with an ETX (end of text character). This makes message parsing easy because it is known that a full message is contained between the two characters. The requests also contain the IP endpoint of the machine making the request. An IP endpoint is the IP address of the machine and the port that is listening for information. An example of an IP endpoint is 128.0.2.54,8001. Every request will indicate that it either wants to read a value or write a value. Finally, requests that write values also need to indicate the value to be written. All of these items are separated by pipes (|). Again, this is for ease of parsing.
Read Request
(Reading a value from the controller) The read request packet format is: <STX><this IP endpoint><separator><Read Instruction><Separator><Command><ETX> STX = ASCII character 02 ETX = ASCII character 03 Separator = | (pipe) Read Instruction = R Command = A command from the Valid Commands table Sample Read Request: localhost,8001|1|R|SV This sample request tells the API to Read the SV from the controller and send the value back to the application listening on the local machine (localhost) on port 8001.
Write Request
(Writing a value to the controller) The write request packet format is: <STX><this IP endpoint><separator><Write Instruction><Separator><Command><Separator><Set value><ETX> STX = ASCII character 02 ETX = ASCII character 03 Seperator = | (pipe) Write Instruction = W Command = A command from the Valid Commands table Set value = A value that falls in the valid range of the Valid Commands table Sample Write Request: localhost,8001|1|W|SV|225 This sample request tells the API to set SV to 225. The API will set the value and then send a message back to the local machine (localhost) on port 8001 indicating the new value. The developer can write safety checks to make sure the value was set properly and act accordingly.
Applications that connect to the API using UDP should use localhost for the loopback address rather than 127.0.0.1. In certain situations, you may need to open up the ports on your router. The API uses port 8000 by default, and the sample application uses port 8001. Every time a request (Read/Write) is sent to the controller via the API, a response is generated and sent back to the application. Responses containing an explanation point (!) indicate that there is an error. An example of this would be trying to set a value outside of the ranges listed in the Valid Commands and Ranges table. The controller can not handle more than 1 request per second. Because every request is followed by a response, it is possible to validate every request. An example of this would be setting the SV to a value and then checking the SV value in the response. Because the developer has full control over reading and writing values, tasks such as ramping, alarms, and notifications can be accomplished with little effort.