TCPSocket

The TCPSocket class is included in the Q-SYS Designer Software's implementation of Lua. It will bind a TCP/IP socket for use on the Q-SYS Core when the design is deployed, following the network configuration of the Core for network interface access. Documentation of the TCPSocket Class is found here.

This example builds a TCPSocket and uses it to communicate with a remote device. The example device uses an ASCII string call response interface, with a login and password prompt and ping response that are built into the example.

The TCPSocket framework above can then be integrated for further functionality. This framework binds the TCP socket responses to helper functions. Send() and ParseResponse can be extended and used to integrate the remote communication into the local script.

This socket’s ParseResponse() uses the ReadLine( TCP.EOL.Lf ) function call to pull a full line of data from the TCPSocket’s buffer. When a TCP packet is received, the data is buffered and ReadLine() pulls a complete line, leaving incomplete messages in the buffer. If an EOL character is not part of the remote device’s API, the Read( bytes ) function can be used instead. An example of using the Read() function is shown in the plugin code.

The following code can be built into a plugin, starting from the Basic Plugin Framework. The TCP client example is built into the runtime.

Tip: This is a common type of interface needed. The Authentication and polling command can be updated to meet the needs of a real device.