Get CAN and CAN FD reception message.
Ret = CanReceive ( Id , ChannelNo , MessageNum , MessageType , CanId , DataLength , Data , ErrorCode , TickCount )
Id
[ VB.NET: Short ] [ C, C++: short ] [ C#: short ]
Specify the device ID retrieved from CanInit.
ChannelNo
[ VB.NET: UShort ] [ C, C++: unsigned short ] [ C#: ushort ]
Specify the channel number.
MessageNum
[ VB.NET: UInteger ] [ C, C++: unsigned long * ] [ C#: out uint
]
Specifies 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
[ VB.NET: UInteger ] [ C, C++: unsigned long * ] [ C#: out 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. *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 [
VB.NET: UInteger ] [ C, C++: unsigned long * ] [ C#: out 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
[ VB.NET: UShort ] [ C, C++: unsigned short * ] [ C#: out 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 [
VB.NET: Byte ] [ C, C++: unsigned char * ] [ C#: out byte ]
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
[ VB.NET: UShort ] [ C, C++: unsigned short * ] [ C#: out ushort
]
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
[ VB.NET: UInteger ] [ C, C++: unsigned long * ] [ C#: out uint
]
Specify the start address of the one-dimensional array that stores the
tick count value when receiving.
The unit is nsec.
Ret [ VB.NET: Integer ] [ C, C++: long ] [ C#: int ]
Definition |
Value [Dec] |
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 device I/O control). |
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.
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.
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.
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
VB.NET |
Dim Ret As Integer Dim MessageNum As UInteger Dim MessageType(0) As UInteger Dim CanId(0) As UInteger Dim DataLength(0) As UShort Dim Data(0)(63) As Byte Dim ErrorCode(0) As UShort Dim TickCount(0) As UInteger
MessageNum = 1
Ret = CanReceive ( Id
, 1 , MessageNum , MessageType , CanId , Data , ErrorCode , TickCount
) |
C, C++ |
long Ret; unsigned long MessageNum; unsinged long MessageType[1]; unsinged long CanId[1]; unsinged short DataLength[1]; unsinged char Data[1][64]; unsinged short ErrorCode[1]; unsinged long TickCount[1];
MessageNum = 1;
|
C# |
int Ret; uint MessageNum = new unit; uint[] MessageType = new unit[1]; uint[] CanId = new uint[1]; ushort[] DataLength = new ushort[1]; ubyte[,] Data = new ubyte[1,64]; ushort[] ErrorCode = new ushort[1]; uint[] TickCount = new uint[1];
MessageNum = 1;
|