private void KickDevice() { if (master.IsOpen) { try { master.Execute(kickWatchdog); if (wdCounter > kickWatchdog.Counter) { wdCounter = kickWatchdog.Counter; Log.Error("The CPAR device has experienced a malfunction and has restarted. Please check the device for abnormal behaviour before continuing with its use"); } commAttemptCount = 0; } catch { } } else { if (Connected) { Log.Debug("DEVICE DISCONNECTED"); Connected = false; wdCounter = 0; DeviceStateChanged?.Invoke(this, Connected); } } }
public override void ResponseReceived(byte[] parameter) { switch ((DeviceManagerCommunication)parameter[0]) { case DeviceManagerCommunication.ResponseDevices: var devices = new Serializer(typeof(List <DeviceInfo>)).Deserialize <List <DeviceInfo> >(parameter, 1); foreach (var deviceInfo in devices) { deviceInfo.DriverBuildDate = deviceInfo.DriverBuildDate.ToLocalTime(); deviceInfo.DriverInstallDate = deviceInfo.DriverInstallDate.ToLocalTime(); } LogService.Receive(string.Format((string)Application.Current.Resources["DevicesReceived"], devices.Count)); DevicesReceived?.Invoke(this, devices); break; case DeviceManagerCommunication.DeviceStateChangedSuccessfully: var enabled = parameter[1] == 1; var hardwareId = Encoding.UTF8.GetString(parameter, 2, parameter.Length - 2); LogService.Receive((string)Application.Current.Resources["DeviceStateChangedSuccessfully"]); DeviceStateChanged?.Invoke(this, new DeviceChangedEventArgs(hardwareId, enabled)); break; case DeviceManagerCommunication.ErrorChangingDeviceState: LogService.Error(string.Format((string)Application.Current.Resources["ErrorChangeDeviceState"], Encoding.UTF8.GetString(parameter, 1, parameter.Length - 1))); break; case DeviceManagerCommunication.ErrorDeviceNotFound: LogService.Error((string)Application.Current.Resources["ErrorDeviceNotFound"]); break; } }
/// <summary> /// New devices found. /// </summary> private void CallBack(List <AndroidDevice> list) { lock (devicesLock) { // Look for removed devices var removed = devices.Where(x => list.All(y => y.Serial != x.Serial)).ToList(); foreach (var device in removed) { devices.Remove(device); DeviceRemoved.Fire(this, new EventArgs <AndroidDevice>(device)); } // Look for added or changed devices foreach (var device in list) { var serial = device.Serial; var existing = devices.FirstOrDefault(x => x.Serial == serial); if (existing == null) { // Device added devices.Add(device); DeviceAdded.Fire(this, new EventArgs <AndroidDevice>(device)); } else if (existing.DeviceState != device.DeviceState) { // State changed devices.Remove(existing); devices.Add(device); DeviceStateChanged.Fire(this, new EventArgs <AndroidDevice>(device)); } } receivedInitialUpdate = true; Monitor.PulseAll(devicesLock); } }
private void OnDeviceStateChanged(DeviceStateChanged msg) { _deviceStateDto = msg.DeviceStateDto; _deviceState = msg.DeviceStateDto.CurrentState; _deviceStateEventTimeStamp = msg.DeviceStateDto.TimeStamp; _deviceStateProcessedTimeStamp = DateTime.UtcNow; }
private static void PrivateDeviceStateChanged(IntPtr device, DeviceState state) { DeviceStateChanged ev = OnDeviceStateChanged; if (ev != null) { ev(new DeviceInfo(device), state); } }
protected async Task SetStateAsync(DeviceState newState, bool isError) { await _uiThreadService.RunOnMainThread(() => { var oldState = DeviceState; DeviceState = newState; DeviceStateChanged?.Invoke(this, new DeviceStateChangedEventArgs(oldState, newState, isError)); }); }
Task OnDeviceStateChanged(RemoteConnection_DeviceStateChangedMessage msg) { if (IsMessageFromCurrentDevice(msg)) { DeviceStateChanged?.Invoke(this, msg.State.ToDeviceState()); } return(Task.CompletedTask); }
public void SetConnectionState(DeviceState state) { if (state == DeviceState.ConnectionAttempt) { awaitingDeviceConfirmation = 1; } DeviceConnectionState = state; DeviceStateChanged?.Invoke(DeviceConnectionState); }
private void Device_StateChanged(IObservableDevice device, DeviceState state) { _logger.Info(device.DeviceType.Code + " " + state); DeviceStatus status; if (_context.TryUpdateDevice(device.DeviceType, state, out status)) { DeviceStateChanged?.Invoke(this, status); } }
/// <summary> /// A device has a state change. /// </summary> void OnDeviceStateChanged(object sender, EventArgs <AndroidDevice> e) { if (InvokeRequired) { Invoke(new EventHandler <EventArgs <AndroidDevice> >(OnDeviceStateChanged), sender, e); } else { RemoveItemsBySerial(e.Data.Serial); var item = new AndroidDeviceItem(e.Data); tvList.Items.Add(item); SetIsCompatible(item); ReloadList(); UpdateNoDevicesItem(); DeviceStateChanged.Fire(this, e); } }
public NotificationsHub(NavigationManager navigationManager) { _connection = new HubConnectionBuilder().WithUrl(navigationManager.ToAbsoluteUri("api/NotificationsHub")).WithAutomaticReconnect(new HubReconnectPolicy()).Build(); _connection.StartAsync(); _connection.On("DeviceStateChanged", (string deviceId) => { DeviceStateChanged?.Invoke(deviceId); }); _connection.On("DevicePropertyChanged", (string propertyPath) => { DevicePropertyChanged?.Invoke(propertyPath); }); _connection.On("DashboardConfigurationChanged", () => { DashboardConfigurationChanged?.Invoke(); }); }
private async void StateChangedTimer_Elapsed(object sender, ElapsedEventArgs e) { var result = await baseClient.GetSystemParameterListAsync(new byte[] { 0, 1, 2, 3, 4, 5, 6, 9 }); var deviceStateChangedEventArgs = new DeviceStateChangedEventArgs() { IsUserSitting = result.DataArray[0] != 0, IsAnalShowerRunning = result.DataArray[1] != 0, IsLadyShowerRunning = result.DataArray[2] != 0, IsDryerRunning = result.DataArray[3] != 0, //DescalingState = Deserializer.DeserializeToInt(result.DataArray, 4 * 5 + 1, 4), //DescalingDurationInMinutes = Deserializer.DeserializeToInt(result.DataArray, 5 * 5 + 1, 4), //LastErrorCode = Deserializer.DeserializeToInt(result.DataArray, 6 * 5 + 1, 4), //OrientationLightState = Deserializer.DeserializeToInt(result.DataArray, 7 * 5 + 1, 4), }; if (lastDeviceStateChangedEventArgs == null) { // Invoke event for initial state of the device DeviceStateChanged?.Invoke(this, deviceStateChangedEventArgs); } else { // Only invoke event if something changed if (!deviceStateChangedEventArgs.Equals(lastDeviceStateChangedEventArgs)) { var dsc = deviceStateChangedEventArgs; var ldsc = lastDeviceStateChangedEventArgs; DeviceStateChanged?.Invoke(this, new DeviceStateChangedEventArgs() { IsUserSitting = dsc.IsUserSitting != ldsc.IsUserSitting ? dsc.IsUserSitting : null, IsAnalShowerRunning = dsc.IsAnalShowerRunning != ldsc.IsAnalShowerRunning ? dsc.IsAnalShowerRunning : null, IsLadyShowerRunning = dsc.IsLadyShowerRunning != ldsc.IsLadyShowerRunning ? dsc.IsLadyShowerRunning : null, IsDryerRunning = dsc.IsDryerRunning != ldsc.IsDryerRunning ? dsc.IsDryerRunning : null, }); } } lastDeviceStateChangedEventArgs = deviceStateChangedEventArgs; }
private void ScanPort() { try { if (!initComm) { Log.Debug("Opening port: {0}", PortName); master.Open(PortName); initComm = true; if (!master.IsOpen) { throw new ArgumentException("port is not open"); } } else { Log.Debug("Scanning port: {0}", PortName); master.Execute(devIdentification); Connected = true; initComm = false; Log.Debug("Connected to port {0}", PortName); DeviceStateChanged?.Invoke(this, Connected); } } catch (Exception e) { ++commAttemptCount; Log.Debug("SCANPORT FAILED: {0}", e.Message); initComm = false; if (master.IsOpen) { master.Close(); } } }
public void OnDeviceStateChanged(string deviceId, DeviceState newState) => DeviceStateChanged?.Invoke(this, new DeviceStateChangedEventArgs(deviceId, newState));
// Generate an Event from the v.StateChanged Action public void StateChanged() => DeviceStateChanged?.Invoke(this, null);
void IMMNotificationClient.OnDeviceStateChanged(string deviceId, DeviceState newState) { DeviceStateChanged?.Invoke(this, new DeviceStateChangedEventArgs(deviceId, newState)); }
/// <summary> /// The OnDeviceStateChanged method indicates that the state of an audio endpoint device has /// changed. /// </summary> /// <param name="deviceId">The device id that identifies the audio endpoint device.</param> /// <param name="deviceState">Specifies the new state of the endpoint device.</param> /// <returns>HRESULT</returns> void IMMNotificationClient.OnDeviceStateChanged(string deviceId, DeviceState deviceState) { DeviceStateChanged?.Invoke(this, new DeviceStateChangedEventArgs(deviceId, deviceState)); //return (int) HResult.S_OK; }
public void TriggerDeviceStateChanged(bool inRange) { DeviceStateChanged?.Invoke(this, new DeviceStateEventArgs { InRange = inRange }); }
protected void OnDeviceStateChanged(byte state) { DeviceStateChanged.Raise(this, new EventArgs <byte> { Value = state }); }