private void CloseActiveConnection() { if (activeConnection == null) { return; } activeConnection.Accepted -= activeConnection_Accepted; activeConnection.Disable(); activeConnection.Dispose(); activeConnection = null; }
public void Enable(byte deviceId) { CloseActiveConnection(); if (config.DeviceId == 0 || config.DeviceId == deviceId) { try { var connection = new SvetovodQualityPanelConnection(config.Port, deviceId); connection.Enable(); connection.Accepted += activeConnection_Accepted; activeConnection = connection; } catch (Exception e) { logger.Error(e); throw; } } }