Setting a variable with a script and reading it from Serial/USB

7 years 6 months ago #29527931 by neoplan
Greetings to all

I have two SDC1130 controllers that are both connected to a small board computer and drive two motors. I use serial to USB converters.
On power on I want the computer (linux) to identify the controllers because it assigns different names each time to the ports (dev/ttyUSB0, dev/ttyUSB1).

My first thought was to write a script to each controller:
top:
SetCommand(_VAR, 1, 1) \'var 1 is 1 for left controller and 2 for right controller

So the computer after connecting to a controller will query it with

?VAR 1

and the controller will answer 1 or 2. Then I will be able to identify which controller is in each port.

My question is about the Script on the controller. If it runs only once and then it exits (like in the example above) will it keep the variable value in the memory? If not, I believe it should run on a loop with a large wait time but wouldn\'t that consume CPU time?
For a constantly running script is it enough?
top:
SetCommand(_VAR, 1, 1)
wait(10000)
goto top

Thank you

Please Log in or Create an account to join the conversation.

7 years 6 months ago #29527932 by roboteq
the much simpler way is to store a number in one of the configuration parameter. For example a different watchdog value: 1000 (default value) for the first and 1001 for the second.

Then you would read the RWD configuration parameter from your linux box.

Please Log in or Create an account to join the conversation.

7 years 6 months ago #29527933 by neoplan
Good idea, thank you.

Even though, i would like to know if the memory values are dumped at program stop and if the wait time affects the cpu.

Please Log in or Create an account to join the conversation.

7 years 6 months ago #29527934 by roboteq
the variable is not cleared when the script ends or restarted.

wait does not affect the mcu

Please Log in or Create an account to join the conversation.

Time to create page: 0.090 seconds