#ifndef _ZLG_H #define _ZLG_H #include "CAN.h" //定义CAN信息帧的数据类型。 typedef struct _VCI_CAN_OBJ_ZLG{ UINT ID; UINT TimeStamp; BYTE TimeFlag; BYTE SendType; BYTE RemoteFlag;//是否是远程帧 BYTE ExternFlag;//是否是扩展帧 BYTE DataLen; BYTE Data[8]; BYTE Reserved[3]; }VCI_CAN_OBJ_ZLG,*PVCI_CAN_OBJ_ZLG; //定义初始化CAN的数据类型 typedef struct _VCI_INIT_CONFIG_ZLG{ DWORD AccCode; DWORD AccMask; DWORD Reserved; UCHAR Filter; UCHAR Timing0; UCHAR Timing1; UCHAR Mode; }VCI_INIT_CONFIG_ZLG,*PVCI_INIT_CONFIG_ZLG; //定义接口卡信息的数据类型 typedef struct _VCI_BOARD_INFO_ZLG{ USHORT hw_Version; USHORT fw_Version; USHORT dr_Version; USHORT in_Version; USHORT irq_Num; BYTE can_Num; CHAR str_Serial_Num[20]; CHAR str_hw_Type[40]; USHORT Reserved[4]; } VCI_BOARD_INFO_ZLG,*PVCI_BOARD_INFO_ZLG; class CZLGWrapper : public CDLLModule { public: DECLARE_DLL_FUNCTION_3(DWORD, WINAPI, VCI_OpenDevice, (DWORD DeviceType,DWORD DeviceInd,DWORD Reserved)) DECLARE_DLL_FUNCTION_3(DWORD, WINAPI, VCI_CloseDevice, (DWORD DeviceType,DWORD DeviceInd)) DECLARE_DLL_FUNCTION_3(DWORD, WINAPI, VCI_InitCAN, (DWORD DeviceType, DWORD DeviceInd, DWORD CANInd, PVCI_INIT_CONFIG_ZLG pInitConfig)) DECLARE_DLL_FUNCTION_3(DWORD, WINAPI, VCI_StartCAN, (DWORD DeviceType,DWORD DeviceInd,DWORD CANInd)) DECLARE_DLL_FUNCTION_3(DWORD, WINAPI, VCI_ResetCAN, (DWORD DeviceType,DWORD DeviceInd,DWORD CANInd)) DECLARE_DLL_FUNCTION_3(DWORD, WINAPI, VCI_ReadErrInfo, (DWORD DeviceType,DWORD DeviceInd,DWORD CANInd,PVCI_ERR_INFO pErrInfo)) DECLARE_DLL_FUNCTION_3(DWORD, WINAPI, VCI_ReadCANStatus, (DWORD DeviceType,DWORD DeviceInd,DWORD CANInd,PVCI_CAN_STATUS pCANStatus)) DECLARE_DLL_FUNCTION_3(DWORD, WINAPI, VCI_ReadBoardInfo, (DWORD DeviceType,DWORD DeviceInd,PVCI_BOARD_INFO_ZLG pInfo)) DECLARE_DLL_FUNCTION_3(DWORD, WINAPI, VCI_GetReference, (DWORD DeviceType,DWORD DeviceInd,DWORD CANInd,DWORD RefType,PVOID pData)) DECLARE_DLL_FUNCTION_3(DWORD, WINAPI, VCI_SetReference, (DWORD DeviceType,DWORD DeviceInd,DWORD CANInd,DWORD RefType,PVOID pData)) DECLARE_DLL_FUNCTION_3(DWORD, WINAPI, VCI_GetReceiveNum, (DWORD DeviceType,DWORD DeviceInd,DWORD CANInd)) DECLARE_DLL_FUNCTION_3(DWORD, WINAPI, VCI_ClearBuffer, (DWORD DeviceType,DWORD DeviceInd,DWORD CANInd)) DECLARE_DLL_FUNCTION_3(DWORD, WINAPI, VCI_Transmit, (DWORD DeviceType,DWORD DeviceInd,DWORD CANInd,PVCI_CAN_OBJ_ZLG pSend,ULONG Len)) DECLARE_DLL_FUNCTION_3(DWORD, WINAPI, VCI_Receive, (DWORD DeviceType,DWORD DeviceInd,DWORD CANInd,PVCI_CAN_OBJ_ZLG pReceive,ULONG Len,INT WaitTime)) BEGIN_DLL_INIT() INIT_DLL_FUNCTION_3(VCI_OpenDevice) INIT_DLL_FUNCTION_3(VCI_CloseDevice) INIT_DLL_FUNCTION_3(VCI_InitCAN) INIT_DLL_FUNCTION_3(VCI_StartCAN) INIT_DLL_FUNCTION_3(VCI_ResetCAN) INIT_DLL_FUNCTION_3(VCI_ReadErrInfo) INIT_DLL_FUNCTION_3(VCI_ReadCANStatus) INIT_DLL_FUNCTION_3(VCI_ReadBoardInfo) INIT_DLL_FUNCTION_3(VCI_GetReference) INIT_DLL_FUNCTION_3(VCI_SetReference) INIT_DLL_FUNCTION_3(VCI_GetReceiveNum) INIT_DLL_FUNCTION_3(VCI_ClearBuffer) INIT_DLL_FUNCTION_3(VCI_Transmit) INIT_DLL_FUNCTION_3(VCI_Receive) END_DLL_INIT() bool Init(LPCTSTR szPath, UINT nCnt, ...){return false;}// 具体化 }; class CZLG : public CCAN { public: CZLG(); virtual ~CZLG(); BOOL OpenDevice(DWORD devInd); void CloseDevice(DWORD devInd); BOOL InitCAN(DWORD devInd, DWORD CANInd, PVCI_INIT_CONFIG pInitConfig); BOOL StartCAN(DWORD devInd, DWORD CANInd); BOOL ResetCAN(DWORD devInd, DWORD CANInd); void ReadErrInfo(DWORD devInd, DWORD CANInd, PVCI_ERR_INFO pErrInfo); BOOL ReadCANStatus(DWORD devInd, DWORD CANInd, PVCI_CAN_STATUS pCANStatus); BOOL ReadBoardInfo(DWORD devInd, DWORD CANInd, PVCI_BOARD_INFO_ZLG pInfo); BOOL GetReference(DWORD devInd, DWORD CANInd, DWORD RefType, PVOID pData); BOOL SetReference(DWORD devInd, DWORD CANInd, DWORD RefType, PVOID pData); BOOL ClearBuffer(DWORD devInd, DWORD CANInd); ULONG GetReceiveNum(DWORD devInd, DWORD CANInd); ULONG Transmit(DWORD devInd, DWORD CANInd, PVCI_CAN_OBJ pSend,ULONG Len); ULONG Receive(DWORD devInd, DWORD CANInd, PVCI_CAN_OBJ pReceive, ULONG Len, INT WaitTime=-1); BOOL LoadDLL(); protected: VCI_INIT_CONFIG_ZLG init_config; DWORD m_dwDevType; // 设备类型 DWORD m_dwDevInd; // 设备索引 DWORD m_dwCANInd; // CAN通道索引 CZLGWrapper m_wrapper; }; #endif