public PToolingDataEventArgs(PToolingDataEventArgs data) : base(null) { Weight = data.Weight; IsValid = data.IsValid; PortName = data.PortName; }
/// <summary> /// 只能用于检测串口,收到串口设备数据包 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public override void OnDetectDataReceived(object sender, DataTransmissionEventArgs args) { byte[] buffer = new byte[_detectByteLength]; lock (m_ReadBuffer) { m_ReadBuffer.AddRange(args.EventData); if (m_ReadBuffer.Count >= _detectByteLength) { int endIndex = m_ReadBuffer.FindIndex(0, (x) => { return(x == 0x0D); }); if (endIndex < 0) { return; } else if (endIndex > 0 && endIndex != _detectByteLength - 1) { m_ReadBuffer.RemoveRange(0, endIndex + 1); return; } else { m_ReadBuffer.CopyTo(0, buffer, 0, _detectByteLength); m_ReadBuffer.RemoveRange(0, _detectByteLength); } } else { return; } } int weight = 0; for (int iLoop = 7; iLoop >= 3; iLoop--) { weight += (buffer[iLoop] - 0x30) << (iLoop - 3) * 4; } int decimal_place = buffer[8] & 0x03; float fweightKiloGrams = 0f; switch (decimal_place) { case 0: fweightKiloGrams = weight * 1.0f; break; case 1: fweightKiloGrams = weight * 0.1f; break; case 2: fweightKiloGrams = weight * 0.01f; break; case 3: fweightKiloGrams = weight * 0.001f; break; default: fweightKiloGrams = weight * 1.0f; break; } PToolingDataEventArgs toolingData = new PToolingDataEventArgs(fweightKiloGrams, true); base.OnDetectDataReceived(sender, toolingData); }