You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
275 lines
6.8 KiB
275 lines
6.8 KiB
unit ControlCAN;
|
|
|
|
interface
|
|
|
|
uses
|
|
WinTypes;
|
|
|
|
const
|
|
DLL_NAME = 'ControlCAN.dll';//Dynamic library name
|
|
|
|
type
|
|
|
|
//--------------------------------------ZLG compatible functions and data types -----------------
|
|
//Declare each data structure
|
|
|
|
//USB-CAN bus adapter card data type information.
|
|
VCI_BOARD_INFO = Record
|
|
hw_Version : WORD;
|
|
fw_Version : WORD;
|
|
dr_Version : WORD;
|
|
in_Version : WORD;
|
|
irq_Num : WORD;
|
|
can_Num : BYTE;
|
|
str_Serial_Num : array[0..19] of CHAR;
|
|
str_hw_Type : array[0..39] of CHAR;
|
|
Reserved : array[0..3] of WORD;
|
|
END;
|
|
|
|
PVCI_BOARD_INFO=^VCI_BOARD_INFO;
|
|
|
|
//Defined data types CAN message frame.
|
|
VCI_CAN_OBJ = Record
|
|
ID : UINT;
|
|
TimeStamp : UINT;
|
|
TimeFlag : BYTE;
|
|
SendType : BYTE;
|
|
RemoteFlag : BYTE;
|
|
ExternFlag : BYTE;
|
|
DataLen : BYTE;
|
|
Data : array[0..7] of BYTE;
|
|
Reserved : array[0..2] of BYTE;
|
|
END;
|
|
|
|
PVCI_CAN_OBJ = ^VCI_CAN_OBJ;
|
|
|
|
//Defined data types CAN controller states.
|
|
VCI_CAN_STATUS = Record
|
|
ErrInterrupt : UCHAR;
|
|
regMode : UCHAR;
|
|
regStatus : UCHAR;
|
|
regALCapture : UCHAR;
|
|
regECCapture : UCHAR;
|
|
regEWLimit : UCHAR;
|
|
regRECounter : UCHAR;
|
|
regTECounter : UCHAR;
|
|
Reserved : DWORD;
|
|
END;
|
|
|
|
PVCI_CAN_STATUS = ^VCI_CAN_STATUS;
|
|
|
|
//Definition of wrong data type information.
|
|
VCI_ERR_INFO = Record
|
|
ErrCode : UINT;
|
|
Passive_ErrData : array[0..2] of BYTE;
|
|
ArLost_ErrData : BYTE;
|
|
END;
|
|
|
|
PVCI_ERR_INFO = ^VCI_ERR_INFO;
|
|
|
|
//CAN initialization data type definition
|
|
VCI_INIT_CONFIG = Record
|
|
AccCode : DWORD;
|
|
AccMask : DWORD;
|
|
Reserved : DWORD;
|
|
Filter : UCHAR;
|
|
Timing0 : UCHAR;
|
|
Timing1 : UCHAR;
|
|
Mode : UCHAR;
|
|
END;
|
|
|
|
PVCI_INIT_CONFIG = ^VCI_INIT_CONFIG;
|
|
|
|
//Importing DLL function
|
|
function VCI_OpenDevice ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
Reserved : DWORD) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_CloseDevice ( DevType : DWORD;
|
|
DevIndex : DWORD) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_InitCAN ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
CANIndex : DWORD;
|
|
pInitConfig : PVCI_INIT_CONFIG) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_ReadBoardInfo ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
pInfo : PVCI_BOARD_INFO) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_ReadErrInfo ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
CANIndex : DWORD;
|
|
pErrInfo : PVCI_ERR_INFO) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_ReadCANStatus ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
CANIndex : DWORD;
|
|
pCANStatus : PVCI_CAN_STATUS) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_GetReference ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
CANIndex : DWORD;
|
|
RefType : DWORD;
|
|
pData : Pointer) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_SetReference ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
CANIndex : DWORD;
|
|
RefType : DWORD;
|
|
pData : Pointer) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_GetReceiveNum ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
CANIndex : DWORD) : ULONG;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_ClearBuffer ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
CANIndex : DWORD) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_StartCAN ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
CANIndex : DWORD) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_ResetCAN ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
CANIndex : DWORD) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_Transmit ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
CANIndex : DWORD;
|
|
pSend : PVCI_CAN_OBJ;
|
|
Len : ULONG) : ULONG;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_Receive ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
CANIndex : DWORD;
|
|
pReceive : PVCI_CAN_OBJ;
|
|
Len : ULONG;
|
|
WaitTime : integer) : ULONG;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
//------------------------其他函数及数据结构描述--------------------------------
|
|
type
|
|
//Data type USB-CAN bus adapter card information, a, of the type referred to in VCI_FindUsbDevice function
|
|
VCI_BOARD_INFO1 = Record
|
|
hw_Version : WORD;
|
|
fw_Version : WORD;
|
|
dr_Version : WORD;
|
|
in_Version : WORD;
|
|
irq_Num : WORD;
|
|
can_Num : BYTE;
|
|
reserved : BYTE;
|
|
str_Serial_Num : array[0..7] of CHAR;
|
|
str_hw_Type : array[0..15] of CHAR;
|
|
str_USB_Serial : array[0..3,0..3] of CHAR;
|
|
END;
|
|
|
|
PVCI_BOARD_INFO1=^VCI_BOARD_INFO1;
|
|
|
|
//Define the general parameters of type
|
|
VCI_REF_NORMAL = Record
|
|
Mode : UCHAR;
|
|
Filter : UCHAR;
|
|
AccCode : DWORD;
|
|
AccMask : DWORD;
|
|
kBaudRate : UCHAR;
|
|
Timing0 : UCHAR;
|
|
Timing1 : UCHAR;
|
|
CANRX_EN : UCHAR;
|
|
UARTBAUD : UCHAR;
|
|
END;
|
|
|
|
PVCI_REF_NORMAL = ^VCI_REF_NORMAL;
|
|
|
|
// Define the baud rate setting parameter types)
|
|
VCI_BAUD_TYPE = Record
|
|
Baud : DWORD;
|
|
SJW : UCHAR;
|
|
BRP : UCHAR;
|
|
SAM : UCHAR;
|
|
PHSEG2_SEL : UCHAR;
|
|
PRSEG : UCHAR;
|
|
PHSEG1 : UCHAR;
|
|
PHSEG2 : UCHAR;
|
|
END;
|
|
|
|
PVCI_BAUD_TYPE = ^VCI_BAUD_TYPE;
|
|
|
|
//Reference parameter type definition
|
|
VCI_REF_STRUCT = Record
|
|
RefNormal : VCI_REF_NORMAL;
|
|
Reserved : UCHAR;
|
|
BaudType : VCI_BAUD_TYPE;
|
|
END;
|
|
|
|
PVCI_REF_STRUCT = ^VCI_REF_STRUCT;
|
|
|
|
//Importing DLL function
|
|
function VCI_GetReference2 ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
CANIndex : DWORD;
|
|
Reserved : DWORD;
|
|
pRefStruct : PVCI_REF_STRUCT) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_SetReference2 ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
CANIndex : DWORD;
|
|
RefType : DWORD;
|
|
pRefStruct : Pointer) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_ResumeConfig ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
CANIndex : DWORD) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_ConnectDevice ( DevType : DWORD;
|
|
DevIndex : DWORD) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_UsbDeviceReset ( DevType : DWORD;
|
|
DevIndex : DWORD;
|
|
Reserved : DWORD) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
function VCI_FindUsbDevice ( pInfo : PVCI_BOARD_INFO1) : DWORD;
|
|
stdcall;
|
|
external DLL_NAME;
|
|
|
|
implementation
|
|
|
|
end.
|