Пример #1
0
 public DeviceHandle open(ADTRecord adtRecord, char mod)
 {
     try
     {
         Hid handle = new Hid();
         bool flag = false;
         int num = 10;
         do
         {
             foreach (ushort num2 in new ushort[] { ushort.Parse(SRW006.PID, NumberStyles.HexNumber), ushort.Parse(UDP001.PID, NumberStyles.HexNumber) })
             {
                 if (handle.Connect(ushort.Parse(SRW006.VID, NumberStyles.HexNumber), num2, adtRecord.PortAddress.hidAddr.Serial, 20, 20))
                 {
                     flag = true;
                     num = 0;
                     break;
                 }
             }
             Thread.Sleep(50);
         }
         while (--num > 0);
         if (flag)
         {
             DeviceTypeID eid;
             handle.ADT = adtRecord;
             handle.ADT.PortAddress.handle = new DeviceHandle(new HIDHandle(handle));
             handle.ReceiveBuffer = new DataBuffer(2 * handle.GetInputReportBufferLength());
             handle.ADT.DeviceInfo = this.queryDeviceInfo(handle.ADT.PortAddress.handle);
             if (!this.isDeviceAlive(handle.ADT.PortAddress, out eid))
             {
                 throw new Exception("HID device opened but not responding...");
             }
             _log.Info("Device Successfully Opened: " + handle.ADT.PortAddress.hidAddr.Serial);
             return handle.ADT.PortAddress.handle;
         }
         return null;
     }
     catch (Exception exception)
     {
         _log.Error(exception.Message);
         return null;
     }
 }
Пример #2
0
Файл: Hid.cs Проект: x893/WDS
 public static Hid Connect(ushort vid, ushort pid, uint getReportTimeout, uint setReportTimeout)
 {
     Hid handle = new Hid();
     lock (singleLock)
     {
         StringBuilder deviceString = new StringBuilder(260);
         uint deviceIndex = 0;
         ADTManager manager = ADTManager.instance();
         ADTRecord record = new ADTRecord();
         IOPortAddress portAddress = new IOPortAddress {
             portType = PortType.HID
         };
         portAddress.hidAddr.PID = pid;
         portAddress.hidAddr.VID = vid;
         for (uint i = 0; i < GetNumHidDevices(vid, pid); i++)
         {
             byte num3 = GetHidString(i, vid, pid, 4, deviceString, 0x100);
             if (num3 != 3)
             {
                 if (num3 != 0)
                 {
                     return null;
                 }
                 portAddress.hidAddr.Serial = deviceString.ToString();
                 if (manager.findADTRecord(portAddress) != null)
                 {
                     return null;
                 }
                 break;
             }
         }
         if (!GetDeviceIndex(vid, pid, portAddress.hidAddr.Serial, ref deviceIndex))
         {
             return null;
         }
         if (handle.Open(deviceIndex, vid, pid, 0x200) != 0)
         {
             return null;
         }
         handle.SetTimeouts(getReportTimeout, setReportTimeout);
         handle.ADT = new ADTRecord(portAddress, new DeviceDescriptor());
         handle.ADT.PortAddress.handle = new DeviceHandle(new HIDHandle(handle));
         deviceString = new StringBuilder(260);
         if (handle.GetString(3, deviceString, 260) != 0)
         {
             return null;
         }
         handle.ADT.PortAddress.hidAddr.DeviceString = deviceString.ToString();
         handle.ReceiveBuffer = new DataBuffer(handle.GetInputReportBufferLength());
     }
     return handle;
 }