Get CAN and CAN FD reception message.
Ret = CanReceive ( Id , ChannelNo , MessageNum , MessageType , CanId , DataLength , Data , ErrorCode , TickCount )
Id
[ C: short ] [ Python: ctypes.c_short ]
Specify the device ID retrieved from CanInit.
ChannelNo
[ C: unsigned short ] [ Python: ctypes.c_ushort ]
Specify the channel number.
MessageNum
[ C:unsigned int *] [ Python: ctypes.POINTER(ctypes.c_uint) ]
Specify the address that stores the number of valid received messages.
Specify the memory address that stores the prepared number of received messages (number of arrays) and call the function.
Store received messages within the range of number of received messages (array number) inside the function.
Additionally, MessageNum is overwritten with the valid number of received messages, and the function returns.
The storage range is 1 to 170.
MessageType
[ C:unsigned int *] [ Python: ctypes.POINTER(ctypes.c_uint) ]
Specify the start address of the one-dimensional array that stores the received message type.
If multiple message types are valid, the function processing returns with bitwise operations performed using logical OR.
Definition |
Value |
Description |
CCAN_MSG_TYPE_CAN |
0x01 |
CAN message |
CCAN_MSG_TYPE_CAN_FD |
0x02 |
CAN FD message |
CCAN_MSG_TYPE_REMOTE_FRAME |
0x04 |
Remote frame |
CCAN_MSG_TYPE_BITRATE_SWITCH |
0x08 |
Bitrate switch |
CCAN_MSG_TYPE_EXTENDED_FORMAT |
0X20 |
Extended format |
CanId [
C:unsigned int *] [ Python: ctypes.POINTER(ctypes.c_uint) ]
Specify the start address of the one-dimensional array that stores the received CAN ID.
If standard format is specified, it is specified by base ID (11bit).
Valid specification range is 0x000 to 0x7FF.
If extended format is specified, it is specified as extended ID + base ID (29 bits in total).
Valid specification range is 0x000 to 0x1FFFFFFF.
CanId bit number |
31 |
30 |
29 |
28 |
27 |
26 |
25 |
24 |
23 |
22 |
21 |
20 |
19 |
18 |
17 |
16 |
15 |
14 |
13 |
12 |
11 |
10 |
09 |
08 |
07 |
06 |
05 |
04 |
03 |
02 |
01 |
00 |
Extended ID/Base ID |
- |
- |
- |
Extended ID |
Base ID |
|||||||||||||||||||||||||||
Bit number of each ID |
- |
- |
- |
17 |
16 |
15 |
14 |
13 |
12 |
11 |
10 |
09 |
08 |
07 |
06 |
05 |
04 |
03 |
02 |
01 |
00 |
10 |
09 |
08 |
07 |
06 |
05 |
04 |
03 |
02 |
01 |
00 |
DataLength
[ C:unsigned short *] [ Python: ctypes.POINTER(ctypes.c_ushort)
]
Specify the start address of the one-dimensional array that stores the received message data length.
If CAN communication is specified, valid specification ranges are 0 to 8.
If CAN FD communication is specified, valid specification ranges are 0 to 8, and 12, 16, 20, 24, 32, 48, 64.
Data [
C:unsigned char *] [ Python: ctypes.POINTER(ctypes.c_ubyte) ]
Specify the start address of the two-dimensional array that will store the received data.
The number of elements (number of columns) of the two-dimensional array is 64.
ErrorCode
[ C:unsigned int *] [ Python: ctypes.POINTER(ctypes.c_uint)
]
Specify the start address of a one-dimensional array that stores errors that occur when receiving each message in CAN communication.
Definition |
Value |
Description |
CCAN_STATUS_ERR_SUCCESS |
0 |
Success |
CCAN_STATUS_ERR_BIT |
1 |
Bit error |
CCAN_STATUS_ERR_FORM |
2 |
Form error |
CCAN_STATUS_ERR_STUFF |
3 |
Stuff error |
CCAN_STATUS_ERR_ACK |
4 |
ACK error |
CCAN_STATUS_ERR_CRC |
5 |
CRC error |
CCAN_STATUS_ERR_OTHER |
6 |
Other error |
TickCount
[ C:unsigned long long *] [ Python: ctypes.POINTER(ctypes.c_ulonglong)
]
Specify the start address of the one-dimensional array that stores the tick count value when receiving.
The unit is nsec.
Ret [ C: long ] [ Python: ctypes.c_long ]
Definition |
Value |
Description |
CAN_ERR_SUCCESS |
0 |
Normality completion |
CAN_ERR_SYS_RECOVERED_FROM_STANDBY |
7 |
Execute CanResetDevice function because the device has recovered from standby mode. |
CAN_ERR_DLL_INVALID_ID |
10001 |
Invalid ID specified. |
CAN_ERR_DLL_CALL_DRIVER |
10002 |
Driver can't be called (Failed in the ioctl). |
CAN_ERR_DLL_BUFF_ADDRESS |
10100 |
Invalid data buffer address. |
CAN_ERR_SYS_CH_NO |
20101 |
Channel number is outside the settable range |
CAN_ERR_SYS_MESSAGE_NUM |
20150 |
The number of messages is outside the settable range. |
CAN_ERR_SYS_REC_FIFO_OVERFLOW |
20220 |
Receive FIFO overflowed. |
CAN_ERR_SYS_BUSOFF |
20201 |
Cannot execute because the bus is off. |
CAN_ERR_SYS_BUS_DISCONNECT |
20202 |
Cannot execute because the bus is disconnected. |
The others (See also: Details of Error Code)
None
Get CAN and CAN FD reception message.
Please verify that ErrorCode argument is CCAN_STATUS_ERR_SUCCESS before checking each reception message even though the return value is normal.
Otherwise, the data returned by the other arguments will be invalid.
For message type (MessageType), CAN ID (CanId), data length (DataLength), error code (ErrorCode) and tick count (TickCount), allocate memory in a one-dimensional array, and take the start addresses as arguments.
By specifying the message number as the index of the one-dimensional array, you can refer to the value for the target message number.
Image of one-dimensional array:
Array variable name[message number] |
Element value (example) |
MessageType[0] |
CCAN_MSG_TYPE_CAN |
MessageType[1] |
CCAN_MSG_TYPE_CAN |
MessageType[2] |
CCAN_MSG_TYPE_CAN |
MessageType[3] |
CCAN_MSG_TYPE_CAN |
... |
... |
MessageType[MessageNum - 1] |
CCAN_MSG_TYPE_CAN |
Memory is allocated for the received data (Data) as a two-dimensional array with 64 elements, and the start address is taken as an argument.
By specifying the message number as the first index of the two-dimensional array, you can refer to the received data for each message number.
By specifying the element number in the second index of the two-dimensional array, you can refer to the individual element value.
Image of two-dimensional array:
Array variable name[message number][(element number)] |
Value of element 01 |
Value of element 02 |
Value of element 03 |
... |
Value of element 64 |
Data[0][] |
Data[0][0] |
Data[0][1] |
Data[0][2] |
... |
Data[0][63] |
Data[1][] |
Data[1][0] |
Data[1][1] |
Data[1][2] |
... |
Data[1][63] |
Data[2][] |
Data[2][0] |
Data[2][1] |
Data[2][2] |
... |
Data[2][63] |
Data[3][] |
Data[3][0] |
Data[3][1] |
Data[3][2] |
... |
Data[3][63] |
... |
... |
... |
... |
... |
... |
Data[MessageNum - 1][] |
Data[MessageNum - 1][0] |
Data[MessageNum - 1][1] |
Data[MessageNum - 1][2] |
... |
Data[MessageNum - 1][63] |
Get CAN reception message from ChannelNo = 1. MessageNum =1, MessageType = CCAN_MSG_TYPE_CAN, CAN ID = 0x11c, DataLength = 1, Data = 0xff
C |
long Ret; unsigned int MessageNum; unsigned int MessageType[1]; unsigned int CanId[1]; unsigned short DataLength[1]; unsigned char Data[1][64]; unsigned long long TickCount[1]; MessageNum = 1;
|
Python |
Ret = ctypes.c_long() MessageNum = ctypes.c_uint() MessageTypeType = ctypes.c_uint() * 1 MessageType = MessageTypeType() CanIdType = ctypes.c_uint() * 1 CanId = CanIdType() DataLengthType = ctypes.c_ushort() *1 DataLength = DataLengthType() SingleDataType = ctypes.c_ubyte() * 64 DataType = ctypes.SingleDataType * 1 Data = DataType()
ErrorCodeType = = ctypes.c_uint() * 1 ErrorCode = ErrorCodeType()
TickCountType = ctypes.c_ulonglong() * 1 TickCount = TickCountType()
MessageNum = 1
Ret.value = ccan.CanReceive
( Id , 1 , ctypes.byref(MessageNum) , MessageType , CanId , Data
, ErrorCode , TickCount) |