public async void connect() { if (config.transceiverType == 1) { tciClient?.DisConnectAsync(); tciClient = null; List <SerialDeviceInfo> devices = SerialDevice.SerialDevice.listSerialDevices(); SerialDeviceInfo device = devices.FirstOrDefault(item => item.deviceID == config.serialDeviceId); if (device != null) { string portName = device.portName; serialPort = new SerialPort(portName); try { SerialPortFixer.Execute(portName); serialPort.Open(); initializePort(); } catch (Exception ex) { Logger.Error(ex, "Error opening port " + portName + " " + ex.ToString()); } } else { serialPort = null; } } else if (config.transceiverType == 2) { serialPort?.Close(); try { tciClient = TciClient.Create(config.tciHost, config.tciPort, _cancellationTokenSource.Token); await tciClient.ConnectAsync(); tciTranceiverController = tciClient.TransceiverController; } catch (Exception ex) { Logger.Error(ex, $"Error opening TCI connection to {config.tciHost}:{config.tciPort} {ex.ToString()}"); } } }
private async void ConnectButton_Click(object sender, EventArgs e) { var serverIp = tciServerIP.Text; if ((serverIp != "localhost") && (!IPAddress.TryParse(serverIp, out _))) { MessageBox.Show("Enter a Valid Ipaddress, Refer EESDR -> Options -> TCI Tab"); return; } var serverPort = Convert.ToUInt32(tciServerPort.Text); if (serverPort == 0) { MessageBox.Show("Enter a Valid Port, Refer EESDR -> Options -> TCI Tab"); return; } if (tciClient == null) { tciClient = TciClient.Create(serverIp, serverPort, _cancellationTokenSource.Token); tciClient.OnConnect += TciClient_OnConnect; tciClient.OnDisconnect += TciClient_OnDisconnect; } else { return; } await tciClient.ConnectAsync(); tranceiverController = tciClient.TransceiverController; await dispatcher.InvokeAsync(() => { Drive.Text = $"Drive: {tciClient.TransceiverController.Drive.ToString()}"; DriveControl.Value = (int)tciClient.TransceiverController.Drive; }); await dispatcher.InvokeAsync(() => { Tune.Text = $"Tune: {tciClient.TransceiverController.TuneDrive.ToString()}"; TuneControl.Value = (int)tciClient.TransceiverController.TuneDrive; }); await dispatcher.InvokeAsync(() => { Volume.Text = $"Volume: {tciClient.TransceiverController.Volume.ToString()}"; VolumeControl.Value = tciClient.TransceiverController.Volume; }); tciClient.TransceiverController.OnVolumeChanged += TransceiverController_OnVolumeChanged; await dispatcher.InvokeAsync(() => { foreach (var transceiver in tciClient.TransceiverController.Transceivers) { switch (transceiver.PeriodicNumber) { case 0: Tr1ModulationValue.Text = transceiver.Modulation.ToUpperInvariant(); break; case 1: Tr2ModulationValue.Text = transceiver.Modulation.ToUpperInvariant(); break; default: break; } } }); if (tciClient.TransceiverController.IsStarted()) { await dispatcher.InvokeAsync(() => { StartButton.BackColor = Color.Green; StopButton.BackColor = Color.Red; }); } else { await dispatcher.InvokeAsync(() => { StartButton.BackColor = Color.Red; StopButton.BackColor = Color.Green; }); } tciClient.TransceiverController.OnDrive += TransceiverController_OnDrive; tciClient.TransceiverController.OnTuneDrive += TransceiverController_OnTuneDrive; tciClient.TransceiverController.OnStarted += TransceiverController_OnStarted; tciClient.TransceiverController.OnStopped += TransceiverController_OnStopped; var transceivers = tciClient?.TransceiverController.Transceivers; if (transceivers == null) { return; } foreach (var transceiver in transceivers) { transceiver.OnTrx += TransceiverController_OnTrx; transceiver.OnTune += TransceiverController_OnTune; transceiver.OnModulationChanged += TransceiverController_OnModulationChanged; var channels = transceiver.Channels; switch (transceiver.PeriodicNumber) { case 0: foreach (var channel in channels) { channel.OnVfoChange += TransceiverController_OnVfoChange; switch (channel.PeriodicNumber) { case 0: await dispatcher.InvokeAsync(() => { Receiver1VfoA.Text = channel.Vfo.ToString(); }); break; case 1: await dispatcher.InvokeAsync(() => { Receiver1VfoB.Text = channel.Vfo.ToString(); }); break; default: break; } } break; case 1: foreach (var channel in channels) { channel.OnVfoChange += TransceiverController_OnVfoChange; switch (channel.PeriodicNumber) { case 0: dispatcher.Invoke(() => { Receiver2VfoA.Text = channel.Vfo.ToString(); }); break; case 1: dispatcher.Invoke(() => { Receiver2VfoB.Text = channel.Vfo.ToString(); }); break; default: break; } } break; default: break; } } }