CAN-bus Common Test Software and Interface Function Library Usage
CAN-bus Common Test Software and Interface Function Library Usage
User
Manual
V1.00
Date: 2012/12/19
www.zlgmcu.com
Guangzhou ZHIYUAN Electronics Stock Co., Ltd.
User Manual
CAN-bus Series
Revision History
Version
V1.00
Rev. Date
2012-12-19
Modifications
Original version
User Manual
Date: 2011/05/19
V1.02
i
CAN-bus Series
Sales Information
FAX:
+86-20-38730925
Website: www.zlgmcu.com
Guangzhou Sales Office
User Manual
Date: 2011/05/19
V1.02
ii
CAN-bus Series
Technical Supports
FAX:
+86-20 38601859
Website: www.embedtools.com
www.embedcontrol.com
www.ecardsys.com
Technical Supports
CAN-bus
TEL:
+86-20-22644381, 22644382, 22644253
E-mail: [email protected]
TEL:
+86-20-28872344, 22644373
E-mail: [email protected]
MiniARM
Ethernet
TEL:
+86-20-28872684, 28267813
E-mail: [email protected]
TEL:
+86-20-22644380, 22644385
E-mail: [email protected]
Wireless Communication
Serial Communication
TEL:
+86-20-22644386
E-mail: [email protected]
TEL:
+86-20-28267800, 22644385
E-mail: [email protected]
Programmer
TEL:
+86-20-22644371
E-mail: [email protected]
TEL:
+86-20-22644375, 28872624, 28872345
E-mail: [email protected]
Building Automation
TEL:
TEL:
+86-20-22644376, 22644389, 28267806
E-mail: [email protected]
+86-20-28872347, 28872377,
22644383, 22644384
E-mail: [email protected]
Sales Contact
TEL:
+86-20-22644245
User Manual
Date: 2011/05/19
V1.02
iii
CAN-bus Series
Contents
Chapter 1: Test Software Usage .................................................................. 1
1.1 Device operation................................................................................................... 1
1.1.1 Select device type ..................................................................................................... 1
1.1.2 Filter setting ............................................................................................................. 3
1.1.3 Start CAN ................................................................................................................. 3
1.1.4 Obtain device information........................................................................................ 4
1.1.5 Data transmission ..................................................................................................... 4
1.2 Auxiliary operation ............................................................................................... 5
1.2.1 Frame ID display mode ............................................................................................ 5
1.2.2 Frame ID display format .......................................................................................... 5
1.2.3 Continue to display sent and received data .............................................................. 5
1.2.4 Pause to display sent and received data.................................................................... 5
1.2.5 Roll ........................................................................................................................... 5
1.2.6 Display frame number .............................................................................................. 5
1.2.7 Language .................................................................................................................. 6
V1.02
iv
CAN-bus Series
2.4.12 VCI_ResetCAN.................................................................................................... 40
2.4.13 VCI_Transmit....................................................................................................... 41
2.4.14 VCI_Receive ........................................................................................................ 42
2.5 Interface library function usage........................................................................ 43
2.5.1 Calling dynamic library with VC ........................................................................... 43
2.5.2 Calling dynamic library with VB ........................................................................... 43
2.6 Interface library function usage flow ............................................................... 45
User Manual
Date: 2011/05/19
V1.02
v
CAN-bus Series
User Manual
Date: 2012/12/19
V1.02
1
CAN-bus Series
V1.02
2
CAN-bus Series
In this dialog box, you can select the device index to be open and CAN channel, and
then set the initialization parameters. When finishing setting, click the OK button to
open the device operation window, or click OK and Start CAN button to open the device
operation window and start the device and CAN channel automatically,
V1.02
3
CAN-bus Series
User Manual
Date: 2012/12/19
V1.02
4
CAN-bus Series
1.2.5 Roll
When select this option, the last line of the current data list is always visible.
V1.02
5
CAN-bus Series
1.2.7 Language
This option is used to select language.
User Manual
Date: 2012/12/19
V1.02
6
CAN-bus Series
Type
PCI5121
PCI9810
USBCAN1
USBCAN2
PCI9820
CAN232
PCI5110
CANlite(CANmini)
ISA9620
ISA5420
10
PC104-CAN
11
CANET-UDP
12
DNP9810
13
PCI9840
14
PC104-CAN2
15
PCI9820I
16
CANET-TCP
17
PEC-9920
18
PCIE-9220
18
PCI-5010-U
19
USBCAN-E-U
20
USBCAN-2E-U
21
PCI-5020-U
22
EG20T-CAN
23
User Manual
Date: 2012/12/19
V1.02
7
CAN-bus Series
Value
Description
0x00000001
ERR_CAN_ERRALARM
0x00000002
ERR_CAN_PASSIVE
0x00000004
ERR_CAN_LOSE
0x00000008
ERR_CAN_BUSERR
0x00000010
ERR_CAN_BUSOFF
0x00000020
0x00000100
ERR_DEVICEOPEN
0x00000200
ERR_DEVICENOTOPEN
0x00000400
ERR_BUFFEROVERFLOW
0x00000800
Buffer overflow
ERR_DEVICENOTEXIST
0x00001000
ERR_LOADKERNELDLL
0x00002000
ERR_CMDFAILED
0x00004000
ERR_BUFFERCREATE
0x00008000
Insufficient memory
0x00010000
ERR_CANETE_INDEXUSED
0x00020000
ERR_REF_TYPE_ID
0x00030001
SetReference or GetReference is a
transferred RefType which is not exist
ERR_CREATE_SOCKET
0x00030002
ERR_OPEN_CONNECT
0x00030003
ERR_NO_STARTUP
0x00030004
ERR_NO_CONNECTED
0x00030005
ERR_SEND_PARTIAL
0x00030006
ERR_SEND_TOO_FAST
0x00030007
V1.02
8
CAN-bus Series
can_Num;
CHAR
str_Serial_Num[20];
CHAR
str_hw_Type[40];
USHORT Reserved[4];
} VCI_BOARD_INFO, *PVCI_BOARD_INFO;
2.3.1.2 Member
hw_Version
Hardware version number (Hexadecimal). For example, 0x0100 is for V1.00.
fw_Version
Firmware version number (Hexadecimal)
dr_Version
Driver version number (Hexadecimal)
in_Version
Interface library version number (Hexadecimal)
irq_Num
Interrupt number for Board card
can_Num
The quality of the CAN channel
str_Serial_Num
Board card serial number
str_hw_Type
This is for Hardware type, such as USBCAN V1.00. (Notice: It includes character
string terminator \0).
Reserved
System reserved item
2.3.2 VCI_CAN_OBJ
2.3.2.1 Description
VCI_CAN_OBJ structure is used to transfer CAN information frame in VCI_Transmit
User Manual
Date: 2012/12/19
V1.02
9
CAN-bus Series
ID;
UINT
TimeStamp;
BYTE
TimeFlag;
BYTE
SendType;
BYTE
RemoteFlag;
BYTE
ExternFlag;
BYTE
DataLen;
BYTE
Data[8];
BYTE
Reserved[3];
} VCI_CAN_OBJ, *PVCI_CAN_OBJ;
2.3.2.2 Member
ID
Message ID
TimeStamp
This is the time stamp for when information frame is received. It is counted since CAN
controller is initialized.
TimeFlag
This is used to indicate whether the time stamp is in used, in which 1 for TimeStamp is
valid. TimeFlag and TimeStamp are effective only when the frame is a received frame.
SendType
This is used to indicate the transmission mode, in which 0 is for normal, 1 is for single
transmission, 2 is for receive own message, 3 is for receive own message once.
SendType is effective only when the frame is a received frame. (For EG20T-CAN device,
the transmission mode is set in VCI_InitCan function. In this case, the setting on here is
invalid. For receive own message setting, G20T-CAN will not receive any data from the
bus, but only receive the data send by itself.)
RemoteFlag
This is used to indicate whether the frame is a remote frame.
ExternFlag
This is used to indicate whether the frame is an extend frame.
DataLen
Data length (<=8)
Data
Data in the message
Reserved
System reserved item
User Manual
Date: 2012/12/19
V1.02
10
CAN-bus Series
2.3.3 VCI_CAN_STATUS
2.3.3.1 Description
VCI_CAN_STATUS structure contains CAN controller status information. This structure
will be filled within VCI_ReadCanStatus function.
typedef struct _VCI_CAN_STATUS {
UCHAR
ErrInterrupt;
UCHAR
regMode;
UCHAR
regStatus;
UCHAR
regALCapture;
UCHAR
regECCapture;
UCHAR
regEWLimit;
UCHAR
regRECounter;
UCHAR
regTECounter;
DWORD
Reserved;
} VCI_CAN_STATUS, *PVCI_CAN_STATUS;
2.3.3.2 Member
ErrInterrupt
This is the interrupt logging. It is cleared by reading.
regMode
CAN controller mode register
regStatus
CAN controller status register
regALCapture
CAN controller arbitration lost register
regECCapture
CAN controller error register
regEWLimit
CAN controller error warning limit register
regRECounter
CAN controller receive error register
regTECounter
CAN controller transmit error register
Reserved
System reserved item
User Manual
Date: 2012/12/19
V1.02
11
CAN-bus Series
2.3.4 VCI_ERR_INFO
2.3.4.1 Description
VCI_ERR_INFO structure is used to load the VCI library running error information. This
structure will be filled within VCI_ReadErrInfo function.
typedef struct _ERR_INFO {
UINT ErrCode;
BYTE Passive_ErrData[3];
BYTE ArLost_ErrData;
} VCI_ERR_INFO, *PVCI_ERR_INFO;
2.3.4.2 Member
ErrCode
Error code (Refer to the definition of error code in the Section 2.2 of Chapter 2)
Passive_ErrData
When passive error occurs, it indicates the error marking data of passive error.
ArLost_ErrData
When arbitration lost error occurs, it indicates the error marking data of arbitration lost
error.
2.3.5 VCI_INIT_CONFIG
2.3.5.1 Description
VCI_INIT_CONFIG structure defines the configuration for CAN initialization. This
structure will be filled within VCI_InitCan function.
typedef struct _INIT_CONFIG {
DWORD
AccCode;
DWORD
AccMask;
DWORD
Reserved;
UCHAR
Filter;
UCHAR
Timing0;
UCHAR
Timing1;
UCHAR
Mode;
} VCI_INIT_CONFIG, *PVCI_INIT_CONFIG;
User Manual
Date: 2012/12/19
V1.02
12
CAN-bus Series
2.3.5.2 Member
AccCode
This is the verification code.
AccMask
This is the mask code.
Reserved
System reserved
Filter
This is the filter mode
Timing0
This is the Timer 0 (BTR0)
Timing1
This is the Timer 1 (BTR1)
Mode
This is the mode.
2.3.5.3 Remark
This structure is described in detailed in Table 2-3.
Timing0 and Timing1 are used to set the CAN baudrate. The tabel below lists the
common baud rate settings.
CAN baud rate
Timer 0
Timer 1
5Kbps
0xBF
0xFF
10Kbps
0x31
0x1C
20Kbps
0x18
0x1C
40Kbps
0x87
0xFF
50Kbps
0x09
0x1C
80Kbps
0x83
0Xff
100Kbps
0x04
0x1C
125Kbps
0x03
0x1C
200Kbps
0x81
0xFA
250Kbps
0x01
0x1C
400Kbps
0x80
0xFA
500Kbps
0x00
0x1C
666Kbps
0x80
0xB6
800Kbps
0x00
0x16
1000Kbps
0x00
0x14
User Manual
Date: 2012/12/19
V1.02
13
CAN-bus Series
2.3.6 CHGDESIPANDPORT
2.3.6.1 Description
CHGDESIPANDPORT structure is used to load the necessary information of the target
IP and port for changing CANET-E. This structure is applied in CANETE-E.
typedef struct _tagChgDesIPAndPort {
char szpwd[10];
char szdesip[20];
int desport;
BYTE blisten;
} CHGDESIPANDPORT;
2.3.6.2 Member
szpwd[10]
This is the password for changing target IP and port. The length should be less than 10,
such as 11223344.
szdesip[20]
This is the target IP to be changed, such as 192.168.0.111.
desport
This is the target port to be changed, such as 4000.
blisten
This is the operation mode to be changed, 0 for normal mode and 1 for listen only
mode.
2.3.7 VCI_FILTER_RECORD
2.3.7.1 Description
VCI_FILTER_RECORD structure defines the filtering range of the CAN filter. This
structure will be filled within VCI_SetReference function.
typedef struct _VCI_FILTER_RECORD{
DWORD ExtFrame;
DWORD Start;
DWORD End;
} VCI_FILTER_RECORD,*PVCI_FILTER_RECORD;
User Manual
Date: 2012/12/19
V1.02
14
CAN-bus Series
2.3.7.2 Member
ExtFrame
This is the frame type flag for filtering, 1 for extend frame and 0 for standard frame.
Start
This is the ID of start frame in the filtering range.
End
This is the ID of end frame in the filtering range.
2.4.1.2 Parameters
DevType
This is the type of device.
DevIndex
This is the index number of device. For example, when there is only one PCI5121, the
index number is 0. For two devices, the index number can be 0 or 1. (Notice: For
CAN232, 0 is for opening COM1, and 1 is for opening COM2.)
Reserved
For CAN232, this parameter is used to indicate the baud rate for the serial port. It can
be 2400, 4800, 9600, 14400, 19200, 28800 or 57600. For CANET-UDP, this parameter
indicates the local port number to be open. The range of it can be from 5000 to 40000.
For CANET-TCP, this parameter is fixed with 0. However, for other devices, this
parameter is invalid.
Return value
When return 1, operation is successful; when return 0, operation is failure.
2.4.1.3 Example
#include "ControlCan.h"
int nDeviceType = 6;
/* CAN232 */
int nDeviceInd = 0;
/* COM1 */
User Manual
Date: 2012/12/19
V1.02
15
CAN-bus Series
/* Baud rate */
DWORD dwRel;
2.4.2 VCI_CloseDevice
2.4.2.1 Description
This function is used to close device.
DWORD __stdcall VCI_CloseDevice(DWORD DevType, DWORD DevIndex);
2.4.2.2 Parameters
DevType
This is the type of device.
DevIndex
This is the index number of device. For example, when there is only one PCI5121, the
index number is 0. For two devices, the index number can be 0 or 1. (Notice: For
CAN232, 0 is for opening COM1, and 1 is for opening COM2.)
Return value
When return 1, operation is successful; when return 0, operation is failure.
2.4.2.3 Example
#include "ControlCan.h"
int nDeviceType = 6;
// CAN232
int nDeviceInd = 0;
// COM1
BOOL bRel;
2.4.3 VCI_InitCan
2.4.3.1 Description
User Manual
Date: 2012/12/19
V1.02
16
CAN-bus Series
This function is used to initialize the specific CAN channel. (For USBCAN-E-U or
USBCAN-2E-U, the baud rate should be set by VCI_SetReference function before
VCI_InitCan function is called)
DWORD
__stdcall
VCI_InitCan(DWORD
DevType,
DWORD
DevIndex,
DWORD
CANIndex,
PVCI_INIT_CONFIG pInitConfig);
2.4.3.2 Parameters
DevType
This is the type of device.
DevIndex
This is the index number of device. For example, when there is only one PCI5121, the
index number is 0. For two devices, the index number can be 0 or 1. (Notice: For
CAN232, 0 is for opening COM1, and 1 is for opening COM2.)
CANIndex
This is the index number of CAN channel.
pInitConfig
It is used to initialize parameter structure. (Notes: 1. For CAN232, this parameter should
beset to NULL; 2. For PCI-5010-U/PCI-5020-U/USBCAN-E-U/USBCAN-2E-U, the
settings about filtering and baud rate should be configured in VCI_SetReference. And
only Mode is needed to be set in pInitConfig, while other 6 member can be ignored. For
more detailed information, please refer to VCI_SetReference).
Table 2-3: Initial parameter structure
Member
Description
pInitConfig->AccCode
pInitConfig->AccMask
pInitConfig->Reserved
Reserved
Filter mode, 1 for single filtering, 0 for double filtering
(For EG20T-CAN, 0 means receive standard frame and extend
pInitConfig->Filter
frame; 1 means only receive and filter standard frame, extend frame
is not received; 3 means only receive and filter extend frame,
standard frame is not received
pInitConfig->Timing0
Timer 0
pInitConfig->Timing1
Timer 1
pInitConfig->Mode
User Manual
Date: 2012/12/19
V1.02
17
CAN-bus Series
For single filtering mode, when the received frame is set to be a standard frame:
For double filtering mode, when the received frame is set to be a standard frame:
User Manual
Date: 2012/12/19
V1.02
18
CAN-bus Series
For double filtering mode, when the received frame is set to be a extend frame:
User Manual
Date: 2012/12/19
V1.02
19
CAN-bus Series
Return value
When return 1, operation is successful; when return 0, operation is failure. (Notes: This
function is not exist in CANET, so it will return 1 when calling this function)
2.4.3.3 Example
#include "ControlCan.h"
int nDeviceType = 6;
// CAN232
int nDeviceInd = 0;
// COM1
int nCANInd = 0;
int nReserved = 9600;
// Baudrate
VCI_INIT_CONFIG vic;
DWORD dwRel;
User Manual
Date: 2012/12/19
V1.02
20
CAN-bus Series
2.4.4 VCI_ReadBoardInfo
2.4.4.1 Description
This function is used to obtain device information. (For EG20T-CAN, this function is not
supported)
DWORD __stdcall VCI_ReadBoardInfo(DWORD DevType, DWORD DevIndex, PVCI_BOARD_INFO pInfo);
2.4.4.2 Parameter
DevType
This is the type of device.
DevIndex
This is the index number of device. For example, when there is only one PCI5121, the
index number is 0. For two devices, the index number can be 0 or 1. (Notice: For
CAN232, 0 is for opening COM1, and 1 is for opening COM2.)
pInfo
This is a VCI_BOARD_INFO structure pointer for device information storage.
Return value
When return 1, operation is successful; when return 0, operation is failure. (Notes: This
function is not exist in CANET, so it will return 0 when calling this function, and error
code ERR_CMDFAILED will be return as well
2.4.4.3 Example
#include "ControlCan.h"
int nDeviceType = 6;
// CAN232
int nDeviceInd = 0;
// COM1
int nCANInd = 0;
VCI_INIT_CONFIG vic;
VCI_BOARD_INFO vbi;
User Manual
Date: 2012/12/19
V1.02
21
CAN-bus Series
2.4.5 VCI_ReadErrInfo
2.4.5.1 Description
This function is used to obtain the last error information (For EG20T-CAN, this function
is not supported)
DWORD
__stdcall
VCI_ReadErrInfo(DWORD
DevType,
DWORD
DevIndex,
DWORD
CANIndex,
PVCI_ERR_INFO pErrInfo);
2.4.5.2 Parameters
DevType
This is the type of device.
DevIndex
This is the index number of device. For example, when there is only one PCI5121, the
index number is 0. For two devices, the index number can be 0 or 1. (Notice: For
CAN232, 0 is for opening COM1, and 1 is for opening COM2.)
CANIndex
This is the index number of CAN channel. (Notes: When reading device error, this
parameter should be set to -1. For example, if VCI_OpenDevice, VCI_CloseDevice or
VCI_ReadBoardInfo function call fails, when calling this function to obtain error code,
user should set CANIndex to -1 at first)
pErrInfo
This is the VCI_ERR_INFO structure pointer for error information storage.
pErrInfo->ErrCode may be any combination of the following error codes. (For other
errors, please refer to error code definition 2.2)
ErrCode
Passive_ErrData
ArLost_ErrData
0x0100
No
No
Device is open
0x0200
No
No
0x0400
No
No
0x0800
No
No
Buffer overflow
0x1000
No
No
0x2000
No
No
0x4000
No
No
No
Insufficient memory
No
CAN
0x8000
0x0001
No
Description
controller
internal
FIFO overflow
User Manual
Date: 2012/12/19
V1.02
22
CAN-bus Series
Passive_ErrData
ArLost_ErrData
0x0002
No
No
Description
CAN
controller
error
warning
0x0004
No
0x0008
No
lost
below
0x0010
No
No
Return value
When return 1, operation is successful; when return 0, operation is failure.
2.4.5.3 Remark
When (PErrInfo->ErrCode&0x0004)==0x0004, CAN controller passive error occurs.
The table below lists the bit interpretation of PErrInfo->Passive_ErrData[0] error code
capture bit.
Bit7
Bit6
Bit5
Bit4
Bit3
Error
Bit2
Bit1
Bit0
attribute
Bit ECC.6
Function
Bit error
Format error
Stuff error
Other error
bit 3
bit 2
bit 1
bit 0
start of frame
ID.28 to ID.21
ID.20 to ID.18
bit SRTR
bit IDE
ID.17 to ID.13
User Manual
Date: 2012/12/19
Function
V1.02
23
CAN-bus Series
bit 3
bit 2
bit 1
bit 0
Function
ID.12 to ID.5
ID.4 to ID.0
bit RTR
reserved bit 1
reserved bit 0
data field
CRC sequence
CRC delimiter
acknowledge slot
acknowledge delimiter
end of frame
intermission
error delimiter
overload flag
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Bit interpretation of the arbitration lost capture register is shown in the table below:
Bit
Decimal value
Function
ALC.4
ALC.3
ALC.2
ALC.1
ALC.0
10
User Manual
Date: 2012/12/19
V1.02
24
CAN-bus Series
Decimal value
Function
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2.4.5.5 Example
#include "ControlCan.h"
int nDeviceType = 6;
// CAN232
int nDeviceInd = 0;
// COM1
int nCANInd = 0;
VCI_ERR_INFO vei;
DWORD dwRel;
2.4.6 VCI_ReadCanStatus
2.4.6.1 Description
This function is used to obtain CAN channel state.
DWORD __stdcall VCI_ReadCanStatus(DWORD DevType, DWORD DevIndex, DWORD CANIndex,
PVCI_CAN_STATUS pCANStatus);
User Manual
Date: 2012/12/19
V1.02
25
CAN-bus Series
2.4.6.2 Parameters
DevType
This is the type of device.
DevIndex
This is the index number of device. For example, when there is only one PCI5121, the
index number is 0. For two devices, the index number can be 0 or 1. (Notice: For
CAN232, 0 is for opening COM1, and 1 is for opening COM2.)
CANIndex
This is the index number of CAN channel.
pCANStatus
This is the VCI_CAN_STATUS structure pointer for CAN state storage.
Return value
When return 1, operation is successful; when return 0, operation is failure. (Notes: This
function is not exist in CANET, so it will return 0 when calling this function, and error
code ERR_CMDFAILED will be return as well
2.4.6.3 Example
#include "ControlCan.h"
int nDeviceType = 6;
// CAN232
int nDeviceInd = 0;
// COM1
int nCANInd = 0;
VCI_INIT_CONFIG vic;
VCI_CAN_STATUS vcs;
DWORD dwRel;
2.4.7 VCI_GetReference
2.4.7.1 Description
This function is used to obtain the parameters of device.
DWORD __stdcall VCI_GetReference(DWORD DevType, DWORD DevIndex, DWORD CANIndex, DWORD
RefType, PVOID pData);
2.4.7.2 Parameters
DevType
This is the type of device.
User Manual
Date: 2012/12/19
V1.02
26
CAN-bus Series
DevIndex
This is the index number of device. For example, when there is only one PCI5121, the
index number is 0. For two devices, the index number can be 0 or 1. (Notice: For
CAN232, 0 is for opening COM1, and 1 is for opening COM2.)
CANIndex
This is the index number of CAN channel.
RefType
This is the type of the reference parameter.
pData
This is the buffer head pointer for parameter storage.
Return value
When return 1, operation is successful; when return 0, operation is failure.
2.4.7.3 Remark
(1) For PCI5121, CI5110 or SA5420:
RefType
1
pData
Description
Length: 2 bytes
09H in a register
controller
VCI_GetReference(DeviceType,DeviceInd,CANInd,1,p
Data);
pData
Description
Length: 1 byte
controller
address
BYTE val=0;
of
the
control
VCI_GetReference(VCI_USBCAN1,0,0,1,(PVOID)&val
to be read;
);
When it is used as an
User Manual
Date: 2012/12/19
V1.02
27
CAN-bus Series
pData
Description
Length: 1 byte
controller
address
BYTE val=0;
of
the
control
VCI_GetReference(VCI_USBCAN1,0,0,1,(PVOID)&val
to be read;
);
When it is used as an
be returned in val
bytes;
For example:
BYTE buf[12];
WORD addr=0,readlen=8;
VCI_GetReference(VCI_USBCAN1,0,0,20,(PVOID)&b
When it is used as an
uf);
pData
Character
string
Description
head
For example:
char szip[20];
VCI_GetReference(VCI_CANETE,0,0,0,(PVOID)szip);
If this function is called successfully, CANET-E address
will be returned in szip
For example:
int port;
VCI_GetReference(VCI_CANETE,0,0,1,(PVOID)&port);
If this function is called successfully, the CANET-E
operation port will be returned in the parameter port
User Manual
Date: 2012/12/19
V1.02
28
CAN-bus Series
pData
pointer; it is used to
For example:
char szip[20];
read
VCI_GetReference(VCI_CANETE,0,0,0,(PVOID)szip);
out
Description
from
the
CANETE-E
Length: 4 bytes; it is
For example:
operation port to be
int port;
read out
VCI_GetReference(VCI_CANETE,0,0,1,(PVOID)&port);
If this function is called successfully, the CANET-E
operation port will be returned in the parameter port
Length: 4 bytes; it is
For example:
int port;
VCI_SetReference(VCI_CANET_TCP,0,0,2,(PVOID)&port);
available)
Length: 4 bytes; it is
For example:
TCP device
int iType = 1;
VCI_SetReference(VCI_CANET_TCP,0,0,4,(PVOID)&iTyp
e);
If this function is called successfully, device will be set to
work at Server mode
Length: 4 bytes; it is
used
the
For example:
the
int iCount;
to
number
obtain
of
VCI_GetReference( VCI_CANET_TCP,0,0,5,(PVOID)&iCo
available
unt);
only
when
mode
REMOTE_CLIENT
For example:
connection information
REMOTE_CLIENT cli;
(it
cli.iIndex = 0;
is available
only
User Manual
Date: 2012/12/19
V1.02
29
CAN-bus Series
pData
Description
Client mode
REMOTE_CLIENT structure
typedef struct tagRemoteClient{
int iIndex;
DWORD port;
HANDLE hClient;
char szip[32];
}REMOTE_CLIENT;
pData
Description
Length: 14 bytes;
following:
BYTE info[14];
info[0]=1;
VCI_GetReference(VCI_CAN232,0,0,1,(PVOID)info);
of it is 1, 2, 3 or 4
When it is used as an
Length: 1 byte
controller
For example:
address
BYTE val=0;
of
the
control
VCI_GetReference(VCI_CAN232,0,0,2,(PVOID)&val);
to be read;
When it is used as an
be returned in val
When RefType=1, the meanings of each byte in the returned pData are as following:
pData[0] is for reserved
pData[1] is for the value of CAN controller BTR0;
pData[2] is for the value of CAN controller BTR1;
pData[3] is for reading the operation mode of acceptance filter; its bit interpretation is
listed as below:
STATUS.7
STATUS.6
STATUS.5
STATUS.4
STATUS.3
User Manual
Date: 2012/12/19
STATUS.2
STATUS.1
STATUS.0
MFORMATB
AMODEB
V1.02
30
CAN-bus Series
MFORMATB
=1; acceptance filter is only available for extend frame information; the
standard frame information will be ignored.
=0; acceptance filter is only available for standard frame information;
the extend frame information will be ignored.
AMODEB
pData[4] is for reading the state of acceptance filter (enabled or not); its bit interpretation
is listed as below:
STATUS.7
STATUS.6
STATUS.5
STATUS.4
STATUS.3
STATUS.2
BF2EN
STATUS.1
STATUS.0
BF2EN
BF1EN
=1; filter 2 is enabled, and writing shield and code registers are not allowed;
=0; filter 2 is disabled, and shield and code registers can be written.
BF1EN
=1; filter 1 is enabled, and writing shield and code registers are not allowed;
=0; filter 1 is disabled, and shield and code registers can be written.
Notes: For single filter mode, the single filter is related to the filter 1 enable bit. And filter 2 enable bit
is ineffective under this mode.
pData[5] is for reading the priory level of acceptance filter (enabled or not); its bit
interpretation is listed as below:
STATUS.7
STATUS.6
STATUS.5
STATUS.4
STATUS.3
STATUS.2
STATUS.1
STATUS.0
BF2PRIO
BF1PRIO
BF2PRIO =1; Filter 2 has higher priory level. If there is message come into filer 2,
receive interrupt will be generated immediately;
=0Filter 2 has lower priory level. When FIFO level has passed the receive
interrupt level, receive interrupt will be generated;
BF1PRIO =1; Filter 1 has higher priory level. If there is message come into filer 2,
receive interrupt will be generated immediately;
=0 Filter 1 has lower priory level. When FIFO level has passed the receive
interrupt level, receive interrupt will be generated.
pData[69] is for the ACR value of this filter;
pData[ad] is for the AMR value of this filter.
2.4.7.4 Example
#include "ControlCan.h"
int nDeviceType = 6;
// CAN232
int nDeviceInd = 0;
// COM1
int nCANInd = 0;
BYTE info[14];
User Manual
Date: 2012/12/19
V1.02
31
CAN-bus Series
info[0] = 1;
bRel = VCI_GetReference(nDeviceType, nDeviceInd, nCANInd, 1, (PVOID)info);
2.4.8 VCI_SetReference
2.4.8.1 Description
This function is used to set the parameters of the device, to handle different specific
operations of the device.
DWORD __stdcall VCI_SetReference(DWORD DevType, DWORD DevIndex, DWORD CANIndex, DWORD
RefType, PVOID pData);
2.4.8.2 Parameters
DevType
This is the type of device.
DevIndex
This is the index number of device. For example, when there is only one PCI5121, the
index number is 0. For two devices, the index number can be 0 or 1. (Notice: For
CAN232, 0 is for opening COM1, and 1 is for opening COM2.)
CANIndex
This is the index number of CAN channel.
RefType
This is the type of the reference parameter.
pData
This is the buffer head pointer for parameter storage.
Return value
When return 1, operation is successful; when return 0, operation is failure.
2.4.8.3 Remark
VCI_SetReference and VCI_GetReference functions are used for specific operations,
such as modifying the baud rate of CAN232 or setting message filter. The meaning of
the PVOID type parameter pData is depended on operation.
User Manual
Date: 2012/12/19
V1.02
32
CAN-bus Series
pData
Description
Length: 2 bytes
pData[0]
is
the
is
the
control
pData
Description
Length: 2 bytes
pData[0]
is
the
is
the
control
pData
Description
Length: 2 bytes
pData[0]
is
the
is
the
control
bytes;
For example:
BYTE buf[12];
WORD addr=0,writelen=8;
written
VCI_SetReference(VCI_USBCAN1,0,0,20,(PVOID)&bu
data to be wrritten
f);
pData
Character
string
Description
head
User Manual
Date: 2012/12/19
V1.02
33
CAN-bus Series
pData
to
the
Description
CANET-UDP
DWORD port=5000;
VCI_SetReference(12,0,0,1,(PVOID)&port);
out
pData
Character
Description
string
head
store
the
operation
CANET
It is read only.
Length:
It is read only.
REMOTE_CLIENT,
used
to
it
store
is
the
connection information
7
For example:
REMOTE_CLIENT
REMOTE_CLIENT cli;
structure
to
delete
cli.iIndex = 0;
VCI_SetReference(VCI_CANET_TCP,0,0,7,(PVOID)&c
li);
Client mode
REMOTE_CLIENT structure
typedef struct tagRemoteClient{
int iIndex;
DWORD port;
HANDLE hClient;
char szip[32];
}REMOTE_CLIENT;
User Manual
Date: 2012/12/19
V1.02
34
CAN-bus Series
pData
Description
Length: 1 byte
Modify the CAN baud rate, for example, set the CAN
10Kbps
20Kbps
BYTE baud=0;
50Kbps
VCI_SetReference(VCI_CAN232,0,0,1,(PVOID)&baud)
125Kbps
250Kbps
500Kbps
800Kbps
1000Kbps
Length: 1 byte
1
2.4Kbps
4.8Kbps
9.6Kbps
14.4Kbps
19.2Kbps
28.8Kbps
57.6Kbps
Length: 2 bytes
pData[0]
is
the
control
is
the
control
Length: 1 byte,
Set timestamp
do
not
use
timestamp
When RefType=2, the meanings of each byte in the returned pData are as following:
pData[0] is used to set the which group of acceptant filter to be used, there are 4 group
of filters:
=1: Set the 1st group
=2: Set the 2nd group
=3: Set the 3rd group
=4: Set the 4th group
pData[1] is used to set the operation mode of the acceptant filter; its bit interpretation is
listed as below:
User Manual
Date: 2012/12/19
V1.02
35
CAN-bus Series
STATUS.6
STATUS.5
STATUS.4
STATUS.3
STATUS.2
MFORMATB
STATUS.1
STATUS.0
MFORMATB
AMODEB
=1; acceptance filter is only available for extend frame information; the
standard frame information will be ignored.
=0; acceptance filter is only available for standard frame information;
the extend frame information will be ignored.
AMODEB
pData[2] is for reading the state of acceptance filter (enabled or not); its bit interpretation
is listed as below:
STATUS.7
STATUS.6
STATUS.5
STATUS.4
STATUS.3
STATUS.2
BF2EN
STATUS.1
STATUS.0
BF2EN
BF1EN
=1; filter 2 is enabled, and writing shield and code registers are not allowed;
=0; filter 2 is disabled, and shield and code registers can be written.
BF1EN
=1; filter 1 is enabled, and writing shield and code registers are not allowed;
=0; filter 1 is disabled, and shield and code registers can be written.
Notes: For single filter mode, the single filter is related to the filter 1 enable bit. And filter 2 enable bit
is ineffective under this mode.
pData[3] is for reading the priory level of acceptance filter (enabled or not); its bit
interpretation is listed as below:
STATUS.7
STATUS.6
STATUS.5
STATUS.4
STATUS.3
STATUS.2
STATUS.1
STATUS.0
BF2PRIO
BF1PRIO
BF2PRIO =1; Filter 2 has higher priory level. If there is message come into filer 2,
receive interrupt will be generated immediately;
=0; Filter 2 has lower priory level. When FIFO level has passed the receive
interrupt level, receive interrupt will be generated;
BF1PRIO =1; Filter 1 has higher priory level. If there is message come into filer 2,
receive interrupt will be generated immediately;
=0; Filter 1 has lower priory level. When FIFO level has passed the receive
interrupt level, receive interrupt will be generated.
pData[4---7] are corresponding to ACR0---ACR3 of SJA1000 to be set;
pData[8---b] are corresponding to AMR0---AMR3 of SJA1000 to be set.
(7) For PCI-5010-U/PCI-5020-U/USBCAN-E-U/ USBCAN-2E-U:
RefType
0
pData
Description
following:
BPS=
register BTR
/(BRP+1)*(TESG1+TESG2+3)
User Manual
Date: 2012/12/19
Peripheral
bus
clock
V1.02
36
CAN-bus Series
pData
Description
Where:
setting:
BRP:
0~9bit of BTR
0x060003
1000Kbps
TESG1:
16~19bit of BTR
0x060004
800Kbps
TESG2:
20~22bit of BTR
0x060007
500Kbps
0x1C0008
250Kbps
0x1C0011
125Kbps
0x160023
100Kbps
0x1C002C
50Kbps
0x1600B3
20Kbps
0x1C00E0
10Kbps
0x1C01C1
5Kbps
80% <=
TESG1 + 2
TESG1 + TESG 2 + 3
<= 90%
USBCAN-E-U/
USBCAN-2E-U,
it
is
Pointer to VCI_FILTER_RECORD
structure
NULL
2.4.8.4 Example
#include "ControlCan.h"
int nDeviceType = 6;
// CAN232
int nDeviceInd = 0;
// COM1
int nCANInd = 0;
BYTE baud;
DWORD dwRel;
baud = 0;
bRel = VCI_SetReference(nDeviceType, nDeviceInd, nCANInd, 1, (PVOID)baud);
User Manual
Date: 2012/12/19
V1.02
37
CAN-bus Series
2.4.9 VCI_GetReceiveNum
2.4.9.1 Description
This function is used to obtain the quantity of frames that has been received but not
read out.
ULONG __stdcall VCI_GetReceiveNum(DWORD DevType, DWORD DevIndex, DWORD CANIndex);
DevType
This is the type of device.
DevIndex
This is the index number of device. For example, when there is only one PCI5121, the
index number is 0. For two devices, the index number can be 0 or 1. (Notice: For
CAN232, 0 is for opening COM1, and 1 is for opening COM2.)
CANIndex
This is the index number of CAN channel.
Return value
Return the frame number that is not read.
2.4.9.2 Example
#include "ControlCan.h"
int nDeviceType = 6;
// CAN232
int nDeviceInd = 0;
// COM1
int nCANInd = 0;
DWORD dwRel;
2.4.10 VCI_ClearBuffer
2.4.10.1 Description
This function is used to clear the specific buffer.
DWORD __stdcall VCI_ClearBuffer(DWORD DevType, DWORD DevIndex, DWORD CANIndex);
DevType
This is the type of device.
DevIndex
This is the index number of device. For example, when there is only one PCI5121, the
index number is 0. For two devices, the index number can be 0 or 1. (Notice: For
CAN232, 0 is for opening COM1, and 1 is for opening COM2.)
User Manual
Date: 2012/12/19
V1.02
38
CAN-bus Series
CANIndex
This is the index number of CAN channel.
Return value
When return 1, operation is successful; when return 0, operation is failure.
2.4.10.2 Example
#include "ControlCan.h"
int nDeviceType = 6;
// CAN232
int nDeviceInd = 0;
// COM1
int nCANInd = 0;
DWORD dwRel;
2.4.11 VCI_StartCAN
2.4.11.1 Description
This function is used to start CAN.
DWORD __stdcall VCI_StartCAN(DWORD DevType, DWORD DevIndex, DWORD CANIndex);
DevType
This is the type of device.
DevIndex
This is the index number of device. For example, when there is only one PCI5121, the
index number is 0. For two devices, the index number can be 0 or 1. (Notice: For
CAN232, 0 is for opening COM1, and 1 is for opening COM2.)
CANIndex
This is the index number of CAN channel.
Return value
When return 1, operation is successful; when return 0, operation is failure.
2.4.11.2 Example
#include "ControlCan.h"
int nDeviceType = 6;
// CAN232
int nDeviceInd = 0;
// COM1
int nCANInd = 0;
int nReserved = 9600;
// Baudrate
User Manual
Date: 2012/12/19
V1.02
39
CAN-bus Series
2.4.12 VCI_ResetCAN
2.4.12.1 Description
This function is used to reset CAN.
DWORD __stdcall VCI_ResetCAN(DWORD DevType, DWORD DevIndex, DWORD CANIndex);
DevType
This is the type of device.
DevIndex
This is the index number of device. For example, when there is only one PCI5121, the
index number is 0. For two devices, the index number can be 0 or 1. (Notice: For
CAN232, 0 is for opening COM1, and 1 is for opening COM2.)
CANIndex
This is the index number of CAN channel.
Return value
When return 1, operation is successful; when return 0, operation is failure.
(Notes: For CANET-TCP, in the case of network disconnection, user should recall
VCI_StartCAN function to use CANET-TCP connect to the network.)
User Manual
Date: 2012/12/19
V1.02
40
CAN-bus Series
2.4.12.2 Example
#include "ControlCan.h"
int nDeviceType = 6;
// CAN232
int nDeviceInd = 0;
// COM1
int nCANInd = 0;
DWORD dwRel;
2.4.13 VCI_Transmit
2.4.13.1 Description
Return the actual transmitted frame number.
ULONG
__stdcall
VCI_Transmit(DWORD
DevType,
DWORD
DevIndex,
DWORD
CANIndex,
2.4.13.2 Parameters
DevType
This is the type of device.
DevIndex
This is the index number of device. For example, when there is only one PCI5121, the
index number is 0. For two devices, the index number can be 0 or 1. (Notice: For
CAN232, 0 is for opening COM1, and 1 is for opening COM2.)
CANIndex
This is the index number of CAN channel.
pSend
This is the head pointer to the data frame array to be sent.
Len
This is the length of the data frame array to be sent.
Return value
Return the actual transmitted frame number.
2.4.13.3 Example
#include "ControlCan.h"
#include <string.h>
User Manual
Date: 2012/12/19
V1.02
41
CAN-bus Series
// CAN232
int nDeviceInd = 0;
// COM1
int nCANInd = 0;
DWORD dwRel;
VCI_CAN_OBJ vco;
2.4.14 VCI_Receive
2.4.14.1 Description
This function is used to read data from the specific device.
ULONG __stdcall VCI_Receive(DWORD DevType, DWORD DevIndex, DWORD CANIndex, PVCI_CAN_OBJ
pReceive, ULONG Len, INT WaitTime=1);
DevType
This is the type of device.
DevIndex
This is the index number of device. For example, when there is only one PCI5121, the
index number is 0. For two devices, the index number can be 0 or 1. (Notice: For
CAN232, 0 is for opening COM1, and 1 is for opening COM2.)
CANIndex
This is the index number of CAN channel.
pReceive
This is used to receive the head pointer of the data frame array.
Len
This is the length of the data frame array to be received.
WaitTime
This is the wait overtime (unit: ms);
Return value
Return the frame number read actually. If the return value is 0xFFFFFFFF, it means
reading data fails and error occurs. In this case, you should call VCI_ReadErrInfo
function to obtain the error code.
2.4.14.2 Example
User Manual
Date: 2012/12/19
V1.02
42
CAN-bus Series
int nDeviceType = 6;
// CAN232
int nDeviceInd = 0;
// COM1
int nCANInd = 0;
DWORD dwRel;
VCI_CAN_OBJ vco[100];
V1.02
43
CAN-bus Series
It means the called function has another name in the dynamic link library (DLL). When
the external function name is the same with certain function name, this parameter can
be used. When the function in the dynamic link library has the same name with the
name of public variable, constant or any procedure, you can use Alias too. If a character
in this DLL function has confliction with the naming convention of the dynamic link
library, Alias will be used.
Aliasname (optional)
It is dynamic link library. If the first character is not #, then aliasname will be the name
of the entry point in this function. If the first character is a #, the subsequent character
should specific the sequence number of the function entry.
Arglist (optional)
It is the variable table for passing parameter when calling this function.
Type (optional)
It is the data type of the Function return value. It can be Byte, Boolean, Integer, Long,
Currency, Single, Double, Decimal (not supported in current), Date, String (only support
varchar) or Variant, user defined type or object type.
The syntax of the parameter arglist is as following:
[Optional] [ByVal | ByRef] [ParamArray] varname[( )] [As type]
Partial description:
Optional (optional)
It means the parameter is not necessary. When using this option, the subsequent
parameters in arglist are optional too, and all of them should use the key work Optional
for declaration. However, if ParamArray is used, no parameter can be Optional.
ByVal (optional)
It means the parameter is passed by value.
ByRef (optional)
It means the parameter is passed by address.
For example:
Public Declare Function VCI_OpenDevice Lib "ControlCAN" (ByVal devicetype As Long,
ByVal deviceind As Long, ByVal reserved As Long) As Long
User Manual
Date: 2012/12/19
V1.02
44
CAN-bus Series
VCI_InitCan
VCI_ReadBoardInf
VCI_ReadErrInfo
VCI_ReadCanStatu
VCI_GetReceiveN
VCI_ClearBuffer
VCI_GetReference
VCI_SetReference
VCI_StartCAN
VCI_ResetCAN
VCI_Transmit
VCI_Receive
VCI_CloseDevice
User Manual
Date: 2012/12/19
V1.02
45
CAN-bus Series
User Manual
Date: 2012/12/19
V1.02
46
CAN-bus Series
User Manual
Date: 2012/12/19
V1.02
47