Files
hcanview/include/usb/WinUsbDevice.h
yemai 81bee50cd9 Initial commit: Complete USB2CAN cross-platform framework
Features:
- Cross-platform support (Windows/Linux/macOS)
- CAN and CANFD protocol support
- USB communication (WinUSB/libusb)
- Device management and configuration
- Message transmission and reception
- Filter configuration
- CMake build system
- Comprehensive examples and tests
2025-09-11 17:56:26 +08:00

81 lines
2.1 KiB
C++
Raw 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.
/**
* @file WinUsbDevice.h
* @brief Windows平台USB设备实现
*/
#ifndef USB2CAN_WIN_USB_DEVICE_H
#define USB2CAN_WIN_USB_DEVICE_H
#include "UsbDevice.h"
#ifdef _WIN32
#include <windows.h>
#include <setupapi.h>
#include <winusb.h>
#endif
namespace usb2can {
namespace usb {
/**
* @brief Windows平台USB设备实现类
*/
class WinUsbDevice : public UsbDevice {
public:
WinUsbDevice(platform::Platform* platform);
~WinUsbDevice() override;
bool open(const std::string& devicePath) override;
void close() override;
bool isOpen() const override;
int write(const uint8_t* data, size_t size, int timeout = 1000) override;
int read(uint8_t* data, size_t size, int timeout = 1000) override;
bool getDeviceInfo(UsbDeviceInfo& info) override;
std::string getDevicePath() const override;
private:
platform::Platform* platform_; ///< 平台实例
void* deviceHandle_; ///< 设备句柄
std::string devicePath_; ///< 设备路径
bool isOpen_; ///< 设备是否已打开
UsbDeviceInfo deviceInfo_; ///< 设备信息
/**
* @brief 获取WinUSB设备句柄
* @return WinUSB设备句柄
*/
WINUSB_INTERFACE_HANDLE getWinUsbHandle() const;
/**
* @brief 获取Windows设备句柄
* @return Windows设备句柄
*/
HANDLE getWindowsHandle() const;
/**
* @brief 获取USB管道信息
* @param pipeId 管道ID
* @param pipeInfo 管道信息
* @return 操作成功返回true否则返回false
*/
bool getPipeInfo(UCHAR pipeId, WINUSB_PIPE_INFORMATION& pipeInfo);
/**
* @brief 获取USB设备描述符
* @param descriptor 设备描述符
* @return 操作成功返回true否则返回false
*/
bool getDeviceDescriptor(USB_DEVICE_DESCRIPTOR& descriptor);
/**
* @brief 获取USB字符串描述符
* @param descIndex 描述符索引
* @return 字符串描述符内容
*/
std::string getStringDescriptor(uint8_t descIndex);
};
} // namespace usb
} // namespace usb2can
#endif // USB2CAN_WIN_USB_DEVICE_H