Set the CAN communication timing.
Ret = CanSetCanTiming ( Id , ChannelNo , Bitrate , TSeg1 , SJW , TSeg2 )
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.
Bitrate
[ VB.NET: UInteger ] [ C, C++: unsigned long ] [ C#: uint ]
Specify the bitrate.
The specified range varies depending on the device.
For details, please refer to the Specifications based on devices section.
TSeg1 [
VB.NET: UShort ] [ C, C++: unsigned short ] [ C#: ushort ]
Specify the time segment 1.
For details, please refer to the Specifications based on devices section.
SJW [
VB.NET: UShort ] [ C, C++: unsigned short ] [ C#: ushort ]
Specify the SJW. (Synchronization Jump Width)
For details, please refer to the Specifications based on devices section.
TSeg2 [
VB.NET: UShort ] [ C, C++: unsigned short ] [ C#: ushort ]
Specify the time segment 2.
For details, please refer to the Specifications based on devices section.
Ret [ VB.NET: Integer ] [ C, C++: long ] [ C#: int ]
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 device I/O control). |
CAN_ERR_SYS_CH_NO |
20101 |
Channel number is outside the settable range. |
CAN_ERR_SYS_BITRATE |
20110 |
The bit rate is outside the settable range. |
CAN_ERR_SYS_TSEG1 |
20120 |
Time segment 1 is outside the settable range. |
CAN_ERR_SYS_SJW |
20121 |
Synchronization Jump Width is outside the settable range. |
CAN_ERR_SYS_TSEG2 |
20122 |
Time segment 2 is outside the settable range. |
CAN_ERR_SYS_TIMING_COMBINATION |
20144 |
This is a combination in which the communication parameters cannot be set. |
CAN_ERR_SYS_BUSON |
20200 |
Cannot execute because the bus is on. |
The others (See also: Details of Error Code)
None
Set the CAN communication timing.
Setting is possible only when the CAN bus is not connected.
It depends on the combination of the CAN
communication clock installed in the device and the prescaler to divide
this clock.
Therefore, there are restrictions on the combinations of Bitrate, TSeg1,
TSeg2, SJW that can be set on the device, and if it is not possible to
set it, it will be corrected to a similar value.
Use CanGetCanTiming
function to ensure that the bitrate and sample point ratio are the desired
values.
It is easy to check using the CAN communication sample program.
For details, please refer to CAN
communication transmission time.
Model No. |
Arguments |
Content |
CAN-4P-PE |
Bitrate |
The setting range is 60000 to 1000000. The unit is bps. (bit per second) |
TSeg1 |
The setting range is 2 to 513. The unit is TQ. |
|
SJW |
The setting range is 1 to 127. Also, please set time segment 2 (TSeg2) as follows. The unit is TQ. |
|
TSeg2 |
The setting range is 1 to 128. Also, please set the synchronization jump width (SJW) as above. The unit is TQ. |
|
CAN-2-USB |
Bitrate |
The setting range is 5000 to 1000000. The unit is bps. (bit per second) |
TSeg1 |
The setting range is 2 to 16. The unit is TQ. |
|
SJW |
The setting range is 1 to 4. Also, please set time segment 2 (TSeg2) as follows. The unit is TQ. |
|
TSeg2 |
The setting range is 1 to 8. The unit is TQ. |
Set Bitrate = 1000000 bps, TSeg1 = 100TQ, SJW = 60TQ, TSeg2 = 60TQ to ChannelNo = 1.
VB.NET |
Dim Ret As Integer Ret = CanSetCanTiming
( Id , 1 , 1000000 , 100 , 60 , 60 ) |
C, C++ |
long Ret; |
C# |
int Ret; |