public string UpdateComPorts() { string result = ""; if (_connectedComPort != "") { string[] ports = _ardController.GetSerialPortNames(); bool contain = false; foreach (string item in ports) { if (_connectedComPort == item) { contain = true; break; } } if (!contain) { try { if (!_ardController.CloseComPort()) { _ardController.BefehlReceived -= _ardController_BefehlReceived; _ardController.Dispose(); _ardController = new ArduinoController(); _ardController.BefehlReceived += _ardController_BefehlReceived; } } catch (Exception e) { } result = "ComPort " + _connectedComPort + " getrennt"; } else { if (!_ardController.CloseComPort()) { _ardController.BefehlReceived -= _ardController_BefehlReceived; _ardController.Dispose(); _ardController = new ArduinoController(); _ardController.BefehlReceived += _ardController_BefehlReceived; } if (_ardController.OpenComPort(_connectedComPort, false)) { result = "ComPort " + _connectedComPort + " neu verbunden"; AlleAusgaengeSenden(); _ardController.SendData(new byte[] { 1, 19, 0, 0, 20 }); } else { result = "ComPort " + _connectedComPort + " getrennt"; } } } return(result); }
public bool CloseComPort() { bool result = this._ardController.CloseComPort(); if (!result) { _ardController.BefehlReceived -= _ardController_BefehlReceived; _ardController.Dispose(); _ardController = new ArduinoController(); _ardController.BefehlReceived += _ardController_BefehlReceived; } _connectedComPort = ""; return(true); }