Text Formats
This document outlines the different character formats that can be used the in the Serial, USB HID, Socket Client, Socket Server, Execute, and Write Text modules. All of these modules have the ability to specify a custom string of characters to either transmit or to be used as incoming data that is to be parsed into variables. Because there are many ways this data can be represented other than just using straight text there are many escape symbols that can be used to achieve different variable parsing.
Sending Data
The default string sequence used in all the sequence entry boxes is ASCII text. To modify ASCII text to
become a binary version of the string
sequence you can use the modifier '\' similar to the C/C++ syntax. For example the hexadecimal string :
\x0f\x0f\x08\x40\xb8\x04
would transmit 15 15 8 64 184 4 as single byte binary numbers to the device. While the text string
0f0f0840b804
would transmit the ASCII codes 48 102 48 102 48 56 52 48 etc. as single byte numbers to the device. Also the octal string
\o4\o10\o44
would transmit 4 8 36 as single byte numbers to the device.
Variables can also be included using [] to surround the text. Thus
\255\0\[left_motor]\255\1\[right_motor]
would transmit the binary values (note the '\' before the '[') for left and right variables) to an SSC type device.
A single '\' will transmit a single byte that represents the variable value. In some cases you want to send a much larger number. In that case double the '\' using something like
\\[left_motor]\\[right_motor]
which would transmit a total of 8 bytes (4 bytes per number) that represents an integer 32 bits per value.
If your receiving device uses a different byte order than a PC you can use the division slash to instead reverse the order of the bytes. For example if the left_motor variable used above has a value of 66 then
\\[left_motor]
would send the four bytes as 66 0 0 0 whereas
//[left_motor]
would send the four bytes as 0 0 0 66.
Other special characters worth noting are
<lf> translates to a line feed ASCII code 10
<cr> translates to a carriage return ASCII code 13
<tab> translates to a tab ASCII code 9
To learn more about what expressions can be contained with []'s please refer to the Expressions page.
Receiving Data
To receive data in a specific format you would type in the known letters/numbers that would be expected interlaced with formatting codes that specify how unknown parts are to be read in. This allows you to specify a format string that indicates how incoming data is to be parsed and ensure that the expected format is actually seen. For example, you would use something like
\[binary_input_1]:\[binary_input_2]
which would read binary numbers delimited by a ':' and ended with \r into the two variables binary_input_1
and binary_input_2. But
[ascii_input_1]:[ascii_input_2]
would read in two ASCII numbers into the two variables.
For ARRAYS such as CIRCLES generated by the Circle shape finder the format of the data will include as
the first number the size of the array. For example in the send sequence if you use:
[CIRCLES]
the text sent will be something like:
65,173,154,20,1499,255,255,255,271,15,15,255,255,255,204,203,20,1499,255,255 ...
where 65 is the total number of numbers (not all are included in this example) of the array. Note that
the size for the CIRCLES array should always be 65 mod 13 = 0.
For binary data if you use
\\[CIRCLES]
the data sent will be something like:
\65\0\0\0\173\0\0\0\154\0\0\0\20\0\0\0\219\5\0\0\255\0\0\0 ...
Note that all numbers are 4 bytes long (due to the double \\ usage) with least significant byte first.
You can also send images as RGB triplet or a single gray (green value) of the
current image. You do this by inserting
<rgb_image>
into the send text stream. That command will be replaced with the current image. Note that you may
want to include the image dimensions before sending the image unless you always expect an exact size.
Summary
See Also
Serial
USB HID
Socket Client
Socket Server
Execute Program
Write Text
New Post
Text_Formats Related Forum Posts Last post Posts Views None