public Graseby9600DataEventArgs(Graseby9600DataEventArgs data)
     : base(null)
 {
     SensorValue = data.SensorValue;
     IsValid     = data.IsValid;
     PortName    = data.PortName;
 }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public override void ReceiveData(object sender, DataTransmissionEventArgs args)
        {
            byte[] buffer = new byte[_detectByteLength];
            lock (m_ReadBuffer)
            {
                m_ReadBuffer.AddRange(args.EventData);
                if (m_ReadBuffer.Count >= _detectByteLength)
                {
                    int headIndex = m_ReadBuffer.FindIndex(0, (x) => { return(x == 0x55); });
                    if (headIndex < 0)
                    {
                        m_ReadBuffer.Clear();
                        return;
                    }
                    else if (headIndex > 0)
                    {
                        m_ReadBuffer.RemoveRange(0, headIndex);
                        return;
                    }
                    else
                    {
                        m_ReadBuffer.CopyTo(0, buffer, 0, _detectByteLength);
                        m_ReadBuffer.RemoveRange(0, _detectByteLength);
                    }
                }
                else
                {
                    return;
                }
            }
            ushort sensorValue = buffer[7];

            sensorValue += (ushort)(buffer[8] << 8);
            byte  decimal_place = buffer[9];
            float fSensorValue  = 0f;

            switch (decimal_place)
            {
            case 0:
                fSensorValue = sensorValue * 1.0f;
                break;

            case 1:
                fSensorValue = sensorValue * 0.1f;
                break;

            case 2:
                fSensorValue = sensorValue * 0.01f;
                break;

            case 3:
                fSensorValue = sensorValue * 0.001f;
                break;

            default:
                fSensorValue = sensorValue * 1.0f;
                break;
            }
            Graseby9600DataEventArgs toolingData = new Graseby9600DataEventArgs(fSensorValue, true);

            base.ReceiveData(sender, toolingData);
        }