哪里是LibUsbphp com dotnet.dlll

14:05 提问
C# 使用LibusbDotNet实现usb热插拔遇到的异常
我想实现USB连接后,数据通信过程中插拔USB,软件自动识别USB后,能够自动连接并继续发送数据,软件不死机。
但是,往往插拔几次后会出现“ Safe handle has been closed Exception”异常
下面是识别USB的代码
我试了下,先关闭USB设备后关闭发送线程标志位,和先关闭发送线程标志位后关闭USB设备都会出现这种问题,
下面是打印的调试信息,通过调试信息发现,在识别到USB断开之前,发送线程依然会执行write函数发送数据,结果打印出发送0字节错误
Win32Error,不知道是不是由于发送错误后引发异常?
线?程¨? '&无T名?称?&' (0x156c) 已°?退??出?,ê?返¤??回?值??为a 0 (0x0)。?ê
now time is 11.6512
now time is 1.1498
now time is 0.4251
Win32Error
now time is 501.0047
Win32Error
now time is 499.6215
close thread
public void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
if (e.EventType == EventType.DeviceArrival)
if (null == e.Device)
if (e.Device.IdProduct == myProductID && e.Device.IdVendor == myVendorID)
Console.WriteLine("连??接¨(R)");
FindTheHid(m_wnd);
if (myDeviceDetected == true)
OpenTheHid(m_wnd);
onDataSend();
//数?y据Y发¤?é送¨?线?程¨?
//onReceive();
//开a启?接¨(R)收??数?y据Y线?程¨?
//onDataProcess();
//开a启?数?y据Y处?|理¤¨?线?程¨?
//m_dataSendThread.Resume();
IsSendThreadRun =
Thread.Sleep(200);
IsRecvThreadRun =
IsProcessThreadRun =
Thread.Sleep(200);
HandShakeAsk(m_wnd);
//握?手??指?令??
Console.WriteLine("握?手??完?¨?毕??");
else if (e.EventType == EventType.DeviceRemoveComplete)
if (null == e.Device)
if (e.Device.IdProduct == myProductID && e.Device.IdVendor == myVendorID)
Console.WriteLine("断开");
Reader.DataReceived -= (OnRxEndPointData);
Reader.DataReceivedEnabled =
CloseUSB();
closesendthread =
onShutDown();
myDeviceDetected =
IsHandShakeBack =
//新?添?¨?加¨(R)
Console.WriteLine("断开完毕");
下面是发送线程
private void DataSendProc()
int success = 0;
Byte[] SendBuffer = new Byte[12];
//Stopwatch stoptime = new Stopwatch();
while (true)
if (IsSendThreadRun)
if (Send_RJS != Send_Done)
Stopwatch stoptime = new Stopwatch();
stoptime.Start();
if ((myDeviceDetected == true))
for (i = 0; i & 12; i++)
SendBuffer[i] = SendDataBuffer[Send_Done * 12 + i];
success = 0;
success = Write(SendBuffer, 50, 12);
if (success == 12)
if (Send_Done * 12 &= 43200)
Send_Done = 0;
Send_Done++;
Console.WriteLine("警??告?1");
Thread.Sleep(500);
Console.WriteLine("警??告?");
System.Windows.MessageBox.Show("Invalid handle. The device is probably a system mouse or keyboard.", "Alert");
System.Windows.MessageBox.Show("No attempt to write an Output report was made.", "Alert");
stoptime.Stop();
TimeSpan ts = stoptime.E
Console.WriteLine("now time is {0}",ts.TotalMilliseconds);
if (closesendthread == true) {
closesendthread =
Console.WriteLine("close thread");
Thread.Sleep(10); //静2态??方¤?法¤?§,ê?暂Y停??ê当???前??线?程¨?5毫¨?秒?;ê?
按赞数排序
libusbdotnet 的HID实现吗
其他相似问题/view/2094367
1、首先你需要创建一个C#的应用程序(控制台、窗体都可以)
2、将LibUsbDotNet安装目录下Src目录下LibWinUsb拷贝一份到你的工程根目录下
3、不需要多说了吧,在你的解决方案上右击,添加现有项目,将LibWinUsb目录下的项目包含进来
4、在你的项目上右击,添加引用,选择LibUSBDotNet项目,如下图:
5、在你的CS文件开头,添加引用:
using LibUsbDotN
using LibUsbDotNet.M
using LibUsbDotNet.D
using LibUsbDotNet.LibU
using LibUsbDotNet.WinU
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:3310次
排名:千里之外
转载:53篇
(1)(3)(28)(14)(5)(9)(2)unity3d(33)
1. 先下载 ,下载地址 :&http://download.csdn.net/detail/cumtwys/7713473, 下载完之后进行安装。
2. 把&LibUsbDotNet.dll 丢到Unity3D 工程中,就开始使用LibUsbDotNet库了。
3. 根据复制官方例子,进行测试
using LibUsbDotN
using LibUsbDotNet.D
using LibUsbDotNet.M
using LibUsbDotNet.LudnMonoLibU
using System.Collections.ObjectM
using UnityE
public class ShowInfo : MonoBehaviour {
public static UsbDevice MyUsbD
// Use this for initialization
void Start () {
// Dump all devices and descriptor information to console output.
UsbDevice.ForceLibUsbWinBack =
UsbRegDeviceList allDevices = UsbDevice.AllD
Debug.Log(allDevices.Count);
foreach (UsbRegistry usbRegistry in allDevices)
if (usbRegistry.Open(out MyUsbDevice))
Debug..ToString());
for (int iConfig = 0; iConfig & MyUsbDevice.Configs.C iConfig++)
UsbConfigInfo configInfo = MyUsbDevice.Configs[iConfig];
Debug.Log(configInfo.ToString());
ReadOnlyCollection&UsbInterfaceInfo& interfaceList = configInfo.InterfaceInfoL
for (int iInterface = 0; iInterface & interfaceList.C iInterface++)
UsbInterfaceInfo interfaceInfo = interfaceList[iInterface];
Debug.Log(interfaceInfo.ToString());
ReadOnlyCollection&UsbEndpointInfo& endpointList = interfaceInfo.EndpointInfoL
for (int iEndpoint = 0; iEndpoint & endpointList.C iEndpoint++)
Debug.Log(endpointList[iEndpoint].ToString());
// Free usb resources.
// This is necessary for libusb-1.0 and Linux compatibility.
UsbDevice.Exit();
// Update is called once per frame
void Update () {
4. 如果发现有报错 缺少 libusb-1.0.dll 的话,就需要去下载&libusb-1.0.dll,下载地址就是,https://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-1.0.19/,
下载libusb-1.0.19-rc1-win,解压就有&libusb-1.0.dll,把&libusb-1.0.dll 放到Windows/System32中就可以解决了。
5. 如果无法检测设备,那么 需要运行 &install-filter-win.exe 安装对应的 USB 的设备。
6. 目前发现,XBox 手柄可以识别出来。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:46803次
积分:1924
积分:1924
排名:第18380名
原创:142篇
转载:71篇
(1)(14)(12)(4)(15)(11)(12)(2)(22)(7)(16)(27)(4)(1)(10)(15)(7)(2)(3)(18)(8)

我要回帖

更多关于 libusbdotnet下载 的文章

 

随机推荐