private static IEnumerable <SerialPortViewModel> GetSerialPorts()
        {
            string wmiQuery = string.Format("SELECT Name, DeviceID FROM Win32_SerialPort");

            var searcher     = new ManagementObjectSearcher(wmiQuery);
            var queryResults = searcher.Get();

            var results = new Collection <SerialPortViewModel>();

            foreach (var serialPort in queryResults)
            {
                var serialPortViewModel = new SerialPortViewModel
                {
                    DeviceId    = serialPort["DeviceID"].ToString(),
                    Description = serialPort["Name"].ToString()
                };

                if (serialPortViewModel.Description.Contains("Arduino Leonardo") ||
                    serialPortViewModel.Description.Contains("Arduino Micro"))
                {
                    serialPortViewModel.DtrEnable = true;
                }
                results.Add(serialPortViewModel);
            }

            return(results.OrderBy(serialPort => serialPort.DeviceId));
        }
        public void Connect(SerialPortViewModel serialPort)
        {
            if (serialPort == null)
            {
                throw new ArgumentNullException("serialPort");
            }

            SerialPort      = serialPort;
            _simulationForm = new SimulatedSerialPortForm
            {
                SerialPortDescription = string.Format("{0} (DtrEnable: {1})", serialPort.DisplayValue, serialPort.DtrEnable)
            };
            _simulationForm.Show();
        }
        public void Connect(SerialPortViewModel serialPort)
        {
            if (serialPort == null)
            {
                throw new ArgumentNullException("serialPort");
            }

            _serialPortViewModel = serialPort;

            _serialPort = new SerialPort(_serialPortViewModel.DeviceId, 9600)
            {
                ReadTimeout = 10,
                DtrEnable   = serialPort.DtrEnable,
                NewLine     = Environment.NewLine
            };
            _serialPort.Open();
        }