Difference between revisions of "Changing SimpleMotion baud rate"

From Granite Devices Knowledge Wiki
Jump to: navigation, search
[checked revision][checked revision]
Line 36: Line 36:
 
//and reinitialization of the speed is needed.
 
//and reinitialization of the speed is needed.
 
</syntaxhighlight>
 
</syntaxhighlight>
[category:SimpleMotion]
+
[[category:SimpleMotion]]
  
 
[[Category:Development]]
 
[[Category:Development]]
 
[[Category:Software]]
 
[[Category:Software]]

Revision as of 15:51, 9 February 2017

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:

int pbs=1000000;//new bus baud rate
int slaveSMWatchdogTimeountMs=700;//adjustable in 10ms steps up to 8000 ms
 
//open SM bus with default baud rate
smSetBaudrate(460800);
smhandle=smOpenBus("COM1");
 
//reduce timeout because as following commands are sent to address 0 (broadcast to all devices), they will not return anything, so they will just timeout
smSetTimeout(50);
 
//setup SM bus watchdog feature. when communication is timeouted, motor will be stopped and baudrate is reset to default
smSetParameter(smhandle,0,SMP_FAULT_BEHAVIOR,((slaveSMWatchdogTimeountMs/10)<<8)|1);
 
//change baudrate of all devices on the bus (by giving address 0). it is important to change all devices at once so no communication errors happen due to wrong speed devices on the bus.
smSetParameter(smhandle,0,SMP_BUS_SPEED,pbs);
 
//reset errors that have come from above commands (SM library current version expects response from the commands even when they are broadcasted to address 0, thus it is expected not to give respose)
resetCumulativeStatus(smhandle);
 
//set longer timeout, to make SM bus watchdog activate on error, set this value higher than slaveSMWatchdogTimeountMs
smSetTimeout(1000);
 
//reopen SM bus device with new speed
smCloseBus(smhandle);
smSetBaudrate(pbs);
smhandle=smOpenBus("COM1");
 
//continue using bus at new speed normally.
//keep in mind that new commands must be sent to bus at least with the rate defined by slaveSMWatchdogTimeountMs.
//if any command fails to timeout, or by any other reason timeout occurs, then devices have reset to default speed 
//and reinitialization of the speed is needed.