Serial Communication
The serial module is used to communicate from RoboRealm to serial based controllers. The module can
be used to communicate to SSC, Parallax, etc. type controllers. Before embarking on using the serial module
check that the specific device is not already supported by another RoboRealm module.
The serial module allows you to configure the serial port for various communication parameters
(baud rate, stop bits, etc.) and specify the communication protocol for initializing, sending and
receiving data. The text boxes allow you to enter in the necessary command numbers for each
respective sequence type.
Text format
The default string sequence used in all the sequence 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 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
Interface
Instructions
1. Post - select the COM port to use. Note that COM1-4 are typically assigned directly to
hardware ports. COM5+ are typically assigned to virtual ports created by USB devices.
2. Baud - specifies how fast communication will occur between the PC and serial
device. Typically rates are 9600 with the fastest being 115200. Note that if you see
irregular characters being received from the serial device this many indicate a
mismatch between baud rates.
3. Data Bits - indicate how many bits are reserved for data communication between the
serial device and the PC. Typical value is 8.
4. Parity - indicates what kind of error checking that is performed during serial
communication. Even means the last bit is set to ensure that an even number of bits
are used, whilst odd means the last bit is set to ensure that an odd number of bits
are used. When the receiving side sees a discrepancy (i.e. an odd number of bits
being transmitted when even parity is required) the device knows a transmission error
has occurred. Typical value is None.
5. Stop Bits - refer to how many bits are used to indicate a delimiter between data bits.
6. Flow Control - allows you to set the flow control options for the serial device. By default
RoboRealm sets all flow control to off/disabled. By clicking on the Flow Control button you can
set the following options
XON/XOFF for both transmission and reception
CTS/DRS (clear to send)/(data set ready)
DTR/RTS (data terminal ready)/(request to send)
7. Console - if the device supports reading you will start to see a large amount of numbers scrolling by in the console. This
shows the current values being read from the device
and provides a log of the ongoing communication activities. The green text is from RoboRealm,
the red text are characters received and the green text are characters sent by RoboRealm to the device.
To copy the log click on the Copy button, likewise to clear it click on the Clear button. Note that the
console log only shows several lines at a time with older information being discarded.
You can switch the output to various formats for better viewing:
ASCII - shows the data as ASCII characters. Any character outside of printable characters will be represented with a \ followed
by the actual integer data that was read
Decimal - shows the data as sets of single byte integer numbers
Hexadecimal - shows the data as sets of hexadecimal numbers (base 16 numbers, e.g. FF)
Short Binary - shows the data as binary numbers with prefix 0's removed
Binary - shows the data as sets of single byte binary numbers
8. Send Now - often you need to quickly test the device by sending a certain sequence of characters. To
do so just type in the character sequence (using for carriage return, [image_count] for variables, etc.)
and click on Send Now. The text will be parsed and sent to the serial device and the response will then
appear in the console log. Note that this is different from the send sequence which will be sent each time
the serial module is encountered in the processing pipeline. The Send Now button is a manual testing
mechanism meant for debugging purposes. Also note that the returned text will be parsed by the
Receive Sequence so that you can test your parsing code and see if the variables have been created.
Use the Watch Variables module to see those variables being created.
9. Refresh Rate - to slow the scrolling of the numbers select a different refresh rate for the console. This will just slow down
how quickly RoboRealm reads information from the device.
10. Initialization Sequence - The initialization data sequence sends the provided string to the serial device
on initialization of communication. You may want to use
this to command the receiving device into a specific mode ready for communication with RoboRealm. This initialization
sequence is sent each time the serial communication is reset. This happens when you click on the "Stop" button in
this interface, change one of the above parameters (Baud, Port, etc) or when the RoboRealm starts running for the
first time. It is NOT sent when the Run button in the main RoboRealm interface is toggled.
11. Send sequence - Used to enter commands sent per pipeline loop (i.e. image processed) by RoboRealm. You can
use this sequence to transmit variables created by other RoboRealm modules to the
serial device. Each time an image is captured and processed the serial module will
interpret the Send Sequence text and send the result to the serial device.
12. Enable - Allows you to temporarily disable sending text to the serial device while performing
edits. Note that the Send Sequence textarea will turn red to indicate this setting.
13. Send Rate - Some serial devices cannot handle data streams even given a slower baud rate. Use this
dropdown to select how quickly you want the data to be sent. At AFAP (As Fast As Possible) the data
will be sent out about 30 times a second (this assumes a camera running at 30 fps).
14. Clear serial buffer trigger - there are cases when too much data may be buffered on the serial
port that needs to be cleared due to some event. In this case specify a variable whose value when set
to "clear" will remove all data scheduled to be sent over the serial port.
15. Send only on change - If your data does need to be sent out to your serial device every iteration
through the processing pipeline loop this selection will prevent the same data from being sent to the
serial device that was last sent. This is also an elegant way to reduce the data bandwidth to the
device if your sequence does not change rapidly.
16. Receive sequence - used to receive and parse text send from the serial device. The
text string is matched against the incoming serial bytes. When a match is found
variables are added into RoboRealm for use in other modules. Reading into variables just
requires adding in a variable at the appropriate spot within the receive string similar to the
scanf routine in C/C++. The Receive sequence works similar to an expect string, i.e. you need to
specify patterns that match the incoming text and substitute the areas that need to be
fed into variables with the [ variable_nane ] format. Note that even if you are missing
one space or newline the patter will not match and the variable will be zero or blank.
17. Test Receive - instead of waiting for the correct data bytes to come from your serial device
you can type in a test sequence that will be parsed by the receive sequence. This can be handy when
first testing that your receive sequence is picking up the right bytes.
Example
To read digital inputs from a VEX Robotics System robot over the serial port you can configure the settings to port COM5, baud 115200, 8 data bits,
no parity, 1 stop bit with the sequences as:
Initialization Sequence
\x0f\x0f\x08\x40\xb8\x04
Send Sequence
\xaa\x55\x00\x00\x00\x0B\x00\x00
Receive Sequence
DIN [din1] [din2] [din3] [din4] [din5] [din6]<lf>
which would command the Vex in the online mode (be sure to download that code to your
Vex robot) and read in the digital inputs into variables din1, din2, din3, etc. You can add
the Watch Variables module to see these variables change when you press
a bump switch on the Vex.
Note that the Vex online mode needs to be downloaded prior to using this serial sequence. Be sure
your Vex is reacting to the online interface provided by Vex to ensure correct online operation.
To receive data from a serial device that transmits binary data back to the PC (as apposed to the
ASCII mode sent by the Vex) you would use something like
\[binary_input_1]:\[binary_input_2]
which would read binary numbers delimited by ':' and ended with \r into the two variables (\1024:\667\n) but
[ascii_input_1]:[ascii_input_2]
would read in two ASCII numbers into the two variables (1024:667\n).
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 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 to the serial device 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.
See Also
SSC
Parallax
For more information
CodeGuru: Serial Communications in Windows
The Code Project: Serial library for C++
| Serial Related Forum Posts | Last post | Posts | Views |
how to interface DC gear Motor to roborealm software
i dont know how to interface the motor with software . i am using 89v51rd2 microcotroller to run the motor but i dont know how t... |
8 days |
2 |
58 |
Edge Probe Variable Issue
I'm using the Edge probe module, and then trying to send the found edges through the Serial module. I've configured... |
10 days |
2 |
90 |
Use YUY2 compression by default
2 questions:
Is it possible to force RR to use YUY2 compression by default, instead of other availa... |
2 months |
2 |
107 |
SSC-32 and reading Analog Sensor via Serial Module
Hi,
Can someone please help me out with this one. I am having real trouble reading analog sensor proper... |
3 months |
3 |
214 |
Oscillations
I've found a RR script that sends a balls COGX serially to an Arduino controlling a Sabertooth in RC/Microcontroller mode. I'm... |
3 months |
7 |
173 |
Serial Write Buffer Clearing
Hi,
I test serial communication RR with PLC. The PLC consumes data from RR.
Some times, in outbound... |
6 months |
6 |
357 |
Serial receiving
Hello,
I dont understand how to put all incoming bytes into a variable...
| 6 months |
9 |
360 |
robotics
sir,
how to make sure that my com port in mother board is working??... |
7 months |
2 |
241 |
Sensors
Are there any I/O boards that are supported by Roborealm? I would really like to be able to input data from sensors into Roborea... |
8 months |
4 |
276 |
Finding 3 targets
Hello,
My name is Hein van den Broek and i'm making a schoolproject. We need to make a tennisball... |
10 months |
6 |
485 |
Roborealm+Ardiuno+2 axis stepper
I would like to have Roborealm control the direction of stepper motors (all drivers and circuitry for the steppers currently wit... |
11 months |
2 |
517 |
problems with roborealm serial module
when i initialize roborealm, it works fine, but inmediately i try to open serial module ( trying comunicate and arduino with rob... |
1 month |
4 |
507 |
Serial Sequence
In the serial communications console area i am sending the code
\\x10\\xff\\xef\\x80\\x80\\x80\\x80... |
2 months |
35 |
989 |
interface with microcontroller
anyone can teach/tell me how to interface RR to microcontroller like dsPIC.
please.... |
2 months |
2 |
463 |
Read NMEA / data strings?
I'm interested in displaying a compass heading in RR. The compass I'm considering is here:
... |
2 months |
4 |
435 |
wireless transmission over serial
I am using an RF transmitter that I bought locally. It has 8-bits of TTL outputs from a microcontroller. Can someone give me an... |
2 months |
6 |
660 |
serial communication problem
hi i am rohit ,i am trying to communicate my siemens plc with roboleam but i was unable to send or receive any data, i am using... |
2 months |
2 |
392 |
|