public GamePad(OnConnectionChange function) { onConnectionChange += function; controller = new Controller(UserIndex.One); status = Connected; onConnectionChange.Invoke(status); }
public GamePad(OnConnectionChange function) { onConnectionChange += function; controller = new Controller(UserIndex.One); status = Connected; onConnectionChange.Invoke(status); }
public void Shutdown() { try { if (port != null) { var prt = port; port = null; if (prt.IsOpen) { prt.Close(); } prt.Dispose(); } } catch (Exception) { } try { if (!CommsTimeout && _TmrPeriodic != null) { var tmr = _TmrPeriodic; _TmrPeriodic = null; tmr.Dispose(); } } catch (Exception) { } GetSetSuctionPressure(0); ComponentPickedupMinPressure = 0; PressureAtPickup = 0; ConnectionState = "Disconnected"; OnConnectionChange?.Invoke(ConnectionState); }
private void WebSocket_OnClose(object sender, bool e) { isConnectedEvent.Reset(); isDisconnectedEvent.Set(); logger.LogInformation($"WebSocket_OnClose uri:{Uri} Connect Closed!"); OnConnectionChange?.Invoke(this, IsConnected); }
private async Task DoConnect(CancellationToken cancellationToken) { Type prevException = null; isConnectedEvent.Reset(); isDisconnectedEvent.Set(); while (!cancellationToken.IsCancellationRequested && IsRunning) { try { logger.LogDebug($"MqttClientHelper Connecting with ClientId:{Config.ClientId}"); if (string.IsNullOrEmpty(Config.Username)) { Client.Connect(Config.ClientId); } else { Client.Connect(Config.ClientId, Config.Username, Config.Password); } logger.LogInformation($"MqttClientHelper Connected ClientId:{Config.ClientId}"); prevException = null; isConnectedEvent.Set(); isDisconnectedEvent.Reset(); OnConnectionChange?.Invoke(this, IsConnected); // block while is connected isDisconnectedEvent.WaitOne(); } catch (Exception e) { if (cancellationToken.IsCancellationRequested || !IsRunning) { break; } if (e.GetType() != prevException) { prevException = e.GetType(); logger.LogError(e, "MqttClientHelper Connect Error"); logger.LogWarning($"MqttClientHelper ClientId:{Config.ClientId} Connect Failed, retry on {Config.ReconnectDealy / 1000} seconds"); } await Task.Delay(Config.ReconnectDealy, cancellationToken); } finally { isConnectedEvent.Reset(); isDisconnectedEvent.Set(); } } logger.LogInformation($"MqttClientHelper ClientId:{Config.ClientId} Connection Closed!"); OnConnectionChange?.Invoke(this, IsConnected); }
private async Task DoConnect(CancellationToken cancellationToken) { Type prevException = null; IsRunning = true; isConnectedEvent.Reset(); isDisconnectedEvent.Set(); while (!cancellationToken.IsCancellationRequested && IsRunning) { try { logger.LogDebug($"WebSocketClient Connecting with uri:{Uri}"); await client.ConnectAsync(Uri, cancellationToken); logger.LogInformation($"WebSocketClient Connected uri:{Uri}"); prevException = null; isConnectedEvent.Set(); isDisconnectedEvent.Reset(); OnConnectionChange?.Invoke(this, IsConnected); // block while is connected isDisconnectedEvent.WaitOne(); } catch (Exception e) { if (cancellationToken.IsCancellationRequested || !IsRunning) { break; } if (e.GetType() != prevException) { prevException = e.GetType(); logger.LogError(e, "WebSocketClient Connect Error"); logger.LogInformation($"WebSocketClient uri:{Uri} Connect Failed, retry on {ReconnectDelay}."); } await Task.Delay(ReconnectDelay, cancellationToken); } finally { isConnectedEvent.Reset(); isDisconnectedEvent.Set(); } } logger.LogInformation($"WebSocketClient uri:{Uri} Connection Closed!"); OnConnectionChange?.Invoke(this, IsConnected); }
public void Update(GameTime gameTime, GamePadDeadZone deadZoneMode) { _lastGamePadState = _currentGamePadState; _currentGamePadState = GamePad.GetState(PlayerNumber, deadZoneMode); UpdateVibrating(gameTime); CheckGamePadTouched(); if (Connected) { OnConnectionChange?.Invoke(true); } if (Disconnected) { OnConnectionChange?.Invoke(false); } }
public ESuctionSensorState Init() { //Get our settings. if (!PressureSettings.SuctionSensorEnable) { _Main.DisplayText(SuctionSensorNotEnabled); Shutdown(); return(ESuctionSensorState.InitialisedOk); } //Get our serial port. if (string.IsNullOrEmpty(PressureSettings.SuctionSensorPort)) { MessageForUser = SuctionSensorNoPort; _Main.DisplayText(MessageForUser, System.Drawing.KnownColor.Red); return(ESuctionSensorState.RequireOkStopUserConfirmation); } try { //init the port. port = new SerialPort(PressureSettings.SuctionSensorPort); port.BaudRate = 38400; port.StopBits = StopBits.One; port.Parity = Parity.None; port.DataReceived += Port_DataReceived; port.Open(); CommsTimeout = false; ConnectionState = "Connected!"; OnConnectionChange?.Invoke(ConnectionState); } catch (Exception ex) { Shutdown(); MessageForUser = SuctionSensorNoPort + $"Err: {ex.Message}"; _Main.DisplayText(MessageForUser, System.Drawing.KnownColor.Red); return(ESuctionSensorState.RequireOkStopUserConfirmation); } //We might be trying to reconnect after a disconnection. if (_TmrPeriodic == null) { _TmrPeriodic = new Timer(TmrTick, this, TimerTickRate, Timeout.Infinite); } return(ESuctionSensorState.InitialisedOk); }
private void MqttOnConnectionClosed(object sender, EventArgs e) { OnConnectionChange?.Invoke(this, IsConnected()); }
private void OnConnectionClosed(object sender, EventArgs e) { isDisconnectedEvent.Set(); logger.LogInformation($"MqttClientHelper ClientId:{Config.ClientId} Connect Closed!"); OnConnectionChange?.Invoke(this, IsConnected); }