public virtual bool Create(int portNumber, int baudRate = 19200, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One) { string portName = "COM" + portNumber; if (!AvailablePorts.Contains(portName)) { return(false); } _port = new SerialPort { PortName = portName, BaudRate = baudRate, DataBits = dataBits, Parity = parity, StopBits = stopBits, ReadTimeout = 1000, WriteTimeout = 1000, Encoding = Encoding.ASCII }; return(true); }
private void OnRefreshingAvailablePorts() { string selectedPort = SelectedPort; AvailablePorts.Clear(); AvailablePorts.AddCollection(_connectionManager.GetSerialPortNames()); SelectedPort = !AvailablePorts.Contains(selectedPort) ? null : selectedPort; }
public MainVm(IComms session) { _comms = session; _comms.LineOfDataReceived += _session_LineOfDataReceived; MonitorVms = new BindingList <IPresentationModel> { new SensorsVm(), new TransmitterChannelsVm(), new FlightControlPidsVm(), new PositionAltitudePidsVm(), new GpsStatusVm(), //new MotorCommandsVm(session), new SerialMonitorVm(), }; foreach (var vm in MonitorVms) { if (vm is ItalksToApm) { vm.sendTextToApm += MainVm_sendTextToApm; } } ConnectCommand = new DelegateCommand( _ => Connect(), _ => _connectionState == SessionStates.Disconnected && AvailablePorts.Contains(SelectedPort)); DisconnectCommand = new DelegateCommand(_ => Disconnect(), _ => IsConnected); RefreshPortListCommand = new DelegateCommand(_ => RefreshPorts()); RestoreDefaultsCommand = new DelegateCommand(_ => RestoreDefaults(), _ => IsConnected); WriteToEepromCommand = new DelegateCommand(_ => WriteToEeprom(), _ => IsConnected); ConnectionState = SessionStates.Disconnected; AvailablePorts = new BindingList <string>(); AvailableBaudRates = new BindingList <int>() { 115200, 57600, 38400, 9600 }; SelectedBaudRate = 115200; RefreshPorts(); // Initially have selected the last discovered com port. // I think this is more likely to be the correct one, as // the built in comports come first, then the usb/serial // converter ports if (AvailablePorts.Count > 0) { SelectedPort = AvailablePorts[AvailablePorts.Count - 1]; } }
/// <summary> Default constructor. </summary> public ELLDevicesViewModel() { MaxSearchLimit = 'F'; MinSearchLimit = '0'; SelectedPort = CommonUserSettings.ReadUserSetting("DevicePort", "Com1"); ShowTxLoggedCmds = CommonUserSettings.ReadUserSetting("ShowTxOutput", true); ShowRxLoggedCmds = CommonUserSettings.ReadUserSetting("ShowRxOutput", true); ValidAddress = _ellDevice.ValidAddress; AvailablePorts = SerialPort.GetPortNames().ToList(); if (!AvailablePorts.Contains(SelectedPort)) { SelectedPort = AvailablePorts.Count > 0 ? AvailablePorts[0] : ""; } IsConnected = false; _commsLogStore = new List <OutputItem>(); CommsLog = new ObservableCollection <OutputItem>(_commsLogStore); BackgroundThreadManager = new BackgroundThreadManager(); _ellDevice.MessageUpdates.OutputUpdate += OutputUpdate; _ellDevice.MessageUpdates.ParameterUpdate += ParameterUpdate; _sequenceViewModel = new ELLSequenceViewModel(this, _ellDevice); UpdateUI(); }