/// 处理状态数据包 public static void ProcessWorkGraphStatusPackage(byte[] data) { try { var iotDataWorkGraphStatus = new IotDataWorkGraphStatus { DateTime = DateTime.Now, WellId = 0, ModbusAddress = (byte)BytesConvertHelper.ConvertByteArrayToInt8(data, 0), BatteryVoltage = BytesConvertHelper.ConvertByteArrayToInt16(data, 11) / 1000.0, WellStatus = BytesConvertHelper.ConvertByteArrayToInt16(data, 13), Temperature = BytesConvertHelper.ConvertByteArrayToInt16(data, 15) / 100.0, Humidity = BytesConvertHelper.ConvertByteArrayToInt16(data, 17) / 100.0, Stroke = BytesConvertHelper.ConvertByteArrayToInt16(data, 19) / 100.0, Displacement = BytesConvertHelper.ConvertByteArrayToInt16(data, 21) / 100.0 }; var connectionFactory = HostContext.TryResolve <IDbConnectionFactory>(); var dbFac = connectionFactory.OpenDbConnection(); var list = dbFac.Select <IotOilWell>(x => x.ModbusAddress == data[0]); if (!list.IsEmpty()) { iotDataWorkGraphStatus.WellId = list[0].WellId; DataWriter.WorkGraphStatusQueue.Enqueue(iotDataWorkGraphStatus); } Logger.Info(iotDataWorkGraphStatus.Dump()); } catch (Exception e) { Console.WriteLine(e); throw; } }
//处理功图包 public static void ProcessWorkGraphPackage(byte[] data) { try { var iotDataOilWellIndicatorDiagram = new IotDataOilWellIndicatorDiagram { DateTime = DateTime.Now, Count = (int?)BytesConvertHelper.ConvertByteArrayToInt8(data, 8), Interval = BytesConvertHelper.ConvertByteArrayToInt16(data, 9) / 100.0, D = new List <double>(), L = new List <double>() }; var count = (int)iotDataOilWellIndicatorDiagram.Count; var deviceId = (byte)1; var offset = (ushort)((deviceId - 1) * 550); MyModbusServer.Server.SetHoldingRegister(deviceId, (ushort)(31550 + offset + 3), (ushort)count); MyModbusServer.Server.SetHoldingRegister(deviceId, (ushort)(31550 + offset + 4), (ushort)(iotDataOilWellIndicatorDiagram.Interval * 100)); for (var i = 0; i < count; i++) { iotDataOilWellIndicatorDiagram.L.Add(BytesConvertHelper.ConvertByteArrayToInt16(data, 11 + 2 * i)); MyModbusServer.Server.SetHoldingRegister(deviceId, (ushort)(31550 + offset + i), (ushort)(iotDataOilWellIndicatorDiagram.Interval * 100)); } for (var i = 0; i < count; i++) { iotDataOilWellIndicatorDiagram.D.Add(BytesConvertHelper.ConvertByteArrayToInt16(data, 11 + 2 * count + 2 * i)); MyModbusServer.Server.SetHoldingRegister(deviceId, (ushort)(31550 + offset + 262 + i), (ushort)(iotDataOilWellIndicatorDiagram.Interval * 100)); } var connectionFactory = HostContext.TryResolve <IDbConnectionFactory>(); var dbFac = connectionFactory.OpenDbConnection(); var list = dbFac.Select <IotOilWell>(x => x.ModbusAddress == data[0]); if (!list.IsEmpty()) { iotDataOilWellIndicatorDiagram.WellId = list[0].WellId; DataWriter.WorkGraphDataQueue.Enqueue(iotDataOilWellIndicatorDiagram); } Logger.Info(iotDataOilWellIndicatorDiagram.Dump()); } catch (Exception e) { Console.WriteLine(e); throw; } }