Beispiel #1
0
        static public void usbHID_DataReceived(object sender, EventArgs e)
        {
            report      myRP = (report)e;
            List <byte> data = new List <byte>(myRP.reportBuff);

            //添加到接收缓存列表中
            ReceivedListBufferMutex.WaitOne();
            ReceivedListBuffer.Add(data);
            ReceivedListBufferMutex.ReleaseMutex();
        }
Beispiel #2
0
 /// <summary>
 /// 异步读取结束,发出有数据到达事件
 /// </summary>
 /// <param name="iResult">这里是输入报告的数组</param>
 private void ReadCompleted(IAsyncResult iResult)
 {
     byte[] readBuff = (byte[])(iResult.AsyncState);
     try
     {
         hidDevice.EndRead(iResult);//读取结束,如果读取错误就会产生一个异常
         byte[] reportData = new byte[readBuff.Length - 2];
         for (int i = 2; i < readBuff.Length; i++)
         {
             reportData[i - 2] = readBuff[i];
         }
         report e = new report(readBuff[0], reportData);
         OnDataReceived(e); //发出数据到达消息
         BeginAsyncRead();  //启动下一次读操作
     }
     catch (IOException)    //读写错误,设备已经被移除
     {
         EventArgs ex = new EventArgs();
         OnDeviceRemoved(ex);//发出设备移除消息
         CloseDevice();
     }
 }