Пример #1
0
        private DeviceHandle openDevice()
        {
            try
            {
                if ((Thread.CurrentThread.Name == string.Empty) || (Thread.CurrentThread.Name == null))
                    Thread.CurrentThread.Name = "MAIN thread";
                if (_isDdiTerminated)
                    return null;
                CToolStick stick = null;
                foreach (ushort num in new ushort[] { ushort.Parse(ToolStick.PID, NumberStyles.HexNumber) })
                {
                    ADTManager.instance().syncToolStickDevicesSerials(CToolStick.GetAllDeviceSerials(ushort.Parse(ToolStick.VID, NumberStyles.HexNumber), num));
                    stick = CToolStick.Connect(ushort.Parse(ToolStick.VID, NumberStyles.HexNumber), num, 20, 20);
                    if (stick != null)
                        break;
                }
                if (stick == null)
                    return null;
                if (((stick.IsUartEnabled() != 1) && (stick.EnableUart() != 0)) && (stick.FlushUartQueues(1, 1) != 0))
                    throw new Exception("TOOLSTICK device UART failed");
                TOOLSTICKHandle handle = new TOOLSTICKHandle(stick);
                DeviceHandle dh = new DeviceHandle(handle);
                dh.TOOLSTICKhnd.hnd.ADT.DeviceInfo = queryDeviceInfo(dh);
                _log.Info("Device Successfully Opened: " + stick.ADT.PortAddress.toolstickAddr.Serial);
                try
                {
                    WDSFrameWindow window = WDS_MainProg.frameWin();
                    switch (((AddDeviceResult) window.Invoke(new AddDevice(window.addDevice), new object[] { dh.TOOLSTICKhnd.hnd.ADT })))
                    {
                        case AddDeviceResult.AppStarted:
                        case AddDeviceResult.FirmwareReplaced:
                        case AddDeviceResult.Aborted:
                            break;

                        case AddDeviceResult.ExcludeOrCancel:
                            ADTManager.instance().excludeToolStickDevice(stick.ADT.PortAddress.toolstickAddr.Serial);
                            break;
                    }
                }
                catch (Exception exception)
                {
                    _log.Error("Invoking AddDevice failed " + exception.Message);
                }
                open();
                return dh;
            }
            catch (Exception exception2)
            {
                _log.Error(exception2.Message);
                return null;
            }
        }
Пример #2
0
 public DeviceHandle(TOOLSTICKHandle handle)
 {
     this._devType = PortType.TOOLSTICK;
     this._TOOLSTICKhnd = handle;
 }
Пример #3
0
 public DeviceHandle open(ADTRecord _adtRec)
 {
     try
     {
         if (_isDdiTerminated)
             return null;
         CToolStick stick = null;
         foreach (ushort num in new ushort[] { ushort.Parse(ToolStick.PID, NumberStyles.HexNumber) })
         {
             stick = CToolStick.Connect(ushort.Parse(ToolStick.VID, NumberStyles.HexNumber), num, 20, 20);
             if (stick != null)
                 break;
         }
         if (stick == null)
             return null;
         if (((stick.IsUartEnabled() != 1) && (stick.EnableUart() != 0)) && (stick.FlushUartQueues(1, 1) != 0))
             throw new Exception("TOOLSTICK device UART failed");
         TOOLSTICKHandle handle = new TOOLSTICKHandle(stick);
         DeviceHandle handle2 = new DeviceHandle(handle);
         stick.ADT.PortAddress.handle = handle2;
         return stick.ADT.PortAddress.handle;
     }
     catch (Exception exception)
     {
         _log.Error(exception.Message);
         return null;
     }
 }