Performs CAN or CAN FD transmission.
Ret = CanTransmit ( Id , ChannelNo , MessageNum , MessageType , CanId , DataLength , Data )
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.c_uint ]
Specify the number of messages to send.
For details, please refer to the Specifications based on devices section.
MessageType
[ C:unsigned int *] [ Python: ctypes.POINTER(ctypes.c_uint) ]
Specify the send message type in a one-dimensional array.
When specifying multiple message types, perform bitwise operations 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. *Only CAN can be enabled |
CCAN_MSG_TYPE_BITRATE_SWITCH |
0x08 |
Bitrate switch. *Only CAN FD can be enabled |
CCAN_MSG_TYPE_EXTENDED_FORMAT |
0X20 |
Extended format |
CanId [
C:unsigned int *] [ Python: ctypes.POINTER(ctypes.c_uint) ]
Specify the transmission CAN ID in a one-dimensional array.
If standard format is specified, specify with base ID (11bit).
Valid specification range is 0x000 to 0x7FF.
If extended format is specified, specify it 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 sending message data length in a one-dimensional array.
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 sending data in a two-dimensional array.
The number of elements (number of columns) of the two-dimensional array is 64.
If the data length (DataLength) of all messages is 0, specify the NULL character.
Ret [ C: long ] [ Python: ctypes.c_long ]
Definition |
Value |
Description |
CAN_ERR_SUCCESS |
0 |
Normality completion |
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_MESSAGE_TYPE |
20151 |
The messages type is outside the settable range. |
CAN_ERR_SYS_DATA_LEN |
20160 |
Data length is outside the settable range. |
CAN_ERR_SYS_CAN_ID |
20170 |
CAN ID is outside the settable range. |
CAN_ERR_SYS_TIMEOUT_TIME |
20180 |
The timeout time is outside the settable range. |
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. |
CAN_ERR_SYS_TIMEOUT |
20250 |
A timeout occurred |
The others (See also: Details of Error Code)
None
Performs CAN or CAN FD transmission.
For message type (MessageType), CAN ID (CanId), and data length (DataLength), allocate memory in a one-dimensional array, specify numerical values, and take the start addresses as arguments.
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 sending data (Data) as a two-dimensional array with 64 elements, and the start address is taken as an argument.
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] |
Model No. |
Arguments |
Content |
CAN-4P-PE |
MessageNum |
The setting should be 1 only. |
CAN-2-USB |
MessageNum |
The setting range is 1 to 90. |
Perform CAN transmission from ChannelNo = 1. MessageNum =1, MessageType = CCAN_MSG_TYPE_CAN, CAN ID = 0x11c, DataLength = 1, Data = 0xff
C |
long Ret; unsigned int MessageType[1]; unsigned int CanId[1]; unsigned short DataLength[1]; unsigned char Data[1][64];
MessageType[0] = CCAN_MSG_TYPE_CAN; CanId[0] = 0x11c; Data[0][0] = 0xff;
|
Python |
Ret = ctypes.c_long() 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()
MessageType[0] = CCAN_MSG_TYPE_CAN CanId[0] = 0x11c Data[0][0] = 0xff
Ret.value = ccan.CanTransmit ( Id , 1 , 1 , MessageType , CanId , Data )
|