/// <summary> /// Remove emitter instance /// </summary> private void SuppressDevice() { _loraTransceiver.TransceiverDisconnected -= Emitter_DeviceDisconnected; _loraTransceiver = null; _singleton.Reset(); OnDeviceDisconnectedEvent(); }
/// <summary> /// USB Plug/unplug event arrived /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeviceWatcher_EventArrived(object sender, EventArrivedEventArgs e) { if (_timerHelper == null) { _deviceWatcher.Stop(); _timerHelper = new Timer { Interval = 1000 }; _timerHelper.Elapsed += TimerHelper_Elapsed; _timerHelper.Start(); _singleton.Reset(); _loraTransceiver = null; } }
/// <summary> /// Try to connect to device /// </summary> public void DiscoverDevice() { try { Exception ex = null; foreach (string port in SerialPortStream.GetPortNames()) { try { _loraTransceiver = new LoRaCore(port, _softwareConfiguration.TranceiverBaudrate, _softwareConfiguration.TransceiverAddress); if (_loraTransceiver != null) { ex = null; _loraTransceiver.TransceiverDisconnected += Emitter_DeviceDisconnected; OnDeviceConnectedEvent(new ConnectionEventArgs(port)); break; } } catch (Exception e) { ex = e; } } if (ex != null) { throw ex; } } catch (Exception exp) { _loraTransceiver = null; OnDeviceErrorWhenConnecting(new ConnectionErrorEventArgs(exp)); } }