Example #1
0
        public static void Uncheck(Guid uidGuid)
        {
            var index = GetIndex <CheckListItem>(uidGuid);

            if (AvailableSerialPorts.Any(availableSerialPort => uidGuid == Guid.Parse(availableSerialPort.UidGuid)))
            {
                var checkItem = new CheckListItem
                {
                    ItemName  = AvailableSerialPorts[index].ItemName,
                    UidGuid   = AvailableSerialPorts[index].UidGuid,
                    Content   = AvailableSerialPorts[index].Content,
                    IsChecked = false
                };
                AvailableSerialPorts.RemoveAt(index);
                AvailableSerialPorts.Insert(index, checkItem);
            }
            else if (AvailableModbusSerialPorts.Any(
                         availableModbusSerialPort => uidGuid == Guid.Parse(availableModbusSerialPort.UidGuid)))
            {
                var checkItem = new CheckListItem
                {
                    ItemName  = AvailableModbusSerialPorts[index].ItemName,
                    UidGuid   = AvailableModbusSerialPorts[index].UidGuid,
                    Content   = AvailableModbusSerialPorts[index].Content,
                    IsChecked = false
                };
                AvailableModbusSerialPorts.RemoveAt(index);
                AvailableModbusSerialPorts.Insert(index, checkItem);
            }
            else
            {
                throw new NullReferenceException();
            }
        }
 private void DeviceAdded(object sender, INTV.Shared.Interop.DeviceManagement.DeviceChangeEventArgs e)
 {
     if ((e.Type == INTV.Core.Model.Device.ConnectionType.Serial) && DeviceChange.IsDeviceChangeFromSystem(e.State))
     {
         if (!AvailableSerialPorts.Any(p => p.PortName == e.Name) && ((InclusionFilter == null) || InclusionFilter(Connection.CreatePseudoConnection(e.Name, e.Type))))
         {
             AvailableSerialPorts.Add(new SerialPortViewModel(e.Name));
         }
         INTV.Shared.ComponentModel.CommandManager.InvalidateRequerySuggested();
     }
 }
        private bool ThoroughScan()
        {
            Log(1, "Performing thorough scan.");

            // Then try if last stored connection can be opened
            if (PersistentSettings && TryConnection(_serialConnectionManagerSettings.Port, _serialConnectionManagerSettings.BaudRate) == DeviceStatus.Available)
            {
                return(true);
            }

            // Slowly walk through
            foreach (var portName in AvailableSerialPorts)
            {
                // Get baud rates collection
                var baudRateCollection = DeviceScanBaudRateSelection
                    ? SerialUtils.GetSupportedBaudRates(portName)
                    : new[] { _serialTransport.CurrentSerialSettings.BaudRate };

                //  Now loop through baud rate collection
                if (baudRateCollection.Any())
                {
                    Log(1, "Trying serial port " + portName + " using " + baudRateCollection.Length + " baud rate(s).");

                    foreach (var baudRate in baudRateCollection)
                    {
                        // Stop scanning if state was changed
                        if (ConnectionManagerMode != Mode.Scan)
                        {
                            return(false);
                        }

                        DeviceStatus status = TryConnection(portName, baudRate);
                        if (status == DeviceStatus.Available)
                        {
                            return(true);
                        }
                        if (status == DeviceStatus.IdentityMismatch)
                        {
                            break;                                          // break the loop and continue to next port.
                        }
                    }
                }

                // If port list has changed, interrupt scan and test new ports first
                if (NewPortScan())
                {
                    return(true);
                }
            }

            if (!AvailableSerialPorts.Any())
            {
                // Need to check for new ports if current ports list is empty
                if (NewPortScan())
                {
                    return(true);
                }

                // Add small delay to reduce of Quick->Thorough->Quick->Thorough scan attempts - 400ms here + 100ms in main loop = ~500ms
                Thread.Sleep(400);
            }

            return(false);
        }