HONGRI_uds_tools/CAN_Tool/CanDevice/TOOMOSS/usb_device.cs

124 lines
5.3 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace USB2XXX
{
class USB_DEVICE
{
//定义电压输出值
public const Byte POWER_LEVEL_NONE = 0; //不输出
public const Byte POWER_LEVEL_1V8 = 1; //输出1.8V
public const Byte POWER_LEVEL_2V5 = 2; //输出2.5V
public const Byte POWER_LEVEL_3V3 = 3; //输出3.3V
public const Byte POWER_LEVEL_5V0 = 4; //输出5.0V
//设备信息定义
public struct DEVICE_INFO
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public Byte[] FirmwareName; //固件名称字符串
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public Byte[] BuildDate; //固件编译时间字符串
public UInt32 HardwareVersion;//硬件版本号
public UInt32 FirmwareVersion;//固件版本号
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public UInt32[] SerialNumber; //适配器序列号
public UInt32 Functions; //适配器当前具备的功能
}
//方法定义
/**
* @brief USB设备
* @param pDevHandle
* @retval
*/
[DllImport("USB2XXX.dll")]
public static extern Int32 USB_ScanDevice(Int32[] pDevHandle);
/**
* @brief
* @param DevHandle
* @retval
*/
[DllImport("USB2XXX.dll")]
public static extern bool USB_OpenDevice(Int32 DevHandle);
/**
* @brief
* @param DevHandle
* @retval
*/
[DllImport("USB2XXX.dll")]
public static extern bool USB_CloseDevice(Int32 DevHandle);
/**
* @brief USB_ScanDeviceUSB_OpenDevice函数
* @param DevHandle
* @retval
*/
[DllImport("USB2XXX.dll")]
public static extern bool USB_ResetDevice(Int32 DevHandle);
/**
* @brief
* @param DevHandle
* @param pDevInfo
* @param pFunctionStr
* @retval
*/
[DllImport("USB2XXX.dll")]
public static extern bool DEV_GetDeviceInfo(Int32 DevHandle, ref DEVICE_INFO pDevInfo, StringBuilder pFunctionStr);
/**
* @brief
* @param DevHandle
* @retval
*/
[DllImport("USB2XXX.dll")]
public static extern bool DEV_EraseUserData(Int32 DevHandle);
/**
* @brief
* @param DevHandle
* @param OffsetAddr 0x000x1000064KBye
* @param pWriteData
* @param DataLen
* @retval
*/
[DllImport("USB2XXX.dll")]
public static extern bool DEV_WriteUserData(Int32 DevHandle,Int32 OffsetAddr,byte[] pWriteData,Int32 DataLen);
/**
* @brief
* @param DevHandle
* @param OffsetAddr 0x000x1000064KBye
* @param pReadData
* @param DataLen
* @retval
*/
[DllImport("USB2XXX.dll")]
public static extern bool DEV_ReadUserData(Int32 DevHandle,Int32 OffsetAddr,byte[] pReadData,Int32 DataLen);
/**
* @brief
* @param DevHandle
* @param PowerLevel
* @retval
*/
[DllImport("USB2XXX.dll")]
public static extern bool DEV_SetPowerLevel(Int32 DevHandle,byte PowerLevel);
/**
* @brief CAN或者LIN的时间戳原始值
* @param DevHandle
* @param pTimestamp
* @retval
*/
[DllImport("USB2XXX.dll")]
public static extern bool DEV_GetTimestamp(Int32 DevHandle,byte BusType,Int32[] pTimestamp);
/**
* @brief CAN/LIN时间戳CAN/LIN之后调用
* @param DevHandle
* @retval
*/
[DllImport("USB2XXX.dll")]
public static extern bool DEV_ResetTimestamp(Int32 DevHandle);
}
}