示例#1
0
        public bool Connect(HidDeviceInfo hidDevice)
        {
            ReusltString result = new ReusltString();

            HidDeviceData.HID_RETURN hdrtn = device.OpenDevice(hidDevice.vID, hidDevice.pID, hidDevice.serial);

            if (hdrtn == HidDeviceData.HID_RETURN.SUCCESS)
            {
                bConnected = true;

                #region 消息通知
                result.Result  = true;
                result.message = "设备连接成功!";
                RaiseEventConnectedState(result.Result);
                #endregion

                return(true);
            }

            bConnected = false;

            #region 消息通知
            result.Result  = false;
            result.message = "设备连接错误";
            RaiseEventConnectedState(result.Result);

            #endregion
            return(false);
        }
示例#2
0
 void HidDeviceRemoved(object sender, EventArgs e)
 {
     bConnected = false;
     #region 消息通知
     ReusltString result = new ReusltString();
     result.Result  = false;
     result.message = "Device Remove";
     RaiseEventConnectedState(result.Result);
     #endregion
     if (device != null)
     {
         device.CloseDevice();
     }
 }
示例#3
0
        public void HidDataReceived(object sender, HidDeviceReport e)
        {
            try
            {
                //第一个字节为数据长度,因为Device 的HID数据固定长度为64字节,取有效数据
                byte[] buf = new byte[e.reportBuff[0]];
                Array.Copy(e.reportBuff, 1, buf, 0, e.reportBuff[0]);

                //推送数据
                RaiseEventDataReceived(buf);
            }
            catch
            {
                #region 消息通知
                ReusltString result = new ReusltString();
                result.Result  = false;
                result.message = "Receive Error";
                RaiseEventConnectedState(result.Result);
                #endregion
            }
        }