Difference between revisions of "SimpleMotion V2 API documentation"

From Granite Devices Knowledge Wiki
Jump to: navigation, search
[checked revision][checked revision]
Line 85: Line 85:
 
Simple read & write of parameters commands. Single function call will perform all necessary communication with the target device, however this method is not as fast as the low level communication method (see chapter below).  Use these for non-time critical operations, such as initialization and point-to-point motion control where hard real-time control is not needed.
 
Simple read & write of parameters commands. Single function call will perform all necessary communication with the target device, however this method is not as fast as the low level communication method (see chapter below).  Use these for non-time critical operations, such as initialization and point-to-point motion control where hard real-time control is not needed.
  
{{APIdoc|SM_STATUS|smRead1Parameter|( const smbus handle, const smaddr nodeAddress, const smint16 paramId1, smint32 *paramVal1 )|Read one parameter value from the target device}}
+
{{APIdoc|SM_STATUS|smRead1Parameter|( const smbus handle, const smaddr nodeAddress, const smint16 paramId1, smint32 *paramVal1 )|Read one parameter value from the target device|
 
;handle
 
;handle
 
:SimpleMotion bus handle as returned from smOpenBus
 
:SimpleMotion bus handle as returned from smOpenBus
Line 96: Line 96:
 
;Return value
 
;Return value
 
:{{SM_STATUS}}
 
:{{SM_STATUS}}
 
+
}}
 
{{APIdoc|SM_STATUS|smRead2Parameters|( const smbus handle, const smaddr nodeAddress, const smint16 paramId1, smint32 *paramVal1,const smint16 paramId2, smint32 *paramVal2 )|Read two parameter value from the target device with a single function call, this executes faster than two calls of smRead1Parameter}}
 
{{APIdoc|SM_STATUS|smRead2Parameters|( const smbus handle, const smaddr nodeAddress, const smint16 paramId1, smint32 *paramVal1,const smint16 paramId2, smint32 *paramVal2 )|Read two parameter value from the target device with a single function call, this executes faster than two calls of smRead1Parameter}}
 
;handle
 
;handle

Revision as of 21:53, 1 September 2015

This page lists files and the API calls of SimpleMotion V2 C-library.

Files

simplemotion.h
The header file that declares API functions and constants used in SMV2 programs. Include this file in the C-file where SMV2 is used.
simplemotion.dll or smv.dll
A Win32 dynamic library. Place this file in application .exe folder if program is linked against the DLL. If project is being compiled with GNU GCC, then all library .c files may be added in the project to compile library statically in the program thus eliminate the need of .dll.
simplemotion.lib or smv.lib
A library file needed by some Microsoft C/C++ development tools to allow usage of DLL file. Most of other tools don't need these.

Types

SMV2 library uses custom integer types in order to have explicitly defined bit lengths. All types translate to standard C-types.

typedef long smbus;
typedef unsigned long smuint32;
typedef unsigned short smuint16;
typedef unsigned char smuint8;
typedef long smint32;
typedef short smint16;
typedef char smint8;
typedef char smbool;
#define smtrue 1
#define smfalse 0
typedef int SM_STATUS;
typedef smuint8 smaddr;
typedef enum _smVerbosityLevel {Off,Low,Mid,High,Trace} smVerbosityLevel;

SM_STATUS is returned by most of function calls and indicate the success or failure of the call. Multiple states are possible simultaneously, i.e. function may return integer value 40 which is a sum of 32 and 8 meaning both SM_ERR_COMMUNICATION and SM_ERR_LENGTH are active. Possible return values of SM_STATUS:

SM_NONE (integer value 0)
Never returned
SM_OK (integer value 1)
Call completed successfully
SM_ERR_NODEVICE (integer value 2)
Invalid smbus handle given or port not open
SM_ERR_BUS (integer value 4)
RS485 communication device error
SM_ERR_COMMUNICATION (integer value 8)
Invalid reply or no reply received from target device. Typical reasons: inexisting nodeAddress given or signal quality problem (see EMI and Device connection troubleshooting)
SM_ERR_PARAMETER (integer value 16)
Illegal parameter value given
SM_ERR_LENGTH (integer value 32)
Command queue length exceeded maximum size or received return data length differs from expected length. Typical reasons: invalid/exceeded usage of queued commands or same as SM_ERR_COMMUNICATION reasons.

Function reference

General

smuint32 smGetVersion()

smGetVersion

Return SM lib version number in hexadecimal format. Ie V 2.5.1 would be 0x020501 and 1.2.33 0x010233
smbus smOpenBus( const char * devicename )

smOpenBus

Open SM RS485 communication bus.
devicename
"USB2VSD" or com port as "COMx" where x=1-n, i.e. "COM15". In UNIX systems this is device path such as "/dev/ttyUSB0".
return value
handle to be used with all other commands, -1 if fails

Usage:

smbus bushandle;
bushandle=smOpenBus("COM5");
if(bushandle<0)
{
  //error occurred
}
SM_STATUS smCloseBus( const smbus bushandle )

smCloseBus

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. The SM_STATUS return value from all other functions have similar meaning.

Usage:

smCloseBus(bushandle);
void smSetDebugOutput( smVerbosityLevel level, FILE *stream )

smSetDebugOutput

Set stream where debug output is written. By default nothing is written.
level
set verbosity level of debugging output. Enum choices are Off,Low,Mid,High and Trace.
stream
A pointer to output stream such as stderr, stdout or a file handle.
SM_STATUS getCumulativeStatus( const smbus handle )

getCumulativeStatus

Returns all occurred SM_STATUS bits after smOpenBus or resetCumulativeStatus call

For example, this returns SM_OK if all past function calls completed without errors (does not report errors that target device may have, just SM communication related errors). I.e. will return SM_OK|SM_ERR_LENGTH (=decimal value 33) in case of some command returned SM_OK and another SM_ERR_LENGTH.

This function is provided to ease error checking by eliminating the need to inspect return value of each individual function call separately. Instead, programmer may occasionally call this function to check if any errors have occurred during longer period of time.

void resetCumulativeStatus( const smbus handle )

resetCumulativeStatus

Reset cumulative status so getCumultiveStatus returns 0 after calling this until one of the other functions are called

Simple communication

Simple read & write of parameters commands. Single function call will perform all necessary communication with the target device, however this method is not as fast as the low level communication method (see chapter below). Use these for non-time critical operations, such as initialization and point-to-point motion control where hard real-time control is not needed.

SM_STATUS smRead1Parameter( const smbus handle, const smaddr nodeAddress, const smint16 paramId1, smint32 *paramVal1 )

smRead1Parameter

Read one parameter value from the target device
handle
SimpleMotion bus handle as returned from smOpenBus
nodeAddress
Integer value holding target device address in the bus. If unknown, connect to device with Granity to check it's address.
paramId1
Integer value specifying the parameter address to be read. See list of SMP_xxx definitions from simplemotion_defs.h header file for possible parameters.
paramVal1
Integer pointer where read parameter is stored
Return value
SM_STATUS holds a status value of a function call (Note: local error reporting only, such as bus error. This does not report errors that may have occurred in the target devices). See list of possible values in the beginning of this page.
SM_STATUS smRead2Parameters( const smbus handle, const smaddr nodeAddress, const smint16 paramId1, smint32 *paramVal1,const smint16 paramId2, smint32 *paramVal2 )

smRead2Parameters

Read two parameter value from the target device with a single function call, this executes faster than two calls of smRead1Parameter
handle
SimpleMotion bus handle as returned from smOpenBus
nodeAddress
Integer value holding target device address in the bus. If unknown, connect to device with Granity to check it's address.
paramId1
Integer value specifying the first parameter address to be read. See list of SMP_xxx definitions from simplemotion_defs.h header file for possible parameters.
paramVal1
Integer pointer where the first read parameter is stored
paramId2
Integer value specifying the second parameter address to be read. See list of SMP_xxx definitions from simplemotion_defs.h header file for possible parameters.
paramVal2
Integer pointer where the second read parameter is stored
Return value
SM_STATUS holds a status value of a function call (Note: local error reporting only, such as bus error. This does not report errors that may have occurred in the target devices). See list of possible values in the beginning of this page.
SM_STATUS smRead3Parameters( const smbus handle, const smaddr nodeAddress, const smint16 paramId1, smint32 *paramVal1,const smint16 paramId2, smint32 *paramVal2 ,const smint16 paramId3, smint32 *paramVal3 )

smRead3Parameters

Read three parameter value from the target device with a single function call, this executes faster than equivalent operation by using smRead1Parameter or smRead2Parameter
handle
SimpleMotion bus handle as returned from smOpenBus
nodeAddress
Integer value holding target device address in the bus. If unknown, connect to device with Granity to check it's address.
paramId1
Integer value specifying the first parameter address to be read. See list of SMP_xxx definitions from simplemotion_defs.h header file for possible parameters.
paramVal1
Integer pointer where the first read parameter is stored
paramId2
Integer value specifying the second parameter address to be read. See list of SMP_xxx definitions from simplemotion_defs.h header file for possible parameters.
paramVal2
Integer pointer where the second read parameter is stored
paramId3
Integer value specifying the third parameter address to be read. See list of SMP_xxx definitions from simplemotion_defs.h header file for possible parameters.
paramVal3
Integer pointer where the third read parameter is stored
Return value
SM_STATUS holds a status value of a function call (Note: local error reporting only, such as bus error. This does not report errors that may have occurred in the target devices). See list of possible values in the beginning of this page.


SM_STATUS smSetParameter( const smbus handle, const smaddr nodeAddress, const smint16 paramId, smint32 paramVal )

smSetParameter

Write single parameter value to the target device
handle
SimpleMotion bus handle as returned from smOpenBus
nodeAddress
Integer value holding target device address in the bus. If unknown, connect to device with Granity to check it's address.
paramId
Integer value specifying the parameter address to be written. See list of SMP_xxx definitions from simplemotion_defs.h header file for possible parameters.
paramVal
Integer value that will be written into parameter specified by paramId
Return value
SM_STATUS holds a status value of a function call (Note: local error reporting only, such as bus error. This does not report errors that may have occurred in the target devices). See list of possible values in the beginning of this page.

Low level communication

Use low level communication commands for high performance communication, such as real-time update of setpoint and feedback readouts from a real-time controller. For initialization and non-real-time communication needs, use Simple communication API (chapter above).

Low level communication involves assembing an outbound transmission packet from subpackets (with Append calls), sending it out and getting respose fromn the target device (with Excecute call) and reading out the return packet subpackets (with Get calls).

SM_STATUS smAppendSMCommandToQueue( smbus handle, int smpCmdType, smint32 paramvalue )

smAppendSMCommandToQueue

Appends SM subpacket command to a command queue
handle
SimpleMotion bus handle as returned from smOpenBus
smpCmdType
Integer value holding a subpacket type. See SimpleMotion V2 subpacket types.
paramvalue
Integer value that will be written into parameter specified by paramId
Return value
SM_STATUS holds a status value of a function call (Note: local error reporting only, such as bus error. This does not report errors that may have occurred in the target devices). See list of possible values in the beginning of this page.
SM_STATUS smExecuteCommandQueue( const smbus bushandle, const smaddr targetaddress )

smExecuteCommandQueue

Sends all subpacket commands to the target device, and reads the response packet from target
handle
SimpleMotion bus handle as returned from smOpenBus
nodeAddress
Integer value holding target device address in the bus. If unknown, connect to device with Granity to check it's address.
Return value
SM_STATUS holds a status value of a function call (Note: local error reporting only, such as bus error. This does not report errors that may have occurred in the target devices). See list of possible values in the beginning of this page.
STATUS smGetQueuedSMCommandReturnValue( const smbus bushandle, smint32 *retValue )

smGetQueuedSMCommandReturnValue

Fetches an return value from returned subpacket after the call of smExecuteCommandQueue
handle
SimpleMotion bus handle as returned from smOpenBus
retValue
Pointer to a integer value where value if returning subpacket will be stored. See SimpleMotion V2 subpacket types.
Return value
SM_STATUS holds a status value of a function call (Note: local error reporting only, such as bus error. This does not report errors that may have occurred in the target devices). See list of possible values in the beginning of this page.

Buffered low level communucation

Buffered subpackets are executed by the target device in background at timer based schedule. This allows uploading a set of commands to drives that are excecuted at predefined execution rate. Typical application for this is motion control where trajectory points are uploaded to multiple devices and drives will follow the trajectory as commended by the buffered subpackets. Execution clock of all devices in the bus can be synchronized to ensure simultaneous execution of commands over infinite periods of time (eliminate clock drifting).

SM_STATUS smUploadCommandQueueToDeviceBuffer( const smbus bushandle, const smaddr targetaddress )

smUploadCommandQueueToDeviceBuffer

Uploads subpackets to the target device buffer. Subpackets are are added to local buffer with smAppendSMCommandToQueue prior to calling this function. This function also downloads returning subpackets that are already executed in the device and updates the value given by smBytesReceived. Returned subpackets may be extracted by smGetQueuedSMCommandReturnValue function.
handle
SimpleMotion bus handle as returned from smOpenBus
nodeAddress
Integer value holding target device address in the bus. If unknown, connect to device with Granity to check it's address.
Return value
SM_STATUS holds a status value of a function call (Note: local error reporting only, such as bus error. This does not report errors that may have occurred in the target devices). See list of possible values in the beginning of this page.


SM_STATUS smBytesReceived( const smbus bushandle, smint32 *bytesinbuffer )

smBytesReceived

Gives the amount of how many bytes waiting to be read with smGetQueuedSMCommandReturnValue
handle
SimpleMotion bus handle as returned from smOpenBus
bytesinbuffer
Pointer to a integer value where value of number of bytes will be stored
Return value
SM_STATUS holds a status value of a function call (Note: local error reporting only, such as bus error. This does not report errors that may have occurred in the target devices). See list of possible values in the beginning of this page.


SM_STATUS smGetBufferClock( const smbus handle, const smaddr targetaddr, smuint16 *clock )

smGetBufferClock

Read buffered execution clock value from a device and synchronize clocks of all other bus devices to this clock value. When used, call this at least once per every three seconds to avoid side-effects from value rollover. The first call of this function begins the execution of buffered commands (on single device, or multiple devices simultaneusly).
handle
SimpleMotion bus handle as returned from smOpenBus
clock
Pointer to a 16 bit integer value where the clock time will be stored. Clock counter runs at 10 kHz meaning that 16 bit value will rollover every 6.5 seconds.
Return value
SM_STATUS holds a status value of a function call (Note: local error reporting only, such as bus error. This does not report errors that may have occurred in the target devices). See list of possible values in the beginning of this page.