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; } } }
private static void Main(string[] args) { var exitEvent = new ManualResetEvent(false); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); Console.CancelKeyPress += (sender, eventArgs) => { eventArgs.Cancel = true; exitEvent.Set(); }; Timer timer = new Timer(60000); timer.Elapsed += Timer_Elapsed; timer.Start(); try { tciClient = TciClient.Create("localhost", 40001, cancellationTokenSource.Token); tciClient.ConnectAsync().Wait(cancellationTokenSource.Token); //tciClient.TransceiverController.OnVfoChange += TransceiverController_OnVfoChange; tciClient.TransceiverController.OnAudioStartChanged += TransceiverController_OnAudioStartChanged; tciClient.TransceiverController.OnDrive += TransceiverController_OnDrive; tciClient.TransceiverController.OnTuneDrive += TransceiverController_OnTuneDrive; //tciClient.TransceiverController.OnIfFreqChanged += TransceiverController_OnIfFreqChanged; tciClient.TransceiverController.OnIfLimitsChanged += TransceiverController_OnIfLimitsChanged; tciClient.TransceiverController.OnModulationChanged += TransceiverController_OnModulationChanged; tciClient.TransceiverController.OnSplitEnableChanged += TransceiverController_OnSplitEnableChanged; tciClient.TransceiverController.OnTrx += TransceiverController_OnTrx; tciClient.TransceiverController.OnTune += TransceiverController_OnTune; tciClient.TransceiverController.OnVolumeChanged += TransceiverController_OnVolumeChanged; tciClient.TransceiverController.OnXitEnableChanged += TransceiverController_OnXitEnableChanged; tciClient.TransceiverController.OnXitOffsetChanged += TransceiverController_OnXitOffsetChanged; tciClient.TransceiverController.OnRitEnableChanged += TransceiverController_OnRitEnableChanged; tciClient.TransceiverController.OnRitOffsetChanged += TransceiverController_OnRitOffsetChanged; tciClient.TransceiverController.OnMute += TransceiverController_OnMute; //tciClient.TransceiverController.OnChannelSMeterChanged += TransceiverController_OnChannelSMeterChanged; tciClient.TransceiverController.OnRxFilterChanged += TransceiverController_OnRxFilterChanged; tciClient.TransceiverController.OnRxMute += TransceiverController_OnRxMute; tciClient.TransceiverController.Start(); tciClient.TransceiverController.Vfo(0, 0, 7154400); } catch (Exception exception) { Console.WriteLine($"Message: {exception.Message} /n StackTrace {exception.StackTrace}"); } exitEvent.WaitOne(); if (tciClient != null) { tciClient.TransceiverController.Stop(); // tciClient.TransceiverController.OnVfoChange -= TransceiverController_OnVfoChange; tciClient.TransceiverController.OnAudioStartChanged -= TransceiverController_OnAudioStartChanged; tciClient.TransceiverController.OnDrive -= TransceiverController_OnDrive; tciClient.TransceiverController.OnTuneDrive -= TransceiverController_OnTuneDrive; //tciClient.TransceiverController.OnIfFreqChanged -= TransceiverController_OnIfFreqChanged; tciClient.TransceiverController.OnIfLimitsChanged -= TransceiverController_OnIfLimitsChanged; tciClient.TransceiverController.OnModulationChanged -= TransceiverController_OnModulationChanged; tciClient.TransceiverController.OnSplitEnableChanged -= TransceiverController_OnSplitEnableChanged; tciClient.TransceiverController.OnTrx -= TransceiverController_OnTrx; tciClient.TransceiverController.OnTune -= TransceiverController_OnTune; tciClient.TransceiverController.OnVolumeChanged -= TransceiverController_OnVolumeChanged; tciClient.TransceiverController.OnXitEnableChanged -= TransceiverController_OnXitEnableChanged; tciClient.TransceiverController.OnXitOffsetChanged -= TransceiverController_OnXitOffsetChanged; tciClient.TransceiverController.OnRitEnableChanged -= TransceiverController_OnRitEnableChanged; tciClient.TransceiverController.OnRitOffsetChanged -= TransceiverController_OnRitOffsetChanged; tciClient.TransceiverController.OnMute -= TransceiverController_OnMute; //tciClient.TransceiverController.OnChannelSMeterChanged -= TransceiverController_OnChannelSMeterChanged; tciClient.TransceiverController.OnRxFilterChanged -= TransceiverController_OnRxFilterChanged; tciClient.TransceiverController.OnRxMute -= TransceiverController_OnRxMute; tciClient.DisConnectAsync().Wait(cancellationTokenSource.Token); } timer.Dispose(); cancellationTokenSource.Cancel(); }