Using the WRITE Command

Have you ever wanted to sync contacts with your stapler? Maybe not, but the point is, we live in a world of blossoming interconnectivity where you could probably do just that.

In such a connected world, it's increasingly important (and convenient) to keep systems in-touch and in-sync. We've thought about this a lot here at Interactive which is why CueServer has long been "plugged-in" to the internet of things, supporting external communications with devices over an array of protocols such as UDP, serial or telnet.

How about TCP? Well, REST assured that as of CueServer v3.1.1, TCP has joined the list. Today, we're giving you the rundown on the 'WRITE' command and how you can use it to connect to API endpoints on everything from smart-phones to smart-staplers.

If you're looking for the in-depth technical details, take a look at this section of the user's manual.

The Breakdown

We'll cover the four ways to WRITE with CueServer below.

Follow along below, or jump ahead using the index below:

The Walkthrough

Basic Syntax

 

The write command employs the basic syntax:

Write [port] [string]

 

The [port] parameter can be any of the following:

    • COM1 -- RS-232
    • COM2 -- RS-485
    • IP -- UDP to the specified IP over port 52737
    • IP:PORT -- UDP to the specified IP and port
    • MULTICAST-IP:PORT -- UDP to multicast group address over the specified port
    • URL/CURL -- TCP Request to the specified target

 

The [string] parameter is the string to be written to the provided port.

 

Strings may also include escape characters. See the chart to the right for valid characters.

Escape Sequence Hex Value Character Represented
\a 0x07 Alarm/Bell
\b 0x08 Backspace
\f 0x0C Formfeed
\n 0x0A Newline
\r 0x0D Carriage Return
\t 0x09 Horizontal Tab
\v 0x0B Vertical Tab
\\ 0x5C Backslash
\' 0x27 Single quotation mark
\" 0x22 Double quotation mark
\xhh 0xhh Any hexadecimal byte
\nnn 0xoo Any octal byte

Writing to RS-232 & RS-485

 

Writing to the RS-232 and RS-485 port with the WRITE command is initiated with the [port] identifiers COM1 and COM2, respectively.

 

For example, to write the command "SHOW START" over the RS-232 or RS-485 port, you would use:

Write COM1 "SHOW START"

Write COM2 "SHOW START"

 

If you needed to add a carriage return following the string, you would append a \r like so:

Write COM1 "SHOW START\r"

Write COM2 "SHOW START\r"




Writing UDP Packets

 

Writing to UDP is specified by using an IP in the [port] argument.

All UDP messages sent from CueServer are sent over the port 52737 by default when a port number is not specified.

Port numbers are specified by appending a colon : followed by the desired port number to the IP address.

 

Directed Messages

Writing a directed message is as simple as using the IP you want to direct the message to:

 

Write "10.0.1.100" "SHOW START" will send the string "SHOW START" via UDP to the IP 10.0.1.100 over port 52737.

Write "10.0.1.100:59999" "SHOW START" will send the string "SHOW START" via UDP to the IP 10.0.1.100 over port 59999.

 

Multicast Messages

Writing to multicast is just as simple and just requires swapping in a multicast address. As with a directed UDP message, if unspecified, the message will be sent over port 52737.

 

Write "239.255.204.2" "SHOW START" will send the string SHOW START via UDP to the IP 239.255.204.2 (the CueServer Multicast Address) over port 52737 (the CueScript Port).

This message will be received by all CueServers on the network.

 

Write "239.255.204.2:59999" "SHOW START" will send the string SHOW START via UDP to the IP 239.255.204.2 over port 59999.

This message would be sent to the CueServer Multicast group, but not received as they only listen for CueScript over port 52737.

 


Writing to TCP & Making GET Requests

 

Making a TCP or GET/POST request with CueServer is slightly different, you specify URL or CURL as the port, but rather than include the destination in the port argument, you put the entirety of the request into the string argument.

For instance, to make a request to a CueServer via the CGI API, you would use:

Write CURL "http://10.0.1.100/exe.cgi?cmd=cue1go"

or 

Write URL "http://10.0.1.100/exe.cgi?cmd=cue1go"

 

While the above represents the basic functionality, they are also rather basic requests. The CURL/URL functionality supports all the options included with the Linux cURL command. For instance:

specify a user-agent

Write CURL "--user-agent 'CueServer' http://10.0.1.100/exe.cgi?cmd=ch1afl"

specify http1.0

Write CURL "-0 http://10.0.1.100/exe.cgi?cmd=ch1afl"

specify max wait time of 5 seconds

Write CURL "-m 5 http://10.0.1.100/exe.cgi?cmd=ch1afl"

 

There are many more options, to see what's available, check out the manual for URL/CURL.

Have a Tip or Trick you would like to see? Let us know!

We hope you enjoyed this Tip & Trick, and as always, if you ever have any suggestions or ideas that you would like to see
featured, shoot us an email at support@interactive-online.com and let us know!