| ioPAC RTU Controllers C/C++ Sample Code Programming Guide

- Main Page
- Modules
- Data Structures
- Files

Modules | Data Structures | Macros | Enumerations | Functions
Can
Library

## Modules
| CanStatus
| CanBaudRate

## Data Structures
struct | CAN_Emcy_Message

## Macros
#define | RTU_MAX_CAN_BUS_PORT 2
#define | CAN_MAX_PAYLOAD_LEN 8
#define | CAN_MAX_PDO_DATA_LEN CAN_MAX_PAYLOAD_LEN
#define | CAN_MAX_SDO_DATA_LEN 4
#define | CAN_MAX_PDO 4
#define | CANOPEN_SLAVE_MAX_SDO 1000
#define | CANOPEN_SLAVE_MAX_PDO CAN_MAX_PDO

## Enumerations
enum | CAN_ERR_CODE { CAN_ERR_OK = 0, CAN_ERR_SLOT, CAN_ERR_PORT, CAN_ERR_PARAM, CAN_ERR_GET, CAN_ERR_SET, CAN_ERR_NOT_SUPPORT_PRODUCT, CAN_ERR_SYSTEM_INFO, CAN_ERR_HOT_PLUG, CAN_ERR_TTYACM_PORT, CAN_ERR_SOCKETCAN_INDEX, CAN_ERR_SOCKETCAN_INIT, CAN_ERR_SOCKET, CAN_ERR_IOCTL, CAN_ERR_BIND, CAN_ERR_NMT_NODE_STATE, CAN_ERR_HANDLE, CAN_ERR_DUPLICATE_OPEN, CAN_ERR_WRITE, CAN_ERR_READ, CAN_ERR_SLAVE_NODE_ID, CAN_ERR_EITHER_NODEGUARDING_OR_HEARTBEAT, CAN_ERR_NEITHER_NODEGUARDING_NOR_HEARTBEAT, CAN_ERR_THREAD, CAN_ERR_RW_TIMEOUT, CAN_ERR_SDO_RW_ABORT, CAN_ERR_FNCTL, CAN_ERR_NO_DATA_RECEIVE, CAN_ERR_DATA_LENGTH, CAN_ERR_TAG, CAN_ERR_SLAVE_NODE_ID_IS_NOT_SET, CAN_ERR_SLAVE_IS_NOT_LISTENING, CAN_ERR_SLAVE_SDO_REGISTER_FULL, CAN_ERR_SLAVE_SDO_DUPLICATE_REGISTER, CAN_ERR_SLAVE_PDO_REGISTER_FULL, CAN_ERR_SLAVE_PDO_DUPLICATE_REGISTER, CAN_ERR_SLAVE_BOTH_SDO_AND_PDO_ARE_NOT_REGISTERED, CAN_ERR_AMOUNT }
enum | CAN_NODE_STATE { CAN_NODE_START = 0x1, CAN_NODE_STOP = 0x2, CAN_NODE_PRE_OPERATIONAL = 0x80, CAN_NODE_RESET_NODE = 0x81, CAN_NODE_RESET_COMMUNICATION = 0x82, CAN_NODE_AMOUNT }
enum | CAN_NMT_ERROR_STATUS { CAN_NMT_ERROR_OK = 0, CAN_NMT_ERROR_NODE_GUARDING, CAN_NMT_ERROR_HEARTBEAT, CAN_NMT_ERROR_AMOUNT }
enum | CAN_NMT_NODE_GUARDING_STATE { CAN_NMT_NODE_GUARDING_INITIALISING = 0, CAN_NMT_NODE_GUARDING_DISCONNECTED, CAN_NMT_NODE_GUARDING_CONNECTING, CAN_NMT_NODE_GUARDING_PREPARING, CAN_NMT_NODE_GUARDING_STOPPED, CAN_NMT_NODE_GUARDING_OPERATIONAL, CAN_NMT_NODE_GUARDING_PREOPERATIONAL = 127, CAN_NMT_NODE_GUARDING_AMOUNT }
enum | CAN_NMT_HEARTBEAT_STATE { CAN_NMT_HEARTBEAT_BOOTUP = 0, CAN_NMT_HEARTBEAT_STOPPED = 4, CAN_NMT_HEARTBEAT_OPERATIONAL = 5, CAN_NMT_HEARTBEAT_PREOPERATIONAL = 127, CAN_NMT_HEARTBEAT_AMOUNT }

## Functions
CAN_ERR_CODE | MX_RTU_CanSetBaudrate (UINT8 slot, UINT8 port, UINT32 baudrate)
CAN_ERR_CODE | MX_RTU_CanGetBaudrate (UINT8 slot, UINT8 port, UINT32 *baudrate)
CAN_ERR_CODE | MX_RTU_CanSetAccCode (UINT8 slot, UINT8 port, UINT32 accCode)
CAN_ERR_CODE | MX_RTU_CanGetAccCode (UINT8 slot, UINT8 port, UINT32 *accCode)
CAN_ERR_CODE | MX_RTU_CanSetAccMask (UINT8 slot, UINT8 port, UINT32 accMask)
CAN_ERR_CODE | MX_RTU_CanGetAccMask (UINT8 slot, UINT8 port, UINT32 *accMask)
CAN_ERR_CODE | MX_RTU_CanGetStatus (UINT8 slot, UINT8 port, UINT32 *status)
CAN_ERR_CODE | MX_RTU_CanOpen (UINT8 slot, UINT8 port, int *handle)
CAN_ERR_CODE | MX_RTU_CanClose (int handle)
CAN_ERR_CODE | MX_RTU_CanNMTSetState (int handle, UINT32 slaveNodeID, CAN_NODE_STATE state)
CAN_ERR_CODE | MX_RTU_CanNMTNodeGuarding (int handle, UINT32 slaveNodeID, UINT16 guardTime, UINT8 lifeTimeFactor)
CAN_ERR_CODE | MX_RTU_CanNMTHeartbeat (int handle, UINT32 slaveNodeID, UINT16 producerTime, UINT16 consumerTime)
CAN_ERR_CODE | MX_RTU_CanGetNMTError (int handle, UINT32 slaveNodeID, CAN_NMT_ERROR_STATUS *status, CAN_NMT_NODE_GUARDING_STATE *nodeGuardingState)
CAN_ERR_CODE | MX_RTU_CanSYNCSend (int handle, UINT32 CobID)
CAN_ERR_CODE | MX_RTU_CanCyclicSYNCSend (int handle, UINT32 CobID, UINT16 Timer, UINT32 Times)
CAN_ERR_CODE | MX_RTU_CanGetAllEmcyMessage (int handle, UINT32 slaveNodeID, struct CAN_Emcy_Message *Msg, UINT32 *nMsg)
CAN_ERR_CODE | MX_RTU_CanSDORead (int handle, UINT32 slaveNodeID, UINT16 index, UINT8 subIndex, UINT8 *rData, UINT32 *rLen, UINT32 *abortCode)
CAN_ERR_CODE | MX_RTU_CanSDOWrite (int handle, UINT32 slaveNodeID, UINT16 index, UINT8 subIndex, UINT8 *wData, UINT32 wLen, UINT8 *rData, UINT32 *rLen, UINT32 *abortCode)
CAN_ERR_CODE | MX_RTU_CanPDORemote (int handle, UINT8 pdoNumber, UINT32 slaveNodeID, UINT8 *rData, UINT32 *rLen)
CAN_ERR_CODE | MX_RTU_CanPDOSend (int handle, UINT8 pdoNumber, UINT32 slaveNodeID, UINT8 *wData, UINT32 wLen)
CAN_ERR_CODE | MX_RTU_CanCyclicPDOSend (int handle, UINT8 pdoNumber, UINT32 slaveNodeID, UINT8 *wData, UINT32 wLen, UINT16 Timer, UINT32 Times)
CAN_ERR_CODE | MX_RTU_CanSlaveNodeIDSet (int handle, UINT32 slaveNodeID)
CAN_ERR_CODE | MX_RTU_CanSlaveNodeIDGet (int handle, UINT32 *slaveNodeID)
CAN_ERR_CODE | MX_RTU_CanSlaveSDORegister (int handle, UINT16 index, UINT8 subIndex, UINT8 *tagName)
CAN_ERR_CODE | MX_RTU_CanSlavePDORegister (int handle, UINT8 pdoNumber, UINT8 *tagName)
CAN_ERR_CODE | MX_RTU_CanSlaveStartListening (int handle)
CAN_ERR_CODE | MX_RTU_CanSlaveStopListening (int handle)
CAN_ERR_CODE | MX_RTU_CanSlaveNMTStateGet (int handle, CAN_NODE_STATE *state)
CAN_ERR_CODE | MX_RTU_CanSlaveEmcyMessageSend (int handle, struct CAN_Emcy_Message *Msg)
CAN_ERR_CODE | MX_RTU_CanSlaveSYNCGet (int handle, UINT32 *CobID, UINT32 *nCobID)
CAN_ERR_CODE | MX_RTU_CanSlaveHeartbeatGet (int handle, UINT16 *producerTime)
CAN_ERR_CODE | MX_RTU_CanSlaveHeartbeatStateGet (int handle, CAN_NMT_HEARTBEAT_STATE *state)
CAN_ERR_CODE | MX_RTU_CanSlaveNodeGuardingGet (int handle, UINT16 *guardTime, UINT8 *lifeTimeFactor)
CAN_ERR_CODE | MX_RTU_CanSlaveNodeGuardingStateGet (int handle, CAN_NMT_NODE_GUARDING_STATE *state)
CAN_ERR_CODE | MX_RTU_CanSlaveNodeGuardingStateSet (int handle, CAN_NMT_NODE_GUARDING_STATE state)

## Detailed Description

Sample Code:
can.c

## Macro Definition Documentation

#define RTU_MAX_CAN_BUS_PORT 2

#define CAN_MAX_PAYLOAD_LEN 8

#define CAN_MAX_PDO_DATA_LEN CAN_MAX_PAYLOAD_LEN

#define CAN_MAX_SDO_DATA_LEN 4

#define CAN_MAX_PDO 4

#define CANOPEN_SLAVE_MAX_SDO 1000

#define CANOPEN_SLAVE_MAX_PDO CAN_MAX_PDO

## Enumeration Type Documentation

enum CAN_ERR_CODE

Enumerator
CAN_ERR_OK | 0
CAN_ERR_SLOT |
CAN_ERR_PORT |
CAN_ERR_PARAM |
CAN_ERR_GET |
CAN_ERR_SET |
CAN_ERR_NOT_SUPPORT_PRODUCT |
CAN_ERR_SYSTEM_INFO |
CAN_ERR_HOT_PLUG |
CAN_ERR_TTYACM_PORT |
CAN_ERR_SOCKETCAN_INDEX |
CAN_ERR_SOCKETCAN_INIT |
CAN_ERR_SOCKET |
CAN_ERR_IOCTL |
CAN_ERR_BIND |
CAN_ERR_NMT_NODE_STATE |
CAN_ERR_HANDLE |
CAN_ERR_DUPLICATE_OPEN |
CAN_ERR_WRITE |
CAN_ERR_READ |
CAN_ERR_SLAVE_NODE_ID |
CAN_ERR_EITHER_NODEGUARDING_OR_HEARTBEAT |
CAN_ERR_NEITHER_NODEGUARDING_NOR_HEARTBEAT |
CAN_ERR_THREAD |
CAN_ERR_RW_TIMEOUT |
CAN_ERR_SDO_RW_ABORT |
CAN_ERR_FNCTL |
CAN_ERR_NO_DATA_RECEIVE |
CAN_ERR_DATA_LENGTH |
CAN_ERR_TAG |
CAN_ERR_SLAVE_NODE_ID_IS_NOT_SET |
CAN_ERR_SLAVE_IS_NOT_LISTENING |
CAN_ERR_SLAVE_SDO_REGISTER_FULL |
CAN_ERR_SLAVE_SDO_DUPLICATE_REGISTER |
CAN_ERR_SLAVE_PDO_REGISTER_FULL |
CAN_ERR_SLAVE_PDO_DUPLICATE_REGISTER |
CAN_ERR_SLAVE_BOTH_SDO_AND_PDO_ARE_NOT_REGISTERED |
CAN_ERR_AMOUNT | 37

enum CAN_NODE_STATE

Enumerator
CAN_NODE_START |
CAN_NODE_STOP |
CAN_NODE_PRE_OPERATIONAL |
CAN_NODE_RESET_NODE |
CAN_NODE_RESET_COMMUNICATION |
CAN_NODE_AMOUNT |

enum CAN_NMT_ERROR_STATUS

Enumerator
CAN_NMT_ERROR_OK |
CAN_NMT_ERROR_NODE_GUARDING |
CAN_NMT_ERROR_HEARTBEAT |
CAN_NMT_ERROR_AMOUNT |

enum CAN_NMT_NODE_GUARDING_STATE

Enumerator
CAN_NMT_NODE_GUARDING_INITIALISING |
CAN_NMT_NODE_GUARDING_DISCONNECTED |
CAN_NMT_NODE_GUARDING_CONNECTING |
CAN_NMT_NODE_GUARDING_PREPARING |
CAN_NMT_NODE_GUARDING_STOPPED |
CAN_NMT_NODE_GUARDING_OPERATIONAL |
CAN_NMT_NODE_GUARDING_PREOPERATIONAL |
CAN_NMT_NODE_GUARDING_AMOUNT |

enum CAN_NMT_HEARTBEAT_STATE

Enumerator
CAN_NMT_HEARTBEAT_BOOTUP |
CAN_NMT_HEARTBEAT_STOPPED |
CAN_NMT_HEARTBEAT_OPERATIONAL |
CAN_NMT_HEARTBEAT_PREOPERATIONAL |
CAN_NMT_HEARTBEAT_AMOUNT |

## Function Documentation

CAN_ERR_CODE MX_RTU_CanSetBaudrate | ( | UINT8 | slot,
|  | UINT8 | port,
|  | UINT32 | baudrate
| ) |  |

Parameters

  [in] | slot | slot 0: Built-in CAN Ports, slot 1 ~ 12: Expansion CAN Ports.
  [in] | port | port 0 ~ 1.
  [in] | baudrate | CAN baud rate

Returns
  CAN_ERR_CODE

Note
  The supported rate is (system clock) /(bit divisor * pre divisor), which the system clock is 80MHz, the bit divisor can be 4 to 19 and the pre divisor can be 1 to 1024

CAN_ERR_CODE MX_RTU_CanGetBaudrate | ( | UINT8 | slot,
|  | UINT8 | port,
|  | UINT32 * | baudrate
| ) |  |

Parameters

  [in] | slot | slot 0: Built-in CAN Ports, slot 1 ~ 12: Expansion CAN Ports.
  [in] | port | port 0 ~ 1.
  [out] | baudrate | CAN baud rate

Returns
  CAN_ERR_CODE

CAN_ERR_CODE MX_RTU_CanSetAccCode | ( | UINT8 | slot,
|  | UINT8 | port,
|  | UINT32 | accCode
| ) |  |

Parameters

  [in] | slot | slot 0: Built-in CAN Ports, slot 1 ~ 12: Expansion CAN Ports.
  [in] | port | port 0 ~ 1.
  [in] | accCode | CAN ACC code

Returns
  CAN_ERR_CODE

Note
  To filter the CAN message, controller tests the received message ID with ACC code and ACC mask. Message passes the filter only when (message ID & ACC mask) equals to (ACC code & ACC mask) .

CAN_ERR_CODE MX_RTU_CanGetAccCode | ( | UINT8 | slot,
|  | UINT8 | port,
|  | UINT32 * | accCode
| ) |  |

Parameters

  [in] | slot | slot 0: Built-in CAN Ports, slot 1 ~ 12: Expansion CAN Ports.
  [in] | port | port 0 ~ 1.
  [out] | accCode | CAN ACC code

Returns
  CAN_ERR_CODE

CAN_ERR_CODE MX_RTU_CanSetAccMask | ( | UINT8 | slot,
|  | UINT8 | port,
|  | UINT32 | accMask
| ) |  |

Parameters

  [in] | slot | slot 0: Built-in CAN Ports, slot 1 ~ 12: Expansion CAN Ports.
  [in] | port | port 0 ~ 1.
  [in] | accMask | CAN ACC mask

Returns
  CAN_ERR_CODE

CAN_ERR_CODE MX_RTU_CanGetAccMask | ( | UINT8 | slot,
|  | UINT8 | port,
|  | UINT32 * | accMask
| ) |  |

Parameters

  [in] | slot | slot 0: Built-in CAN Ports, slot 1 ~ 12: Expansion CAN Ports.
  [in] | port | port 0 ~ 1.
  [out] | accMask | CAN ACC mask

Returns
  CAN_ERR_CODE

CAN_ERR_CODE MX_RTU_CanGetStatus | ( | UINT8 | slot,
|  | UINT8 | port,
|  | UINT32 * | status
| ) |  |

Parameters

  [in] | slot | slot 0: Built-in CAN Ports, slot 1 ~ 12: Expansion CAN Ports.
  [in] | port | port 0 ~ 1.
  [out] | status | CAN status

Returns
  CAN_ERR_CODE

CAN_ERR_CODE MX_RTU_CanOpen | ( | UINT8 | slot,
|  | UINT8 | port,
|  | int * | handle
| ) |  |

CAN_ERR_CODE MX_RTU_CanClose | ( | int | handle | ) |

CAN_ERR_CODE MX_RTU_CanNMTSetState | ( | int | handle,
|  | UINT32 | slaveNodeID,
|  | CAN_NODE_STATE | state
| ) |  |

CAN_ERR_CODE MX_RTU_CanNMTNodeGuarding | ( | int | handle,
|  | UINT32 | slaveNodeID,
|  | UINT16 | guardTime,
|  | UINT8 | lifeTimeFactor
| ) |  |

CAN_ERR_CODE MX_RTU_CanNMTHeartbeat | ( | int | handle,
|  | UINT32 | slaveNodeID,
|  | UINT16 | producerTime,
|  | UINT16 | consumerTime
| ) |  |

CAN_ERR_CODE MX_RTU_CanGetNMTError | ( | int | handle,
|  | UINT32 | slaveNodeID,
|  | CAN_NMT_ERROR_STATUS * | status,
|  | CAN_NMT_NODE_GUARDING_STATE * | nodeGuardingState
| ) |  |

CAN_ERR_CODE MX_RTU_CanSYNCSend | ( | int | handle,
|  | UINT32 | CobID
| ) |  |

CAN_ERR_CODE MX_RTU_CanCyclicSYNCSend | ( | int | handle,
|  | UINT32 | CobID,
|  | UINT16 | Timer,
|  | UINT32 | Times
| ) |  |

CAN_ERR_CODE MX_RTU_CanGetAllEmcyMessage | ( | int | handle,
|  | UINT32 | slaveNodeID,
|  | struct CAN_Emcy_Message * | Msg,
|  | UINT32 * | nMsg
| ) |  |

CAN_ERR_CODE MX_RTU_CanSDORead | ( | int | handle,
|  | UINT32 | slaveNodeID,
|  | UINT16 | index,
|  | UINT8 | subIndex,
|  | UINT8 * | rData,
|  | UINT32 * | rLen,
|  | UINT32 * | abortCode
| ) |  |

CAN_ERR_CODE MX_RTU_CanSDOWrite | ( | int | handle,
|  | UINT32 | slaveNodeID,
|  | UINT16 | index,
|  | UINT8 | subIndex,
|  | UINT8 * | wData,
|  | UINT32 | wLen,
|  | UINT8 * | rData,
|  | UINT32 * | rLen,
|  | UINT32 * | abortCode
| ) |  |

CAN_ERR_CODE MX_RTU_CanPDORemote | ( | int | handle,
|  | UINT8 | pdoNumber,
|  | UINT32 | slaveNodeID,
|  | UINT8 * | rData,
|  | UINT32 * | rLen
| ) |  |

CAN_ERR_CODE MX_RTU_CanPDOSend | ( | int | handle,
|  | UINT8 | pdoNumber,
|  | UINT32 | slaveNodeID,
|  | UINT8 * | wData,
|  | UINT32 | wLen
| ) |  |

CAN_ERR_CODE MX_RTU_CanCyclicPDOSend | ( | int | handle,
|  | UINT8 | pdoNumber,
|  | UINT32 | slaveNodeID,
|  | UINT8 * | wData,
|  | UINT32 | wLen,
|  | UINT16 | Timer,
|  | UINT32 | Times
| ) |  |

CAN_ERR_CODE MX_RTU_CanSlaveNodeIDSet | ( | int | handle,
|  | UINT32 | slaveNodeID
| ) |  |

CAN_ERR_CODE MX_RTU_CanSlaveNodeIDGet | ( | int | handle,
|  | UINT32 * | slaveNodeID
| ) |  |

CAN_ERR_CODE MX_RTU_CanSlaveSDORegister | ( | int | handle,
|  | UINT16 | index,
|  | UINT8 | subIndex,
|  | UINT8 * | tagName
| ) |  |

CAN_ERR_CODE MX_RTU_CanSlavePDORegister | ( | int | handle,
|  | UINT8 | pdoNumber,
|  | UINT8 * | tagName
| ) |  |

CAN_ERR_CODE MX_RTU_CanSlaveStartListening | ( | int | handle | ) |

CAN_ERR_CODE MX_RTU_CanSlaveStopListening | ( | int | handle | ) |

CAN_ERR_CODE MX_RTU_CanSlaveNMTStateGet | ( | int | handle,
|  | CAN_NODE_STATE * | state
| ) |  |

CAN_ERR_CODE MX_RTU_CanSlaveEmcyMessageSend | ( | int | handle,
|  | struct CAN_Emcy_Message * | Msg
| ) |  |

CAN_ERR_CODE MX_RTU_CanSlaveSYNCGet | ( | int | handle,
|  | UINT32 * | CobID,
|  | UINT32 * | nCobID
| ) |  |

CAN_ERR_CODE MX_RTU_CanSlaveHeartbeatGet | ( | int | handle,
|  | UINT16 * | producerTime
| ) |  |

CAN_ERR_CODE MX_RTU_CanSlaveHeartbeatStateGet | ( | int | handle,
|  | CAN_NMT_HEARTBEAT_STATE * | state
| ) |  |

CAN_ERR_CODE MX_RTU_CanSlaveNodeGuardingGet | ( | int | handle,
|  | UINT16 * | guardTime,
|  | UINT8 * | lifeTimeFactor
| ) |  |

CAN_ERR_CODE MX_RTU_CanSlaveNodeGuardingStateGet | ( | int | handle,
|  | CAN_NMT_NODE_GUARDING_STATE * | state
| ) |  |

CAN_ERR_CODE MX_RTU_CanSlaveNodeGuardingStateSet | ( | int | handle,
|  | CAN_NMT_NODE_GUARDING_STATE | state
| ) |  |