Screenshots     Download     Pricing     Docs     Tutorials     Resources     Contact     Forum     Search  

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

  • [variable] - send/receive a variable as ascii text. See Expressions that show more about variable calculations.
  • \\[variable] - send/receive a 4 byte binary value (intel format)
  • //[variable] - send/receive a 4 byte binary value (mac format)
  • \[variable] - send/receive a single byte binary value
  • \b[variable] - send/receive a single byte binary value
  • \w[variable] - send/receive a two byte binary value
  • \d[variable] - send/receive a four byte binary integer value
  • \f[variable] - send/receive a four byte binary float/decimal value
  • \F[variable] - send/receive an eight byte binary float/decimal value
  • \5[variable] - receive an 5 byte text string (replace 5 with appropriate number)
  • \i[variable] - send variable value as an integer ascii string
  • \x0f - send a hexidecimal byte value (15 in this case)
  • \x0f0f - send a hexidecimal two byte value (3855 in this case)
  • \o11 - send a octal byte value (9 in this case)
  • \o1234 - send a octal two byte value (668 in this case)
  • [[ - send a '[' single character without parsing for any variables
  • \\ - send a '\' single character without parsing for escape characters
  • <gray_image> - send current image as single gray channel
  • <rgb_image> - send current image as RGB triplet
  • <cr> - send/receive a carriage return (decimal 13, hex 0D)
  • <lf> - send/receive a line feed (decimal 10, hex 0A)
  • <tab> - send/receive a tab (decimal 9, hex 09)
  • <sp> - send/receive a space (decimal 32, hex 20)

See Also


Serial
USB HID
Socket Client
Socket Server
Execute Program
Write Text


 New Post 
Text_Formats Related Forum PostsLast postPostsViews
None




© 2005 - 2017 RoboRealm. All Rights Reserved. | Contact | Privacy | Disclaimer | Link to Us |