Wiki source code of Lynxmotion SSC-32 Protocol Tutorial
Last modified by Eric Nantel on 2022/11/01 07:26
Hide last authors
![]() |
10.1 | 1 | (% style="width:710px" %) |
2 | |((( | ||
3 | **Serial Protocols** | ||
4 | ))) | ||
5 | |((( | ||
6 | Many hardware devices communication with the computer using a serial protocol. Some are simple ASCII-based protocols, but others can be more complex binary ones that require checksums. No matter, both can easily be made in FlowBotics. | ||
7 | |||
8 | Let's use the Lynxmotion SSC-32 servo controller board as an example of an ASCII protocol. If you open any of the Lynxmotion projects, you will find the "//LM SC-32 + Comport//" module inside a few levels of schematics that handles all the protocol communications and COM port management. | ||
9 | |||
10 | This module does a few things. The left portion pre-processes the virtual robot's data to get them ready to be encoded into the protocol for transfer to the SSC-32 board. The right portion takes the protocol data received from the SSC-32 board, and extracts various state and input pin signals. | ||
11 | |||
12 | The two main workhorses of the schematic is the //"LM SC-32 Engine//" and "//Comport//" modules: | ||
13 | ))) | ||
14 | |(% style="text-align:center" %)[[image:lynxmotion-ssc-32-protocol-engine.png||height="241" width="500"]] | ||
15 | |The engine module has all the protocol encoding logic, so let's take a look at that. | ||
16 | |((( | ||
17 | **Using Ruby** | ||
18 | ))) | ||
19 | |In this case, we implemented the protocol using a Ruby module, but it could also be implemented using the FlowBotics graphical language. | ||
20 | |(% style="text-align:center" %)[[image:lynxmotion-ssc-32-protocol-ruby.png||width="500"]] | ||
21 | |((( | ||
22 | The code is pretty simple: | ||
23 | |||
24 | 1. Wait until new "//data//" signals arrive. | ||
25 | 1*. Note: The "//i//" variable has the number of the input that changed. In this case "//data//" is input "//0//". | ||
26 | 1. Loop through all the positions in the data array, and make the servo position string. | ||
27 | 1. Output the servo string, and the "//outputs//" string. | ||
28 | 1. Every other time, also output the input poll string. | ||
29 | 1. Finally, output the "//Q//" query string. | ||
30 | |||
![]() |
11.1 | 31 | The four output strings are output as four different signals because there's some additional logic (offscreen) that treats them a bit differently. If you have any questions about how this works, ask us in [[our forum>>https://community.robotshop.com/forum/c/lynxmotion/13]] and we'll be glad to explain it to you! |
![]() |
10.1 | 32 | |
33 | For documentation of the Ruby language, we recommend [[the Ruby Doc site>>url:https://www.ruby-doc.org/core-1.9.1/]]. | ||
34 | ))) | ||
35 | |[[<< Back to Developer Zone>>doc:ses-software.flowbotics.developers.WebHome]] | ||
36 | |||
37 |