Files
agv-control-slam/lib/ControlCAN.h
CaiXiang af65c2425d initial
2025-11-14 16:09:58 +08:00

118 lines
3.8 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef CONTROLCAN_H
#define CONTROLCAN_H
#ifdef __cplusplus
extern "C" {
#endif
// Windows 类型定义
#ifndef _WINDEF_
typedef unsigned char BYTE;
typedef unsigned short USHORT;
typedef unsigned int UINT;
typedef unsigned long DWORD;
typedef void* PVOID;
typedef char CHAR;
typedef int INT;
typedef unsigned long ULONG;
#endif
// 设备类型定义
#define VCI_USBCAN2 4 // USBCAN-2A/2C/CANalyst-II 系列
// 设备信息结构体
typedef struct _VCI_BOARD_INFO {
USHORT hw_Version; // 硬件版本
USHORT fw_Version; // 固件版本
USHORT dr_Version; // 驱动版本
USHORT in_Version; // 接口库版本
USHORT irq_Num; // 保留
BYTE can_Num; // CAN 通道数量
CHAR str_Serial_Num[20]; // 序列号
CHAR str_hw_Type[40]; // 硬件类型
USHORT Reserved[4];
} VCI_BOARD_INFO, *PVCI_BOARD_INFO;
// CAN 帧结构体
typedef struct _VCI_CAN_OBJ {
UINT ID; // CAN ID
UINT TimeStamp; // 时间戳
BYTE TimeFlag; // 时间标志
BYTE SendType; // 发送类型0=正常1=单次
BYTE RemoteFlag; // 远程帧标志0=数据帧1=远程帧
BYTE ExternFlag; // 帧格式0=标准帧1=扩展帧
BYTE DataLen; // 数据长度
BYTE Data[8]; // 数据
BYTE Reserved[3];
} VCI_CAN_OBJ, *PVCI_CAN_OBJ;
// 初始化配置结构体
typedef struct _VCI_INIT_CONFIG {
DWORD AccCode; // 验收码
DWORD AccMask; // 屏蔽码
DWORD Reserved;
BYTE Filter; // 滤波方式
BYTE Timing0; // 波特率定时器0
BYTE Timing1; // 波特率定时器1
BYTE Mode; // 工作模式
} VCI_INIT_CONFIG, *PVCI_INIT_CONFIG;
// 滤波范围结构体
typedef struct _VCI_FILTER_RECORD {
DWORD ExtFrame; // 帧类型0=标准1=扩展
DWORD Start; // 起始 ID
DWORD End; // 结束 ID
} VCI_FILTER_RECORD, *PVCI_FILTER_RECORD;
// 函数声明
#ifdef _MSC_VER
#define EXPORT_API __declspec(dllimport)
#else
#define EXPORT_API
#endif
// 打开设备
EXPORT_API DWORD __stdcall VCI_OpenDevice(DWORD DeviceType, DWORD DeviceInd, DWORD Reserved);
// 关闭设备
EXPORT_API DWORD __stdcall VCI_CloseDevice(DWORD DeviceType, DWORD DeviceInd);
// 初始化 CAN
EXPORT_API DWORD __stdcall VCI_InitCAN(DWORD DeviceType, DWORD DeviceInd, DWORD CANInd, PVCI_INIT_CONFIG pInitConfig);
// 启动 CAN
EXPORT_API DWORD __stdcall VCI_StartCAN(DWORD DeviceType, DWORD DeviceInd, DWORD CANInd);
// 复位 CAN
EXPORT_API DWORD __stdcall VCI_ResetCAN(DWORD DeviceType, DWORD DeviceInd, DWORD CANInd);
// 发送数据
EXPORT_API DWORD __stdcall VCI_Transmit(DWORD DeviceType, DWORD DeviceInd, DWORD CANInd, PVCI_CAN_OBJ pSend, DWORD Len);
// 接收数据
EXPORT_API DWORD __stdcall VCI_Receive(DWORD DeviceType, DWORD DeviceInd, DWORD CANInd, PVCI_CAN_OBJ pReceive, DWORD Len, INT WaitTime);
// 获取接收数量
EXPORT_API DWORD __stdcall VCI_GetReceiveNum(DWORD DeviceType, DWORD DeviceInd, DWORD CANInd);
// 清除缓冲区
EXPORT_API DWORD __stdcall VCI_ClearBuffer(DWORD DeviceType, DWORD DeviceInd, DWORD CANInd);
// 读取设备信息
EXPORT_API DWORD __stdcall VCI_ReadBoardInfo(DWORD DeviceType, DWORD DeviceInd, PVCI_BOARD_INFO pInfo);
// 查找 USB 设备
EXPORT_API DWORD __stdcall VCI_FindUsbDevice2(PVCI_BOARD_INFO pInfo);
// 复位 USB 设备
EXPORT_API DWORD __stdcall VCI_UsbDeviceReset(DWORD DeviceType, DWORD DeviceInd, DWORD Reserved);
// 设置参数
EXPORT_API DWORD __stdcall VCI_SetReference(DWORD DeviceType, DWORD DeviceInd, DWORD CANInd, DWORD RefType, PVOID pData);
#ifdef __cplusplus
}
#endif
#endif // CONTROLCAN_H