/// <summary> /// 仅适用于分站的电源箱解码 /// <param name="data">传入回发的Buffer</param> /// <param name="protocol">回发的对象</param> /// <param name="startIndex">分站号的索引位置</param> /// <param name="deviceCommunicationType">分站的类型</param> /// <param name="point">分站的测点号</param> /// </summary> public void HandleBatteryRealData(byte[] data, MasProtocol protocol, ushort startIndex, byte deviceCommunicationType, string point) { QueryBatteryRealDataResponse realData = new QueryBatteryRealDataResponse(); BatteryRealDataItem BatteryItem = new BatteryRealDataItem(); protocol.ProtocolType = ProtocolType.QueryBatteryRealDataResponse; realData.BatteryDateTime = DateTime.Now; realData.DeviceCode = point; realData.BatteryRealDataItems = new List <BatteryRealDataItem>(); BatteryItem.DeviceProperty = ItemDevProperty.Substation; Cache.HandleDeviceBattery(data, (byte)(startIndex + 5), BatteryItem);//解析电源箱的数据 111 realData.BatteryRealDataItems.Add(BatteryItem); protocol.Protocol = realData; }
/// <summary> /// 表示交换机电源的确认 /// </summary> /// <param name="net"></param> /// <param name="data"></param> private void SendBatteryAffirmToCenter(NetworkDeviceInfo net, byte[] data) { //7F-03-2A-00-00-01-8A-01-8A-01-8A-01-8A-01-8A-01-8A-00-00-00-00-09-41-00-40-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-E8-07 ProtocolDataCreatedEventArgs upData = new ProtocolDataCreatedEventArgs(); QueryBatteryRealDataResponse cData = new QueryBatteryRealDataResponse();//获取交换机电源箱的应答数据; //需要反过来找一下,串口服务器对应的交换机IP地址。 upData.DeviceCode = net.IP; upData.DriverCode = this.DriverCode; upData.MasProtocol = new MasProtocol(SystemType.Security, DirectionType.Up, ProtocolType.QueryBatteryRealDataResponse); cData.DeviceCode = net.IP; cData.DeviceProperty = ItemDevProperty.Switches; cData.BatteryRealDataItems = new List <BatteryRealDataItem>(); BatteryRealDataItem BatteryItem = new BatteryRealDataItem(); cData.BatteryDateTime = DateTime.Now; Cache.HandleDeviceBattery(data, 5, BatteryItem, true);//解析电源箱的数据 cData.BatteryRealDataItems.Add(BatteryItem); upData.MasProtocol.Protocol = cData; OnProtocolData(upData); }
/// <summary> /// 处理交换机以及分站的电源箱回发的数据,通用函数 /// </summary> /// <param name="data"></param> /// <param name="startIndex">表示电源箱的地址号</param> /// <param name="batteryItem"></param> public static void HandleDeviceBattery(byte[] data, byte startIndex, BatteryRealDataItem batteryItem, bool switchType = false) { ushort tempValue = 6; batteryItem.BatteryVOL = new float[6]; batteryItem.Address = "0"; if (switchType) { batteryItem.Channel = "250"; } else { batteryItem.Channel = data[startIndex++].ToString(); } for (int i = 0; i < tempValue; i++) { if (switchType) { batteryItem.BatteryVOL[i] = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, true) / 100.0); } else { batteryItem.BatteryVOL[i] = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, false) / 100.0); } startIndex += 2; } if (switchType) { batteryItem.DeviceTemperature1 = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, true) / 100.0); } else { batteryItem.DeviceTemperature1 = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, false) / 100.0); } startIndex += 2; batteryItem.DeviceTemperature1 += 17.0f; if (switchType) { batteryItem.DeviceTemperature2 = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, true) / 100.0); } else { batteryItem.DeviceTemperature2 = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, false) / 100.0); } batteryItem.DeviceTemperature2 += 17.0f; startIndex += 2; if (switchType) { batteryItem.TotalVoltage = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, true) / 100.0); } else { batteryItem.TotalVoltage = (float)(CommandUtil.ConvertByteToInt16(data, startIndex, false) / 100.0); } startIndex += 2; if (switchType) { if ((data[startIndex + 1] & 0x01) == 0) { batteryItem.BatteryACDC = 1;//交直流状态 (0 断线,1交流、2直流) } else { batteryItem.BatteryACDC = 2;//交直流状态 (0 断线,1交流、2直流) } } else { if (data[startIndex] == 0) { batteryItem.BatteryACDC = 1;//交直流状态 (0 断线,1交流、2直流) } else { batteryItem.BatteryACDC = 2;//交直流状态 (0 断线,1交流、2直流) } } }