public override int ReadByte()
 {
     OnDataRead?.Invoke(this, new DataAccessEventArgs {
         DataRead = 1
     });
     return(base.ReadByte());
 }
Exemple #2
0
        private void startReadingAsync()
        {
            Task.Factory.StartNew(() =>
            {
                using (var pipeCommandStream = new MemoryStream())
                {
                    var buffer = new byte[BufferSize];
                    do
                    {
                        var readLength = pipe.Read(buffer, 0, BufferSize);
                        if (readLength == 0)
                        {
                            if (!pipeClosedByUs)
                            {
                                OnPipeClosed?.Invoke(this, EventArgs.Empty);
                            }
                            return;
                        }

                        pipeCommandStream.Write(buffer, 0, readLength);
                        buffer = new byte[BufferSize];
                    }while (!pipe.IsMessageComplete);

                    var pipeCommandDataArray = pipeCommandStream.ToArray();
                    OnDataRead?.Invoke(this, new PipeEventArgs(pipeCommandDataArray, pipeCommandDataArray.Length));

                    if (pipe != null)
                    {
                        startReadingAsync();
                    }
                }
            });
        }
        public override int Read(byte[] buffer, int offset, int count)
        {
            int dataRead = base.Read(buffer, offset, count);

            OnDataRead?.Invoke(this, new DataAccessEventArgs {
                DataRead = dataRead
            });

            return(dataRead);
        }
        private void DataReceived(object sender, string data)
        {
            Log.Information($"CurrentWeight scale raw data {data}");

            double analyzedData = AnalyzeReceivedScaleData(data);

            if (!double.IsNaN(analyzedData))
            {
                OnDataRead?.Invoke(this, analyzedData);
            }
        }
Exemple #5
0
    public GalaxyData[] Read(OnDataRead onDataRead)
    {
        List <GalaxyData> galaxyData = new List <GalaxyData>();

        bool header       = true;
        int  currentEntry = 0;

        while (!reader.EndOfStream && currentEntry <= galaxyCount)
        {
            currentEntry++;
            string input = reader.ReadLine();

            if (header)
            {
                header  = false;
                headers = Split(input);
            }
            else
            {
                string[]   values = Split(input);
                GalaxyData data   = new GalaxyData();

                for (int i = 0; i < values.Length; i++)
                {
                    float floatValue = 0;

                    bool result = float.TryParse(values[i], out floatValue);

                    if (result)
                    {
                        onDataRead.Invoke(headers[i], floatValue);
                        data.SetData(headers[i], floatValue);
                    }
                }

                galaxyData.Add(data);
            }
        }

        return(galaxyData.ToArray());
    }
Exemple #6
0
 internal void RaiseOnDataRead()
 {
     OnDataRead?.Invoke(this, null);
 }
 private void DataReceived(object sender, string data)
 {
     Log.Information($"Power supply state read to {data} volts");
     OnDataRead?.Invoke(this, data);
 }
 public void HandlePIEHidData(byte[] data, PIEHid32Net.PIEDevice sourceDevice, int error)
 {
     OnDataRead?.Invoke(data, this);
 }