예제 #1
0
        public async Task <DeviceSample[]> GetSamplesFromDevice(SamplesReadingCallback samplesReadingCallback)
        {
            var result = new List <DeviceSample>();
            await Task.Run(() =>
            {
                WithSerialPort(() =>
                {
                    var details = new DeviceDetails();
                    GetInfoDetails1(details);

                    var data = new DataMessageSample[details.NumberOfSamples];
                    GetData(data, samplesReadingCallback);

                    int sampleNumber = 1;
                    foreach (var sample in data)
                    {
                        result.Add(new DeviceSample
                        {
                            ID          = sampleNumber++,
                            Temperature = Convert.ToDecimal(sample.Temperature) / 10M,
                            TimeStamp   = sample.GetTimeStamp()
                        });
                    }
                });
            });

            return(result.ToArray());
        }
예제 #2
0
        private void GetInfoDetails2(DeviceDetails result)
        {
            logger.Debug($"Sending command 'get info (2)'");
            var question = Messages.GetDataInfo2Message(SerialNumber, x);
            var details2 = Get <AnswerGetInfoDetails2Message>(question);

            result.SampleInterval = details2.SampleInterval;
        }
예제 #3
0
        public DeviceDetails GetDetailsFromDevice()
        {
            var result = new DeviceDetails();

            WithSerialPort(() =>
            {
                GetInfoDetails1(result);
                GetInfoDetails2(result);

                if (SerialNumber != result.SerialNumber)
                {
                    throw new Exception("Received invalid details from device : different serial number");
                }
            });
            return(result);
        }
예제 #4
0
        private void GetInfoDetails1(DeviceDetails result)
        {
            logger.Debug($"Sending command 'get info (1)'");

            var question = Messages.GetDataInfo1Message(SerialNumber, x);
            var details1 = Get <AnswerGetInfoDetails1Message>(question);

            if (!details1.IsValid())
            {
                throw new Exception("Received invalid details from device.");
            }

            result.Description     = Encoding.ASCII.GetString(details1.Description, 0, 16);
            result.SerialNumber    = Encoding.ASCII.GetString(details1.SerialNumber, 0, 10);
            result.Model           = Encoding.ASCII.GetString(details1.Model, 0, 6);
            result.NumberOfSamples = details1.NumberOfSamples;
            result.OffsetCh1       = Convert.ToDecimal(details1.OffsetCh1) / 10M;
            result.OffsetCh2       = Convert.ToDecimal(details1.OffsetCh2) / 10M;
            result.DelayTime       = details1.DelayTime;
        }