diff options
| author | Tero Kontkanen <tero.kontkanen@granitedevices.fi> | 2016-10-28 15:18:18 +0300 |
|---|---|---|
| committer | Tero Kontkanen <tero.kontkanen@granitedevices.fi> | 2016-10-28 15:18:18 +0300 |
| commit | fa9c9212d7e25e9eacbbfcc4e6a516b4d48ebbb5 (patch) | |
| tree | e243901845512055513c8e8522ac6243e4e0eb04 | |
| parent | ce55c8a4227539f4d4f57f7acc4aaff1d18c0001 (diff) | |
| download | SimpleMotionV2-fa9c9212d7e25e9eacbbfcc4e6a516b4d48ebbb5.tar.gz SimpleMotionV2-fa9c9212d7e25e9eacbbfcc4e6a516b4d48ebbb5.zip | |
Added smSetBaudrate() to allow changing bus speed
| -rw-r--r-- | busdevice.c | 4 | ||||
| -rw-r--r-- | rs232.c | 36 | ||||
| -rw-r--r-- | simplemotion.c | 21 | ||||
| -rw-r--r-- | simplemotion.h | 18 | ||||
| -rw-r--r-- | simplemotion_private.h | 1 |
5 files changed, 79 insertions, 1 deletions
diff --git a/busdevice.c b/busdevice.c index 9bf82c8..c82e27b 100644 --- a/busdevice.c +++ b/busdevice.c @@ -10,6 +10,8 @@ //how much bytes available in transmit buffer #define TANSMIT_BUFFER_LENGTH 128 +unsigned long SMBusBaudrate=SM_BAUDRATE; //the next opened port (with smOpenBus) will be opened with the PBS defined here (default 460800 BPS) + typedef struct _SMBusDevice { //common @@ -65,7 +67,7 @@ smbusdevicehandle smBDOpen( const char *devicename ) if(strncmp(devicename,"COM",3) == 0 || strncmp(devicename,"/dev/tty",8) == 0) //use rs232 lib { - BusDevice[handle].comPort=OpenComport( devicename, SM_BAUDRATE ); + BusDevice[handle].comPort=OpenComport( devicename, SMBusBaudrate ); if( BusDevice[handle].comPort == -1 ) { return -1; //failed to open @@ -93,6 +93,20 @@ int OpenComport(const char * comport_name, int baudrate) break;
case 1000000 : baudr = B1000000;
break;
+ case 1115200 : baudr = B1152000;
+ break;
+ case 1500000 : baudr = B1500000;
+ break;
+ case 2000000 : baudr = B2000000;
+ break;
+ case 2500000 : baudr = B2500000;
+ break;
+ case 3000000 : baudr = B3000000;
+ break;
+ case 3500000 : baudr = B3500000;
+ break;
+ case 4000000 : baudr = B4000000;
+ break;
default : printf("invalid baudrate\n");
return(1);
break;
@@ -254,6 +268,28 @@ int OpenComport(const char * comport_name, int baudrate) break;
case 460800 : strcpy(baudr, "baud=460800 data=8 parity=N stop=1");
break;
+ case 500000 : strcpy(baudr, "baud=500000 data=8 parity=N stop=1");
+ break;
+ case 576000 : strcpy(baudr, "baud=576000 data=8 parity=N stop=1");
+ break;
+ case 921600 : strcpy(baudr, "baud=921600 data=8 parity=N stop=1");
+ break;
+ case 1000000 : strcpy(baudr, "baud=1000000 data=8 parity=N stop=1");
+ break;
+ case 1115200 : strcpy(baudr, "baud=1115200 data=8 parity=N stop=1");
+ break;
+ case 1500000 : strcpy(baudr, "baud=1500000 data=8 parity=N stop=1");
+ break;
+ case 2000000 : strcpy(baudr, "baud=2000000 data=8 parity=N stop=1");
+ break;
+ case 2500000 : strcpy(baudr, "baud=2500000 data=8 parity=N stop=1");
+ break;
+ case 3000000 : strcpy(baudr, "baud=3000000 data=8 parity=N stop=1");
+ break;
+ case 3500000 : strcpy(baudr, "baud=3500000 data=8 parity=N stop=1");
+ break;
+ case 4000000 : strcpy(baudr, "baud=4000000 data=8 parity=N stop=1");
+ break;
default : printf("invalid baudrate\n");
return(-1);
break;
diff --git a/simplemotion.c b/simplemotion.c index cea0238..ea773ac 100644 --- a/simplemotion.c +++ b/simplemotion.c @@ -222,6 +222,27 @@ smbus smOpenBus( const char * devicename ) return handle;
}
+/** Change baudrate of SM communication port. This does not affect already opened ports but the next smOpenBus will be opened at the new speed.
+ Calling this is optional. By default SM bus and all slave devices operates at 460800 BPS speed.
+ Parameters:
+ -bps: bus speed in bits per second. for possible choices, see rs232.c (but note that all speeds are not necessarily supported by SM devices)
+ Typical usage is:
+ - first call smSetParameter(handle,0,SMP_BUS_SPEED,N) to change speed of all connected slaves to N PBS
+ - then close port with smCloseBus
+ - then call smSetBaudrate(N)
+ - then open bus again with smOpenBus
+
+ Note that in upcoming SM device firmware versions, bitrate will be reset to default (460800) if device side SM bus watchdog timer has been enabled, and it timeouts.
+ This allows re-establishing connection at defautl speed if connection breaks up and SM bus watchdog timeout gets exceeded. To identify is device supports this,
+ read parameter SMP_SM_VERSION. Values above 25 support this feature. Value 25 and below will not reset baudrate.
+
+ Note also that SMP_BUS_SPEED will not be saved in device flash memory - it will reset to default at every reset & power on.
+ */
+LIB void smSetBaudrate( unsigned long pbs )
+{
+ SMBusBaudrate=pbs;
+}
+
/** Close connection to given bus handle number. This frees communication link therefore makes it available for other apps for opening.
-return value: a SM_STATUS value, i.e. SM_OK if command succeed
*/
diff --git a/simplemotion.h b/simplemotion.h index 056c745..913a595 100644 --- a/simplemotion.h +++ b/simplemotion.h @@ -81,6 +81,24 @@ typedef enum _smVerbosityLevel {Off,Low,Mid,High,Trace} smVerbosityLevel; */
LIB smbus smOpenBus( const char * devicename );
+/** Change baudrate of SM communication port. This does not affect already opened ports but the next smOpenBus will be opened at the new speed.
+ Calling this is optional. By default SM bus and all slave devices operates at 460800 BPS speed.
+ Parameters:
+ -bps: bus speed in bits per second. for possible choices, see rs232.c (but note that all speeds are not necessarily supported by SM devices)
+ Typical usage is:
+ - first call smSetParameter(handle,0,SMP_BUS_SPEED,N) to change speed of all connected slaves to N PBS
+ - then close port with smCloseBus
+ - then call smSetBaudrate(N)
+ - then open bus again with smOpenBus
+
+ Note that in upcoming SM device firmware versions, bitrate will be reset to default (460800) if device side SM bus watchdog timer has been enabled, and it timeouts.
+ This allows re-establishing connection at defautl speed if connection breaks up and SM bus watchdog timeout gets exceeded. To identify is device supports this,
+ read parameter SMP_SM_VERSION. Values above 25 support this feature. Value 25 and below will not reset baudrate.
+
+ Note also that SMP_BUS_SPEED will not be saved in device flash memory - it will reset to default at every reset & power on.
+ */
+LIB void smSetBaudrate( unsigned long pbs );
+
/** Set timeout of how long to wait reply packet from bus. Must be set before smOpenBus and cannot be changed afterwards
* max value 5000ms. In unix this is rounded to 100ms (rounding downwards), so 99 or less gives 0ms timeout.
*
diff --git a/simplemotion_private.h b/simplemotion_private.h index 1c80780..e46dc1c 100644 --- a/simplemotion_private.h +++ b/simplemotion_private.h @@ -30,6 +30,7 @@ #define BUSDEV_FTDI 2 /*not implemented yet: direct FTDI lib support*/
#define SM_BUSDEVICENAME_LEN 64
+extern unsigned long SMBusBaudrate; //the next opened port (with smOpenBus) will be opened with the PBS defined here (default 460800 BPS)
//default timeout in ms
//Argon drive's worst case response time should be ~20ms with max length packets
|
