/// <summary> /// Автоматический поиск нужного порта и подключение к ниму. /// </summary> private void AutoFindPort() { foreach (var port in SignalPort.GetListPorts()) { if (SignalView.GSMSignaler.PortDevice) { break; } if (SignalView.GSMSignaler.NotIsNull()) { SignalView.GSMSignaler.Close(); } if (SignalView.GSMSignaler.Init(port)) { SignalView.GSMSignaler.SendTestSignal(); SignalView.GSMSignaler.sPort.OnReceived = (data, objPort, sd) => { if (data.Length > 1) { SetPort(objPort.PortName); comboBoxPorts.GuiAsync(() => { comboBoxPorts.SelectedItem = objPort.PortName; }); SignalView.GSMSignaler.PortDevice = true; return; } }; } Thread.Sleep(1000); } }
private void SetCurrentPorts() { comboBoxPorts.DataSource = null; ComboBox.ObjectCollection itemsPorts = new ComboBox.ObjectCollection(comboBoxPorts); foreach (var port in SignalPort.GetListPorts()) { itemsPorts.Add(port); } comboBoxPorts.DataSource = itemsPorts; comboBoxPorts.DropDownStyle = ComboBoxStyle.DropDownList; }