public virtual List <string> GetAvailablePorts()
        {
            List <string> ports = SerialPortHandler.GetAvailablePorts()
                                  .Except(PortBlacklist)
                                  .ToList();

            if (PortWhitelist.Count > 0)
            {
                ports = ports.Intersect(PortWhitelist).ToList();
            }

            return(ports);
        }
        protected virtual void SerialPortLoop(object state)
        {
            if (this.ServerState == ServerState.Waiting)
            {
                if (Settings.AutoConnect == true)
                {
                    List <string> availablePorts = SerialPortHandler.GetAvailablePorts();

                    if (availablePorts.Count > 0)
                    {
                        if (availablePorts.Contains(currentPort))
                        {
                            int nextPortIndex = (availablePorts.IndexOf(currentPort) + 1) % availablePorts.Count;
                            currentPort = availablePorts[nextPortIndex];
                        }
                        else
                        {
                            currentPort = availablePorts[0];
                        }

                        if (Serial.Open(currentPort, (int)Settings.PortSpeed))
                        {
                            Serial.SendText(Regex.Unescape(Settings.AutoConnectRequest));
                        }
                    }
                }
                else
                {
                    if (Serial.Open(targetPort, (int)Settings.PortSpeed))
                    {
                        currentPort      = targetPort;
                        this.ServerState = ServerState.Connected;
                    }
                }
            }

            if (this.ServerState == ServerState.Connected)
            {
                if (Serial.IsOpen == false)
                {
                    Reconnect();
                }

                if (Settings.SendMode == SendMode.Stream)
                {
                    SendData();
                }
            }
        }