Пример #1
0
        //public byte[] SwVer=new byte[2]{0x20,0x01};
        public bool CheckDevice()
        {
            InteractionData tx = new InteractionData();

            tx.buff[0] = 0x03;
            tx.buff[1] = 0x55;  //主机-->设备
            InteractionData rx = DeviceInteraction(tx);

            if (rx == null || rx.CheckDataList() == false)
            {
                return(false);
            }
            HexID[0] = rx.buff[0x10];
            HexID[1] = rx.buff[0x11];
            HexID[2] = rx.buff[0x12];
            HexID[3] = rx.buff[0x13];

            tx = new InteractionData();
            rx = DeviceInteraction(tx);
            if (rx == null || rx.CheckDataList() == false)
            {
                return(false);
            }
            HexVer[0] = rx.buff[0x10];
            HexVer[1] = rx.buff[0x11];
            return(true);
        }
Пример #2
0
 public InteractionData DeviceInteraction(InteractionData tx, int n)
 {
     try
     {
         //int rxCount = HIDStream.Read(InputReport, 0, m_nInputReportLength);
         if (HIDProcCallback != null)
         {
             HIDProcCallback(-2);
         }
         HIDStream.Write(tx.GetDataList(), 0, m_nOutputReportLength);
         byte[]       InputReport = new byte[m_nInputReportLength];
         IAsyncResult ia          = HIDStream.BeginRead(InputReport, 0, m_nInputReportLength, null, null);
         for (int s = 0; s < n; s++)
         {
             if (ia.AsyncWaitHandle.WaitOne(500, false))
             {
                 if (HIDProcCallback != null)
                 {
                     HIDProcCallback(-1);
                 }
                 InteractionData rx = new InteractionData(InputReport);
                 return(rx);
             }
             else
             {
                 if (HIDProcCallback != null)
                 {
                     HIDProcCallback(s + 1);
                 }
             }
         }
         if (HIDProcCallback != null)
         {
             HIDProcCallback(-1);
         }
         HIDStream.Close();
         HIDStream.Dispose();
         HIDStream = null;
         m_hHandle = CreateFile(hidPath, GENERIC_READ | GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, IntPtr.Zero);
         HIDStream = new FileStream(m_hHandle, FileAccess.Read | FileAccess.Write, m_nInputReportLength, true);
         return(null);
     }
     catch (IOException ex)
     {
         // The device was removed!
         throw new HIDDeviceException(ex.Message + ":Device was removed");
     }
 }
Пример #3
0
 public InteractionData DeviceInteraction(InteractionData tx)
 {
     return(DeviceInteraction(tx, 80));
 }