Editing Changing SimpleMotion baud rate
Your changes will be displayed to readers once an authorized user accepts them. (help) |
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | RS485 based [[SimpleMotion V2]] bus supports changing baud rate on the fly from the default 460800 | + | RS485 based [[SimpleMotion V2]] bus supports changing baud rate on the fly from the default 460800 PBS. The procedure in simplest form is done by writing new baudrate value into parameter SMP_BUS_SPEED, and after that closing and re-opening the bus with the same speed. |
However, in addition it is recommended to setup watchdog feature that will reset bus baudrate to default in case of connection is lost and timeouted. Example: | However, in addition it is recommended to setup watchdog feature that will reset bus baudrate to default in case of connection is lost and timeouted. Example: | ||
Line 94: | Line 94: | ||
} | } | ||
− | // | + | //your SimpleMotion application |
int main() | int main() | ||
{ | { | ||
− | smSetDebugOutput(SMDebugMid,stderr); | + | /*in your SM application, the code might follow this kind pattern: */ |
+ | smSetDebugOutput(SMDebugMid,stderr); | ||
− | |||
if( OpenBusWithCustomBaudrate() == smfalse ) | if( OpenBusWithCustomBaudrate() == smfalse ) | ||
{ | { | ||
Line 107: | Line 107: | ||
} | } | ||
− | |||
while(1) | while(1) | ||
{ | { | ||
+ | //do some communication, anything | ||
+ | |||
smint32 deviceType; | smint32 deviceType; | ||
int slaveAddress=enter some address here; | int slaveAddress=enter some address here; | ||
Line 116: | Line 117: | ||
if(getCumulativeStatus(smhandle)!=SM_OK) | if(getCumulativeStatus(smhandle)!=SM_OK) | ||
{ | { | ||
− | //some of | + | //some of above SM commands have failed. |
//handle error: | //handle error: | ||
printf("SM error occurred, status %d\n", getCumulativeStatus(smhandle)); | printf("SM error occurred, status %d\n", getCumulativeStatus(smhandle)); | ||
resetCumulativeStatus(smhandle); | resetCumulativeStatus(smhandle); | ||
− | //... | + | //... |
//if this is happened due to the command timeout, then we know that bus baud rate has been reset to default in all | //if this is happened due to the command timeout, then we know that bus baud rate has been reset to default in all | ||
Line 132: | Line 133: | ||
//print result & quit demo app, in real app do something else maybe | //print result & quit demo app, in real app do something else maybe | ||
printf("Read succeed, device type at address %d = %d\n", slaveAddress, deviceType); | printf("Read succeed, device type at address %d = %d\n", slaveAddress, deviceType); | ||
− | |||
smCloseBus(smhandle); | smCloseBus(smhandle); | ||
return 2; | return 2; | ||
Line 143: | Line 143: | ||
*Newly set baud rate will stay active only when device stays on (logic voltage on and drive not restarted). Baud rate will always reset to default 460800 BPS if device is powered off/on. | *Newly set baud rate will stay active only when device stays on (logic voltage on and drive not restarted). Baud rate will always reset to default 460800 BPS if device is powered off/on. | ||
*If you setup the SimpleMotion watchdog has been set, then baud rate will also reset to default also if connection is lost for certain period of time. This is useful ensuring that you can re-connect again to the device with default baud rate and then re-do the baud date change procedure. | *If you setup the SimpleMotion watchdog has been set, then baud rate will also reset to default also if connection is lost for certain period of time. This is useful ensuring that you can re-connect again to the device with default baud rate and then re-do the baud date change procedure. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− |