public async Task Invoke(DataModel model, PipelineDelegate <DataModel> next) { if (model.NetworkTask != null && Math.Abs(model.NetworkTask.Frequency - model.RadioModel.Frequency) < 0.001) { OnDataAvailable?.Invoke(this, new DataEventArgs <NetworkTaskData>(model.NetworkTask)); } await next.Invoke(model); }
private MediaRecorder(IJSRuntime jsRuntime, JsObjectRef jsObjectRef, IMediaStream stream, MediaRecorderOptions options) : base(jsRuntime, jsObjectRef) { AddNativeEventListenerForObjectRef("dataavailable", (s, e) => OnDataAvailable?.Invoke(s, e), BlobEvent.Create); AddNativeEventListenerForObjectRef("error", (s, e) => OnError?.Invoke(s, e), DOMException.Create); AddNativeEventListener("pause", (s, e) => OnPause?.Invoke(s, e)); AddNativeEventListener("resume", (s, e) => OnResume?.Invoke(s, e)); AddNativeEventListener("start", (s, e) => OnStart?.Invoke(s, e)); AddNativeEventListener("stop", (s, e) => OnStop?.Invoke(s, e)); }
private void PerformContinuousReads() { while (IsRunning) { var sensorData = RetrieveSensorData(); if (!IsRunning) { continue; } OnDataAvailable?.Invoke(this, sensorData); Thread.Sleep(200); } }
public Microphone(WaveFormat format, IWaveIn waveIn) { _audioListener = waveIn; _audioListener.WaveFormat = format; _audioListener.DataAvailable += (obj, args) => { var bytes = new byte[args.BytesRecorded]; Array.Copy(args.Buffer, bytes, args.BytesRecorded); OnDataAvailable?.Invoke(this, new ByteDataEventArgs { Data = bytes }); }; }
/// <summary> /// Performs the continuous reads of the sensor. /// This method represents the body of the worker. /// </summary> private void PerformContinuousReads() { var stopwatch = new HighResolutionTimer(); var lastElapsedTime = TimeSpan.FromSeconds(0); while (IsRunning) { try { // Start to comunicate with sensor // Inform sensor that must finish last execution and put it's state in idle DataPin.PinMode = GpioPinDriveMode.Output; // Waiting for sensor init DataPin.Write(GpioPinValue.High); if (lastElapsedTime < ReadInterval) { Thread.Sleep(ReadInterval - lastElapsedTime); } // Start to counter measure time stopwatch.Start(); // Send request to trasmission from board to sensor DataPin.Write(GpioPinValue.Low); Pi.Timing.SleepMicroseconds(1000); DataPin.Write(GpioPinValue.High); Pi.Timing.SleepMicroseconds(20); DataPin.Write(GpioPinValue.Low); // Acquire measure var sensorData = RetrieveSensorData(); OnDataAvailable?.Invoke(this, sensorData); } catch { // swallow } lastElapsedTime = stopwatch.Elapsed; if (stopwatch.IsRunning) { stopwatch.Stop(); } stopwatch.Reset(); } }
private void PerformContinuousReads(object state) { while (IsRunning) { // Acquire measure var sensorData = RetrieveSensorData(); if (IsRunning) { OnDataAvailable?.Invoke(this, sensorData); Thread.Sleep(200); } } Dispose(true); }
private static void EndReceive(IAsyncResult IAsResult) { object[] Objects = IAsResult.AsyncState as object[]; Socket TcpSocket = Objects[1] as Socket; byte[] Bytes = Objects[0] as byte[]; if (Convert.ToInt32(Bytes.GetValue(0)) <= 0) { return; } try { TcpSocket.EndReceive(IAsResult); BeginReceive(TcpSocket); } catch (Exception ex) { Trace("EndReceive:" + ex.Message, TcpSocket); return; } if (OnDataAvailable != null) { OnDataAvailable.Invoke(TcpSocket, Bytes); } }
/// <summary> /// Performs the continuous reads of the sensor. /// This method represents the body of the worker. /// </summary> private void PerformContinuousReads(object state) { if (!IsRunning) { return; } try { // Acquire measure var sensorData = RetrieveSensorData(); if (IsRunning) { OnDataAvailable?.Invoke(this, sensorData); _readTimer.Change(_period, Timeout.Infinite); } } catch { // swallow } }
/// <summary> /// Performs the continuous reads of the sensor. /// This method represents the body of the worker. /// </summary> private void PerformContinuousReads() { while (_isRunning) { try { // Start to comunicate with sensor // Inform sensor that must finish last execution and put it's state in idle DataPin.PinMode = GpioPinDriveMode.Output; // Send request to trasmission from board to sensor DataPin.Write(GpioPinValue.Low); _systemTiming.SleepMicroseconds(5000); DataPin.Write(GpioPinValue.High); _systemTiming.SleepMicroseconds(30); DataPin.Write(GpioPinValue.Low); // Acquire measure var sensorData = RetrieveSensorData(); if (sensorData != null) { OnDataAvailable?.Invoke(this, sensorData); } DataPin.PinMode = GpioPinDriveMode.Output; DataPin.Write(GpioPinValue.High); } catch (Exception ex) { ex.Error(nameof(TemperatureSensorAM2302), ex.Message); } // Waiting for sensor init Thread.Sleep(ReadInterval); } }