예제 #1
0
 public void Parse(byte b)
 {
     if (rxBufferPosition == 0)
     {
         if (b == MessageHeader)
         {
             rxBuffer[rxBufferPosition++] = b;
         }
     }
     else
     {
         if (rxBufferPosition == 1 && b == MeasureCommand)
         {
             rxBuffer[rxBufferPosition++] = b;
             isMeasurement = true;
         }
         else
         {
             if (isMeasurement && rxBufferPosition < 9)
             {
                 rxBuffer[rxBufferPosition++] = b;
             }
             else if (rxBufferPosition == 9 && b == MessageTail)
             {
                 rxBuffer[rxBufferPosition] = b;
                 if (VerifyCheckSum())
                 {
                     Task.Factory.StartNew(() =>
                     {
                         var message = new ParticleMassSensorValues
                         {
                             TwoPointFiveMicroMeterValue = (float)(rxBuffer[pm25hb] * 256 + rxBuffer[pm25lb]) / 10,
                             TenMicroMeterValue          = (float)(rxBuffer[pm10hb] * 256 + rxBuffer[pm10lb]) / 10
                         };
                         OnNewMeasurementEvent(message);
                     });
                 }
                 rxBufferPosition = 0;
                 isMeasurement    = false;
             }
         }
     }
 }
예제 #2
0
 protected virtual void OnNewMeasurementEvent(ParticleMassSensorValues obj)
 {
     NewMeasurementEvent?.Invoke(obj);
 }