Beispiel #1
0
 public bool isEqual(IOPortAddress another)
 {
     if (this.portType != another.portType)
     {
         return false;
     }
     if (this.portType == PortType.USB_FTDI)
     {
         if (this.usbFtdiAddr.LocationId != another.usbFtdiAddr.LocationId)
         {
             return false;
         }
         return true;
     }
     if (this.portType == PortType.RS232)
     {
         return (this.comAddr.COMPortId == another.comAddr.COMPortId);
     }
     if (this.portType == PortType.HID)
     {
         return (((this.hidAddr.VID == another.hidAddr.VID) && (this.hidAddr.PID == another.hidAddr.PID)) && (this.hidAddr.Serial == another.hidAddr.Serial));
     }
     if (this.portType == PortType.TOOLSTICK)
     {
         return (((this.toolstickAddr.VID == another.toolstickAddr.VID) && (this.toolstickAddr.PID == another.toolstickAddr.PID)) && (this.toolstickAddr.Serial == another.toolstickAddr.Serial));
     }
     if (this.portType != PortType.USB_EZLink)
     {
         return false;
     }
     return ((this.usbEzLinkAddr.devIdx == another.usbEzLinkAddr.devIdx) && (this.usbEzLinkAddr.freqBand == another.usbEzLinkAddr.freqBand));
 }
Beispiel #2
0
 public ADTRecord(IOPortAddress portAddress, DeviceDescriptor deviceInfo)
 {
     this.DevSyncObj = new object();
     this._selectedAssociatedAppName = "";
     this._associatedApps = new List<ADCRRecord>();
     this._portAddress = portAddress;
     this._uniqId = GlobalServices.uniqId();
     this._deviceInfo = deviceInfo;
     this._isOwnedByDDI = portAddress.portType != PortType.SIMULATION;
 }
Beispiel #3
0
 public ADTRecord()
 {
     this.DevSyncObj = new object();
     this._selectedAssociatedAppName = "";
     this._associatedApps = new List<ADCRRecord>();
     this._portAddress = new IOPortAddress();
     this._isOwnedByDDI = false;
     this._uniqId = GlobalServices.uniqId();
     this._deviceInfo = new DeviceDescriptor();
 }
Beispiel #4
0
 public AddDeviceResult addDevice()
 {
     IOPortAddress portAddress = new IOPortAddress {
         portType = PortType.SIMULATION
     };
     TestDeviceHandle handle = new TestDeviceHandle(new DataBuffer(GlobalServices.maxCommandDataLen + GlobalServices.maxReplyDataLen), 0);
     portAddress.handle = new DeviceHandle(handle);
     DeviceDescriptor deviceInfo = new DeviceDescriptor();
     ADTRecord adtRec = new ADTRecord(portAddress, deviceInfo);
     return addDevice(adtRec);
 }
Beispiel #5
0
 private void PollingAddDevice()
 {
     ADTManager.instance();
     IOPortAddress address = new IOPortAddress();
     int devIdx = 0;
     int freqBand = 1;
     address.portType = PortType.USB_EZLink;
     while (!this._isPollerRunEnabled)
     {
         Thread.Sleep(0x3e8);
     }
     WDSFrameWindow window = WDS_MainProg.frameWin();
     Label_0032:
     while (!this._isPollerRunEnabled)
     {
         Thread.Sleep(0x3e8);
     }
     Thread.Sleep(0x3e8);
     devIdx = ADTManager.instance().readNextFree();
     DeviceHandle handle = this.open(devIdx, freqBand);
     if (handle.isInvalid())
     {
         goto Label_0032;
     }
     IOPortAddress address2 = new IOPortAddress {
         portType = PortType.USB_EZLink
     };
     address2.usbEzLinkAddr.devIdx = devIdx;
     address2.handle = handle;
     try
     {
         if (((AddDeviceResult) window.Invoke(new AddDevice(window.addDevice), new object[] { "Add Device (found by EZLink Plug & Play handler)", address2, "Exclude Device", new CompatibleDeviceDescriptor() })) == AddDeviceResult.ExcludeOrCancel)
         {
             this.close(handle);
         }
         goto Label_0032;
     }
     catch
     {
         GlobalServices.ErrMsg("DDI_EZLink", "Invoking AddDevice failed");
         this.close(handle);
         goto Label_0032;
     }
 }
Beispiel #6
0
 public bool IsPortActive(IOPortAddress CheckPort)
 {
     return true;
 }
Beispiel #7
0
        private void PollingAddDevice()
        {
            ADTManager manager = ADTManager.instance();
            IOPortAddress portAddress = new IOPortAddress
            {
                portType = PortType.RS232
            };
            int pollingAddDeviceDelay = int.Parse(ConfigurationManager.AppSettings["PollingAddDeviceDelay"]);

            _log.Debug("DDI_RS232 PollingAddDevice thread started");
            while (!_isPollerRunEnabled)
                Thread.Sleep(250);

            WDSFrameWindow window = WDS_MainProg.frameWin();
            while (!_isPollerStopped)
            {
                if (!_isPollerRunEnabled)
                    Thread.Sleep(250);
                else
                {
                    Thread.Sleep(pollingAddDeviceDelay);
                    string[] portNames = SerialPort.GetPortNames();
                    List<string> list = ADTManager.instance().syncRS232PortLists(portNames);
                    if (list != null)
                    {
                        string str = "";
                        foreach (string str2 in list)
                            str = str + str2 + " ";
                        _log.Debug("Excluded attributes are cleared for port(s): " + str);
                    }

                    List<IOPortAddress> newKnownPorts = new List<IOPortAddress>();
                    newKnownPorts = GetNewKnownPorts(portNames);
                    for (int i = 0; i < newKnownPorts.Count; i++)
                    {
                        portAddress = newKnownPorts[i];
                        if (manager.findADTRecord(portAddress) == null &&
                            !manager.isRS232PortExcluded("COM" + newKnownPorts[i].comAddr.COMPortId.ToString())
                            )
                        {
                            DeviceHandle handle = open(portAddress, 19200, 'D');
                            portAddress.handle = handle;
                            if (!manager.restoreFreezedDevice(portAddress))
                            {
                                if (!handle.isInvalid())
                                {
                                    bool bootLoaderMode;
                                    DeviceTypeID deviceType;
                                    if (isDeviceAlive(portAddress, out bootLoaderMode, out deviceType))
                                    {
                                        DeviceDescriptor devInfo = new DeviceDescriptor
                                        {
                                            BootloaderMode = bootLoaderMode
                                        };
                                        if (!bootLoaderMode)
                                        {
                                            queryDeviceInfo(portAddress.handle, devInfo);
                                            queryEBID(portAddress.handle, devInfo);
                                        }
                                        else
                                        {
                                            queryDeviceInfo(portAddress.handle, devInfo);
                                            if (devInfo.DeviceType == null)
                                            {
                                                devInfo.DeviceType = new DeviceType(deviceType);
                                                devInfo.DeviceVersion = new DeviceVersion("Unknown");
                                            }
                                        }
                                        ADTRecord record = new ADTRecord(portAddress, devInfo);
                                        if (!bootLoaderMode)
                                            InitDeviceSettings(portAddress.handle, devInfo);

                                        try
                                        {
                                            switch (((AddDeviceResult)window.Invoke(new AddDevice(window.addDevice), new object[] { record })))
                                            {
                                                case AddDeviceResult.AppStarted:
                                                    continue;
                                                case AddDeviceResult.FirmwareReplaced:
                                                case AddDeviceResult.Aborted:
                                                    close(record.PortAddress.handle);
                                                    continue;
                                                case AddDeviceResult.ExcludeOrCancel:
                                                    _log.Debug("COM" + portAddress.comAddr.COMPortId.ToString() + " port permanently excluded from WDS.");
                                                    CloseDeviceSettings(record.PortAddress.handle, devInfo);
                                                    manager.excludeRS232Port("COM" + newKnownPorts[i].comAddr.COMPortId.ToString());
                                                    close(record.PortAddress.handle);
                                                    continue;
                                            }
                                        }
                                        catch (Exception exception)
                                        {
                                            _log.Error("PollingAddDevice() - Invoking AddDevice failed " + exception.Message);
                                            close(record.PortAddress.handle);
                                        }
                                    }
                                    else
                                    {
                                        close(portAddress.handle);
                                        _log.Error("Could not communicate with device COM" + portAddress.comAddr.COMPortId.ToString() + ". The device will be excluded!");
                                        manager.excludeRS232Port("COM" + portAddress.comAddr.COMPortId.ToString());
                                    }
                                }
                                else
                                    _log.Error("PollingAddDevice() - Cannot open port: " + newKnownPorts[i]);
                            }
                        }
                    }
                }
            }
            _log.Debug("DDI_RS232 PollingAddDevice thread finished");
        }
Beispiel #8
0
        private bool isDeviceAlive(IOPortAddress iopaddr, out bool bootLoaderMode, out DeviceTypeID deviceType)
        {
            string command_CR = "\r";
            DataBuffer data = new DataBuffer(100);
            bootLoaderMode = false;
            deviceType = DeviceTypeID.Unknown;

            if (iopaddr.handle == null)
                return false;
            if (iopaddr.handle.isInvalid())
            {
                _log.Warn("Called with INVALID handle");
                return false;
            }

            int writeRetryCnt = int.Parse(ConfigurationManager.AppSettings["WriteRetryCnt"]);
            int readRetryCnt = int.Parse(ConfigurationManager.AppSettings["ReadRetryCnt"]);

            while (writeRetryCnt > 0)
            {
                data.copy(command_CR);
                if (write(iopaddr.handle, data) < 0)
                {
                    Thread.Sleep(10);
                    writeRetryCnt--;
                }
                else
                {
                    _log.Debug("[CR] was sent");
                    data.NumItems = 0;
                    int readCount = readRetryCnt;
                    while (readCount > 0)
                    {
                        if (readAppend(iopaddr.handle, data, data.Capacity - data.NumItems) < 0)
                            readCount--;
                        else
                        {
                            if (data.endsWith("OK\n\r>"))
                            {
                                _log.Debug("Device looks to be alive");
                                return true;
                            }
                            Thread.Sleep(20);
                            readCount--;
                        }
                    }
                    Thread.Sleep(20);
                    writeRetryCnt--;
                }
            }
            _log.Debug("Device to be checked with RTS control enabled");
            close(iopaddr.handle);

            iopaddr.handle = open(iopaddr, 19200, 'E');
            _log.Debug("Port opened by isDeviceAlive()@19200:" + iopaddr.comAddr.COMPortId + " DTR Enabled");
            writeRetryCnt = int.Parse(ConfigurationManager.AppSettings["WriteRetryCnt"]);
            readRetryCnt = int.Parse(ConfigurationManager.AppSettings["ReadRetryCnt"]);
            while (writeRetryCnt > 0)
            {
                data.copy(command_CR);
                if (write(iopaddr.handle, data) < 0)
                {
                    Thread.Sleep(10);
                    writeRetryCnt--;
                }
                else
                {
                    _log.Debug("isDeviceAlive():: '\r' sent");
                    data.NumItems = 0;
                    int num4 = readRetryCnt;
                    while (num4 > 0)
                    {
                        if (readAppend(iopaddr.handle, data, data.Capacity - data.NumItems) < 0)
                        {
                            Thread.Sleep(10);
                            num4--;
                        }
                        else
                        {
                            _log.Debug("isDeviceAlive():: response to '\r':" + data.BufToStr);
                            if (data.BufToStr.Contains("OK\n\r>"))
                                return true;
                            Thread.Sleep(20);
                            num4--;
                        }
                    }
                    Thread.Sleep(20);
                    writeRetryCnt--;
                }
            }
            close(iopaddr.handle);
            _log.Debug("Port closed by isDeviceAlive()@19200:" + iopaddr.comAddr.COMPortId);

            iopaddr.handle = open(iopaddr, 115200, 'D');
            _log.Debug("Port opened by isDeviceAlive()@115200:" + iopaddr.comAddr.COMPortId);
            for (int i = 0; i < 4; i++)
            {
                data.copy("J");
                if (write(iopaddr.handle, data) < 0)
                    Thread.Sleep(10);
                Thread.Sleep(50);
                _log.Debug("isDeviceAlive():: 'J' sent");
                data.NumItems = 0;
                int readCnt = readRetryCnt;
                while (readCnt > 0)
                {
                    if (readAppend(iopaddr.handle, data, data.Capacity - data.NumItems) < 0)
                    {
                        Thread.Sleep(10);
                        readCnt--;
                    }
                    else
                    {
                        _log.Debug("isDeviceAlive():: response to 'J':" + data.BufToStr);
                        if (data.endsWith("OK\r\n>\r\n"))
                        {
                            deviceType = DeviceTypeID.SDBC_8;
                            bootLoaderMode = true;
                            return true;
                        }
                        Thread.Sleep(20);
                        readCnt--;
                    }
                }
            }

            writeRetryCnt = int.Parse(ConfigurationManager.AppSettings["WriteRetryCnt"]);
            readRetryCnt = int.Parse(ConfigurationManager.AppSettings["ReadRetryCnt"]);
            while (writeRetryCnt > 0)
            {
                data.copy("OK\n\r>");
                if (write(iopaddr.handle, data) < 0)
                {
                    Thread.Sleep(10);
                    writeRetryCnt--;
                }
                else
                {
                    _log.Debug("[CRLF] sent");
                    data.NumItems = 0;
                    int num7 = readRetryCnt;
                    while (num7 > 0)
                    {
                        if (readAppend(iopaddr.handle, data, data.Capacity - data.NumItems) < 0)
                        {
                            Thread.Sleep(10);
                            num7--;
                        }
                        else
                        {
                            _log.Debug("Response to [CRLF]:" + data.BufToStr);
                            if (data.endsWith("OK\n\r>"))
                                return true;
                            Thread.Sleep(20);
                            num7--;
                        }
                    }
                    Thread.Sleep(20);
                    writeRetryCnt--;
                }
            }
            return false;
        }
Beispiel #9
0
 public bool SetBootloadMode(IOPortAddress iopaddr, bool mode)
 {
     return false;
 }
Beispiel #10
0
 public bool GetBootloadMode(IOPortAddress iopaddr, ref bool mode)
 {
     DataBuffer data = new DataBuffer();
     if (this.GetFeatureReport(iopaddr.handle, 20, data) < 0)
     {
         return false;
     }
     if (data[1] == 0)
     {
         mode = false;
     }
     else
     {
         mode = true;
     }
     return true;
 }
Beispiel #11
0
 public bool IsPortActive(IOPortAddress CheckPort)
 {
     _mut.WaitOne();
     if (CheckPort == null ||
         CheckPort.handle == null ||
         CheckPort.handle.TOOLSTICKhnd == null ||
         CheckPort.handle.TOOLSTICKhnd.hnd == null
         )
         return false;
     bool flag = true;
     if (!_disableDecivePortActiveCheck)
         flag = CheckPort.handle.TOOLSTICKhnd.hnd.IsOpened() != 0;
     _mut.ReleaseMutex();
     return flag;
 }
Beispiel #12
0
 public bool restoreFreezedDevice(IOPortAddress port)
 {
     foreach (ADTRecord record in _freezedDevices)
     {
         if (record.PortAddress.isEqual(port))
         {
             record.PortAddress = port;
             return true;
         }
     }
     return false;
 }
Beispiel #13
0
 public ADTRecord findADTRecord(IOPortAddress portAddress)
 {
     if (portAddress != null)
     {
         int num = -1;
         for (int i = 0; i < _ADTRecords.Count; i++)
         {
             if ((_ADTRecords[i].PortAddress != null) && _ADTRecords[i].PortAddress.isEqual(portAddress))
             {
                 num = i;
                 break;
             }
         }
         if (num > -1)
             return _ADTRecords[num];
     }
     return null;
 }
Beispiel #14
0
 private void Polling()
 {
     ADTManager manager = ADTManager.instance();
     List<IOPortAddress> list = new List<IOPortAddress>();
     IOPortAddress item = new IOPortAddress();
     int nrOfDevices = 0;
     int count = 0;
     int locationID = 0;
     StringBuilder description = new StringBuilder();
     StringBuilder serialNumber = new StringBuilder();
     while (!this._isPollerRunEnabled)
     {
         Thread.Sleep(0x3e8);
     }
     WDSFrameWindow window = WDS_MainProg.frameWin();
     while (true)
     {
         while (!this._isPollerRunEnabled)
         {
             Thread.Sleep(0x3e8);
         }
         count = manager.getADTRecords(PortType.USB_FTDI, true).Count;
         uint num3 = FTDIWrapper.GetNrOfDevices(ref nrOfDevices);
         if (count != nrOfDevices)
         {
             list.Clear();
             for (int i = 0; i < nrOfDevices; i++)
             {
                 item = new IOPortAddress {
                     portType = PortType.USB_FTDI
                 };
                 item.usbFtdiAddr.DeviceIdx = i;
                 num3 = FTDIWrapper.GetLocationID(i, ref locationID);
                 while ((num3 != 0) && (num3 != 1))
                 {
                     GlobalServices.LogMsg(i.ToString() + " " + num3.ToString(), "asdf");
                     num3 = FTDIWrapper.GetLocationID(i, ref locationID);
                     Thread.Sleep(500);
                 }
                 item.usbFtdiAddr.LocationId = locationID;
                 num3 = FTDIWrapper.GetSerialNumber(i, serialNumber);
                 item.usbFtdiAddr.SerialNo = serialNumber.ToString();
                 num3 = FTDIWrapper.GetDescription(i, description);
                 item.usbFtdiAddr.Description = description.ToString();
                 list.Add(item);
             }
             if (count < nrOfDevices)
             {
                 foreach (IOPortAddress address2 in list)
                 {
                     if (manager.findADTRecord(address2) == null)
                     {
                         try
                         {
                             object[] args = new object[5];
                             args[0] = "Add Device (found by USB_FTDI Plug & Play handler)";
                             args[1] = address2;
                             args[3] = "Exclude Device";
                             args[4] = new CompatibleDeviceDescriptor();
                             if (((AddDeviceResult) window.Invoke(new AddDevice(window.addDevice), args)) == AddDeviceResult.ExcludeOrCancel)
                             {
                             }
                         }
                         catch
                         {
                             GlobalServices.ErrMsg("DDI_USB_FTDI", "Invoking AddDevice failed");
                         }
                     }
                 }
             }
             else
             {
                 bool flag = false;
                 foreach (ADTRecord record in manager.getADTRecords(PortType.USB_FTDI, true))
                 {
                     foreach (IOPortAddress address3 in list)
                     {
                         if (record.PortAddress.isEqual(address3))
                         {
                             flag = true;
                         }
                     }
                     if (!flag && (manager.removeADTRecord(record) != -1))
                     {
                         try
                         {
                             WDSApplicationManager.instance().closeApplications(record);
                         }
                         catch
                         {
                             GlobalServices.ErrMsg("DDI_USB_FTDI", "Invoking RemoveDevice failed");
                         }
                     }
                     flag = false;
                 }
             }
         }
         else
         {
             Thread.Sleep(0x3e8);
         }
     }
 }
Beispiel #15
0
        public List<IOPortAddress> GetPortnamesForCP210xDevs()
        {
            List<IOPortAddress> list = new List<IOPortAddress>();
            try
            {
                RegistryKey localMachine = Registry.LocalMachine;
                RegistryKey key2 = localMachine.OpenSubKey(@"HARDWARE\DEVICEMAP\SERIALCOMM");
                string[] valueNames = key2.GetValueNames();
                List<string> list2 = new List<string>();
                foreach (string str in valueNames)
                    if (str.Contains("Silabs") || str.Contains("Slab"))
                        list2.Add((string) key2.GetValue(str));

                RegistryKey key3 = localMachine.OpenSubKey(@"System\CurrentControlSet\Enum\USB");
                string[] subKeyNames = key3.GetSubKeyNames();
                int num = 0;
                foreach (string str2 in subKeyNames)
                {
                    RegistryKey key4 = key3.OpenSubKey(str2);
                    foreach (string str3 in key4.GetSubKeyNames())
                    {
                        RegistryKey key6 = key4.OpenSubKey(str3).OpenSubKey("Device Parameters");
                        string str4 = "";
                        if (key6 != null)
                            str4 = (string) key6.GetValue("PortName");
                        if (str4 != null)
                        {
                            foreach (string str5 in list2)
                            {
                                if (str4 == str5)
                                {
                                    IOPortAddress item = new IOPortAddress {
                                        comAddr = { COMPortId = Convert.ToInt32(str4.Replace("COM", "")) },
                                        portType = PortType.RS232
                                    };
                                    item.usbCP210xAddr.DeviceIdx = num;
                                    num++;
                                    list.Add(item);
                                }
                            }
                        }
                    }
                }
                return list;
            }
            catch
            {
                return list;
            }
        }
Beispiel #16
0
 public bool IsPortActive(IOPortAddress CheckPort)
 {
     bool flag;
     _mut.WaitOne();
     if (CheckPort == null)
     {
         return false;
     }
     if (CheckPort.handle == null)
     {
         return false;
     }
     if (CheckPort.handle.HIDhnd == null)
     {
         return false;
     }
     if (CheckPort.handle.HIDhnd.hnd == null)
     {
         return false;
     }
     if (CheckPort.handle.HIDhnd.hnd.IsOpened() == 0)
     {
         flag = false;
     }
     else
     {
         flag = true;
     }
     _mut.ReleaseMutex();
     return flag;
 }
Beispiel #17
0
 public bool IsPortActive(IOPortAddress CheckPort)
 {
     _mut.WaitOne();
     try
     {
         bool flag = false;
         string[] portNames = SerialPort.GetPortNames();
         IOPortAddress another = new IOPortAddress
         {
             portType = PortType.RS232
         };
         for (int i = 0; i < portNames.Length; i++)
         {
             string s = portNames[i].Replace("COM", "");
             for (int j = s.Length - 1; j >= 0; j--)
                 if (!char.IsNumber(s, j))
                     s = s.Remove(j, 1);
             another.comAddr.COMPortId = Convert.ToInt32(s);
             if (CheckPort.isEqual(another))
                 flag = true;
         }
         if ((CheckPort.usbCP210xAddr.DeviceIdx != -1) && flag)
         {
             try
             {
                 if (CheckPort.handle.devType == PortType.INVALID ||
                     CheckPort.handle.RS232hnd.hnd == null ||
                     !CheckPort.handle.RS232hnd.hnd.IsOpen
                     )
                 {
                     _mut.ReleaseMutex();
                     return false;
                 }
                 bool cDHolding = CheckPort.handle.RS232hnd.hnd.CDHolding;
                 _mut.ReleaseMutex();
                 return true;
             }
             catch (Exception exception)
             {
                 _log.Error("IsPortActive() 1 - " + exception.Message);
                 _mut.ReleaseMutex();
                 return false;
             }
         }
         _mut.ReleaseMutex();
         return flag;
     }
     catch (Exception exception2)
     {
         _log.Error("IsPortActive() 2 - " + exception2.Message);
         _mut.ReleaseMutex();
         return false;
     }
 }
Beispiel #18
0
 public bool SetBootloadMode(IOPortAddress iopaddr, bool mode)
 {
     DataBuffer data = new DataBuffer {
         NumItems = 1
     };
     data[0] = mode ? ((byte) 1) : ((byte) 0);
     return (this.SetFeatureReport(iopaddr.handle, 20, data) >= 0);
 }
Beispiel #19
0
        private List<IOPortAddress> GetNewKnownPorts(string[] portNames)
        {
            ADTManager manager = ADTManager.instance();
            IOPortAddress portAddress = new IOPortAddress();
            List<IOPortAddress> list = new List<IOPortAddress>();
            List<IOPortAddress> list2 = new List<IOPortAddress>();
            portAddress.portType = PortType.RS232;
            List<string> list3 = new List<string>();
            for (int i = 0; i < portNames.Length; i++)
            {
                if (portNames[i] != null && portNames[i].StartsWith("COM"))
                {
                    try
                    {
                        string s = portNames[i].Replace("COM", "");
                        for (int k = s.Length - 1; k >= 0; k--)
                            if (!char.IsNumber(s, k))
                                s = s.Remove(k, 1);

                        portAddress.comAddr.COMPortId = Convert.ToInt32(s);
                        if (!manager.isRS232PortExcluded(portNames[i]) && manager.findADTRecord(portAddress) == null)
                            list3.Add(portNames[i]);
                    }
                    catch (Exception exception)
                    {
                        string str2 = "";
                        for (int m = 0; m < portNames.Length; m++)
                        {
                            str2 = str2 + portNames[m] + " | ";
                        }
                        _log.Error(string.Concat(new object[] { "GetNewKnownPorts() - Could not parse the ports. Message: ", exception.Message, " - Ports: ", portNames }));
                        return list;
                    }
                }
            }
            if (list3.Count > 0)
                list2 = GetPortnamesForCP210xDevs();

            for (int j = 0; j < list3.Count; j++)
            {
                string str3 = list3[j].Replace("COM", "");
                for (int n = str3.Length - 1; n >= 0; n--)
                    if (!char.IsNumber(str3, n))
                        str3 = str3.Remove(n, 1);

                try
                {
                    portAddress.comAddr.COMPortId = Convert.ToInt32(str3);
                    bool flag = false;
                    for (int num6 = 0; num6 < list2.Count; num6++)
                        if (list2[num6].isEqual(portAddress))
                        {
                            list.Add(list2[num6]);
                            flag = true;
                        }

                    if (GlobalServices.isfeatureAllowed(GlobalServices.Features.LoadBoardSupport) &&
                        !flag &&
                        isFTDIDevice(list3[j])
                        )
                    {
                        list.Add(portAddress);
                        flag = true;
                    }
                    if (!flag)
                        manager.excludeRS232Port(list3[j]);
                }
                catch (Exception exception2)
                {
                    string str4 = "";
                    for (int num7 = 0; num7 < list2.Count; num7++)
                        str4 = str4 + list2[num7].comAddr.ToString() + " | ";

                    _log.Error("GetNewKnownPorts() - Could not compare FTDI ports to CP21XX. Message: " + exception2.Message + " - CP21x ports: " + str4);
                    return list;
                }
            }
            return list;
        }
Beispiel #20
0
        private bool isDeviceAlive(IOPortAddress iopaddr, out DeviceTypeID deviceType)
        {
            DataBuffer data = new DataBuffer(0x40);
            deviceType = DeviceTypeID.Unknown;
            if (iopaddr.handle.isInvalid())
            {
                _log.Warn("Called with INVALID handle");
                return false;
            }
            if (this.GetFeatureReport(iopaddr.handle, 0x10, data) < 0)
            {
                _log.Debug("Device accessibility check failed.");
                return false;
            }
            switch (data[1])
            {
                case 0:
                    deviceType = DeviceTypeID.SRW006;
                    break;

                case 1:
                    deviceType = DeviceTypeID.SRW006;
                    break;
            }
            return true;
        }
Beispiel #21
0
        private DeviceHandle open(IOPortAddress a_iopAddr, int baudRate, char a_handshake)
        {
            DeviceHandle handle = new DeviceHandle();
            SafeSerialPort port = null;
            string portName = "COM" + a_iopAddr.comAddr.COMPortId.ToString();
            _log.Debug(string.Concat(new object[] { "Serial Port to open, ", portName, ", baud:", baudRate }));
            if (!ADTManager.instance().isRS232PortExcluded(portName))
            {
                bool flag;
                int num = 0;
                do
                {
                    flag = false;
                    try
                    {
                        bool suppressFinalize = false;
                        suppressFinalize = true;
                        port = new SafeSerialPort(portName, baudRate, Parity.None, 8, StopBits.One, suppressFinalize);
                        port.Open();
                        port.ReadTimeout = 100;
                        if (a_handshake == 'E')
                            port.RtsEnable = true;
                        else
                            port.RtsEnable = false;

                        Thread.Sleep(20);
                        handle = new DeviceHandle(new RS232Handle(port));
                        a_iopAddr.comAddr.baudRate = baudRate;
                    }
                    catch (Exception exception)
                    {
                        flag = true;
                        num++;
                        _log.Error("Open() - " + portName + " - " + exception.Message);
                        if (port != null)
                            port.Dispose();
                    }
                    Thread.Sleep(50);
                }
                while (flag && (num < 3));
                if (flag && !ADTManager.instance().isRS232PortExcluded(portName))
                {
                    _log.Debug(portName + " is busy. Temporarily excluded from WDS.");
                    ADTManager.instance().excludeRS232Port(portName);
                }
            }
            else
                _log.Debug("Port is excluded, will not open it:" + portName);

            _log.Debug("Port has been successfully (re)opened");
            return handle;
        }
Beispiel #22
0
 public static CToolStick Connect(ushort vid, ushort pid, uint getReportTimeout, uint setReportTimeout)
 {
     CToolStick handle = new CToolStick();
     lock (singleLock)
     {
         StringBuilder str = new StringBuilder(260);
         StringBuilder builder2 = new StringBuilder(256);
         bool flag = false;
         ADTManager manager = ADTManager.instance();
         ADTRecord record = new ADTRecord();
         IOPortAddress portAddress = new IOPortAddress
         {
             portType = PortType.TOOLSTICK
         };
         portAddress.toolstickAddr.PID = pid;
         portAddress.toolstickAddr.VID = vid;
         ushort num = 0;
         ushort num2 = 0;
         ushort devRelNum = 0;
         uint numDevices = GetNumDevices();
         for (uint i = 0; i < numDevices; i++)
         {
             if (GetAttributes(i, ref num, ref num2, ref devRelNum) != 0 ||
                 pid != num2 ||
                 vid != num ||
                 GetString(i, 3, str, 260) != 0 ||
                 GetString(i, 4, builder2, 0x100) != 0 ||
                 manager.isToolStickDeviceExcluded(builder2.ToString())
                 )
             {
                 continue;
             }
             bool flag2 = false;
             WDS_MainProg.frameWin().DisablePlugAndPlay();
             int num7 = 0x4e20;
             int millisecondsTimeout = 0x7d0;
             int tickCount = Environment.TickCount;
             int dwDevices = 0;
             while (ToolStickDebugUtil.USBDebugDevices(ref dwDevices) != 0 && (Environment.TickCount - tickCount) < num7)
             {
                 Thread.Sleep(millisecondsTimeout);
                 millisecondsTimeout += 0x3e8;
             }
             for (int j = 0; j < dwDevices; j++)
             {
                 StringBuilder psSerialNum = new StringBuilder(0x80);
                 if ((ToolStickDebugUtil.GetUSBDeviceSN(j, ref psSerialNum) == 0) && (psSerialNum.ToString() == builder2.ToString()))
                 {
                     if (ToolStickDebugUtil.ConnectUSB(psSerialNum, 1, 1, 0) == 0)
                     {
                         flag2 = true;
                         ToolStickDebugUtil.SetTargetGo();
                         ToolStickDebugUtil.DisconnectUSB();
                         Thread.Sleep(250);
                     }
                     break;
                 }
             }
             WDS_MainProg.frameWin().RestorePlugAndPlay();
             if (!flag2)
                 _log.Error("Could not verify the Firmware on the Toolstick!");
             if (handle.Open(i) == 0)
                 flag = true;
             portAddress.toolstickAddr.DeviceString = str.ToString();
             portAddress.toolstickAddr.Serial = builder2.ToString();
             if (manager.findADTRecord(portAddress) == null)
                 break;
         }
         if (!flag)
             return null;
         handle.SetTimeouts(getReportTimeout, setReportTimeout);
         handle.ADT = new ADTRecord(portAddress, new DeviceDescriptor());
         handle.ADT.PortAddress.handle = new DeviceHandle(new TOOLSTICKHandle(handle));
         str = new StringBuilder(260);
         if (handle.GetOpenedString(3, str, 260) != 0)
             return null;
         handle.ADT.PortAddress.toolstickAddr.DeviceString = str.ToString();
         uint maxReadSize = 60;
         maxReadSize = handle.GetMaxReadSize();
         if (maxReadSize != 0)
             maxReadSize = 120;
         handle.ReceiveBuffer = new DataBuffer((int) maxReadSize);
     }
     return handle;
 }
Beispiel #23
0
        private void PollingRemoveDevice()
        {
            WDSFrameWindow window = WDS_MainProg.frameWin();
            ADTManager.instance();
            IOPortAddress address = new IOPortAddress();
            int pollingRemoveDeviceDelay = int.Parse(ConfigurationManager.AppSettings["PollingRemoveDeviceDelay"]);
            address.portType = PortType.RS232;
            while (!_isPollerStopped)
            {
                if (!_isPollerRunEnabled)
                    Thread.Sleep(250);
                else
                {
                    Thread.Sleep(pollingRemoveDeviceDelay);
                    ADTManager manager = ADTManager.instance();
                    List<ADTRecord> list = new List<ADTRecord>();
                    for (int i = 0; i < manager.ADTRecCount(); i++)
                        if (manager[i] != null &&
                            manager[i].PortAddress != null &&
                            manager[i].PortAddress.portType == PortType.RS232 &&
                            manager[i].PortAddress.handle != null &&
                            !IsPortActive(manager[i].PortAddress)
                            )
                        {
                            try
                            {
                                window.Invoke(
                                    new RemoveDevice(window.removeDevice),
                                    new object[] { manager[i] }
                                    );
                            }
                            catch { }
                            list.Add(manager[i]);
                        }

                    foreach (ADTRecord record in list)
                        if (record != null)
                        {
                            _log.Warn("Remove device:      " + record.objectInfo());
                            WDSApplicationManager.instance().closeApplications(record);
                        }
                }
            }
            _log.Debug("DDI_RS232 PollingRemoveDevice thread finished");
        }
Beispiel #24
0
Datei: Hid.cs Projekt: 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;
 }