From d2e40d6b4990c956d9a598b1f313ac47c141671f Mon Sep 17 00:00:00 2001 From: wangzelong <2692854983@qq.com> Date: 星期一, 24 十月 2022 17:24:23 +0800 Subject: [PATCH] 南通 --- Socket/IStation.DataDockingSocket4NT/helper/HandleDataHelper.cs | 151 +++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 129 insertions(+), 22 deletions(-) diff --git a/Socket/IStation.DataDockingSocket4NT/helper/HandleDataHelper.cs b/Socket/IStation.DataDockingSocket4NT/helper/HandleDataHelper.cs index ffe0d32..712412f 100644 --- a/Socket/IStation.DataDockingSocket4NT/helper/HandleDataHelper.cs +++ b/Socket/IStation.DataDockingSocket4NT/helper/HandleDataHelper.cs @@ -1,5 +1,6 @@ 锘縰sing System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -20,7 +21,7 @@ byte[] byteMessage ) { - + if (byteMessage[2] == 0x32) { return ReadMessage鐩戞帶鍊�(byteMessage); @@ -47,7 +48,7 @@ var iFrequece = (int)(frequece * 10); byte[] commandSend = null; - + IStation.DataDockingSocket.ModBusRtuHelper.BuildSendMessage06(0x01, 20, 2, iFrequece, ref commandSend); return commandSend; @@ -104,7 +105,7 @@ } - + /// <summary> /// 璇诲彇娑堟伅(鐩戞帶鍊�) /// </summary> @@ -112,27 +113,121 @@ private static List<Model.MonitorDataDockingReceiveRecord> ReadMessage鐩戞帶鍊�(byte[] byteMessage) { var list = new List<Model.MonitorDataDockingReceiveRecord>(); - return list; - - try - { - //鏄剧ず娑堟伅 - //string strMessage = BitConverter.ToString(byteMessage, 0, byteMessage.Length); - //DisplayMessage(string.Format(" 鏀跺埌鐨勬秷鎭�: {0} ", strMessage)); - //DisplayMessage(string.Format(" 璁惧鍦板潃: {0} (0x{1})", byteMessage[0], Convert.ToString(byteMessage[0], 16))); - //DisplayMessage(string.Format(" 鍔熻兘鐮�: {0} ", byteMessage[1])); + try + { + //鏄剧ず娑堟伅 + //string strMessage = BitConverter.ToString(byteMessage, 0, byteMessage.Length); + //DisplayMessage(string.Format(" 鏀跺埌鐨勬秷鎭�: {0} ", strMessage)); - byte start = 0x1A; - string msg; + + //DisplayMessage(string.Format(" 璁惧鍦板潃: {0} (0x{1})", byteMessage[0], Convert.ToString(byteMessage[0], 16))); + //DisplayMessage(string.Format(" 鍔熻兘鐮�: {0} ", byteMessage[1])); + + byte start = 0x1A; + string msg; + var now = DateTime.Now; + //褰撳墠绠$綉鍘嬪姏 + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1575030496453332992, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########褰撳墠绠$綉鍘嬪姏 -----> {0} Mpa 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3, out msg), msg) }); + + //鍙橀棰戠巼 + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1575030605857558528, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########鍙橀棰戠巼 -----> {0} Hz 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (27 - start) * 2, out msg) * 0.1, msg) }); + + //鍙橀鐢垫祦 + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301190702632960, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########鍙橀鐢垫祦 -----> {0} A 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (28 - start) * 2, out msg) * 0.1, msg) }); + + //鐪熺┖褰撳墠鍘嬪姏 + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1575030435430404096,RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########鐪熺┖褰撳墠鍘嬪姏 -----> {0} Mpa 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (29 - start) * 2, out msg) * 0.001, msg) }); + + //A鐩哥數鍘� + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301249292865536, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########A鐩哥數鍘� -----> {0} 鏁版嵁浜岃繘鍒秢1} ", GetDouble1(byteMessage, 3 + (30 - start) * 2, out msg), msg) }); + + //B鐩哥數鍘� + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301287175819264, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########B鐩哥數鍘� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetDouble1(byteMessage, 3 + (32 - start) * 2, out msg), msg) }); + + //C鐩哥數鍘� + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301332780486656, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########C鐩哥數鍘� -----> {0} 鏁版嵁浜岃繘鍒秢1} ", GetDouble1(byteMessage, 3 + (34 - start) * 2, out msg), msg) }); + + //A鐩哥數娴� + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301384118767616, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########A鐩哥數娴� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetDouble1(byteMessage, 3 + (36 - start) * 2, out msg), msg) }); + + //B鐩哥數娴� + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301478792597504, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########B鐩哥數娴� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetDouble1(byteMessage, 3 + (38 - start) * 2, out msg), msg) }); + + //C鐩哥數娴� + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301691439616000, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########C鐩哥數娴� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetDouble1(byteMessage, 3 + (40 - start) * 2, out msg), msg) }); + + //鍙橀娉电姸鎬� + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582303421711650816, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########鍙橀娉电姸鎬� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (42 - start) * 2, out msg), msg) }); + + //鐪熺┖娉电姸鎬� + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582303241251721216, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########鐪熺┖娉电姸鎬� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (43 - start) * 2, out msg), msg) }); + + ////鐢靛姩闃�寮�闃�鐘舵�� + //list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301332780486656, RecordType = Model.eMonitorType.General, SrcTime = now, + // SrcValue = string.Format("########鐢靛姩闃�寮�闃�鐘舵�� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (44 - start) * 2, out msg), msg) }); + + ////鐢靛姩闃�鍏抽榾鐘舵�� + //list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301332780486656, RecordType = Model.eMonitorType.General, SrcTime = now, + // SrcValue = string.Format("########鐢靛姩闃�鍏抽榾鐘舵�� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (45 - start) * 2, out msg), msg) }); + + //鐢电闃�鐘舵�� + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582303081771700224, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########鐢电闃�鐘舵�� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (46 - start) * 2, out msg), msg) }); + + //姘翠綅鐘舵�� + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582303471342850048, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########姘翠綅鐘舵�� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (47 - start) * 2, out msg), msg) }); + + //瓒呭帇鐘舵�� + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582303606781120512, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########瓒呭帇鐘舵�� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (48 - start) * 2, out msg), msg) }); + + //鎶ヨ鐘舵�� + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582303637420511232, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########鎶ヨ鐘舵�� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (49 - start) * 2, out msg), msg) }); + + //鍙橀鍣ㄧ姸鎬� + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582303671927050240, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########鍙橀鍣ㄧ姸鎬� -----> {0} 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (50 - start) * 2, out msg), msg) }); + + //褰撳墠娑蹭綅 + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1575388386963886080, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########褰撳墠娑蹭綅 -----> {0} 鏁版嵁浜岃繘鍒秢1} ", GetInt2Byte(byteMessage, 3 + (51 - start) * 2, out msg) * 0.01, msg) }); + + //鐬椂娴侀噺 + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1575030320913321984, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########鐬椂娴侀噺 -----> {0} 鏁版嵁浜岃繘鍒秢1} ", GetInt4Byte(byteMessage, 3 + (52 - start) * 2, out msg) * 0.001, msg) }); + + //绱娴侀噺 + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1584475350807744512, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########绱娴侀噺 -----> {0} 鏁版嵁浜岃繘鍒秢1} ", GetInt4Byte(byteMessage, 3 + (54 - start) * 2, out msg) * 1.0, msg) }); + + //绱娴侀噺鏈夊姛鍔熺巼 + list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1584475756476633088, RecordType = Model.eMonitorType.General, SrcTime = now, + SrcValue = string.Format("########鏈夊姛鍔熺巼 -----> {0} 鏁版嵁浜岃繘鍒秢1} ", GetDouble1(byteMessage, 3 + (56 - start) * 2, out msg), msg) }); //褰撳墠绠$綉鍘嬪姏:26 //3 = 3+(26-26)*2 /* DisplayMessage(string.Format("########褰撳墠绠$綉鍘嬪姏 -----> {0} Mpa 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3, out msg), msg));//0.001Mpa + //鍙橀棰戠巼:27 //5 = 3+(27-26)*2 DisplayMessage(string.Format("########鍙橀棰戠巼 -----> {0} Hz 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (27 - start) * 2, out msg) * 0.1, msg));//0.1HZ + //鍙橀鐢垫祦:28 DisplayMessage(string.Format("########鍙橀鐢垫祦 -----> {0} A 鏁版嵁浜岃繘鍒秢1}", GetInt2Byte(byteMessage, 3 + (28 - start) * 2, out msg) * 0.1, msg));//0.1A //鐪熺┖褰撳墠鍘嬪姏:29 @@ -185,14 +280,16 @@ */ } catch //(Exception err) - { - - return null; - } + { + + return null; } + return list; + } + #region MyRegion - private int GetInt2Byte(byte[] byteMessage, int startPosition, out string info) + private static int GetInt2Byte(byte[] byteMessage, int startPosition, out string info) { byte[] value = new byte[2]; Array.Copy(byteMessage, startPosition, value, 0, 2); @@ -208,7 +305,7 @@ return bytesToInt2(byteMessage, startPosition); } - private int GetInt4Byte(byte[] byteMessage, int startPosition, out string info) + private static int GetInt4Byte(byte[] byteMessage, int startPosition, out string info) { byte[] value = new byte[4]; Array.Copy(byteMessage, startPosition, value, 0, 4); @@ -262,8 +359,18 @@ | ((src[offset + 2] & 0xFF) << 8) | (src[offset + 3] & 0xFF)); return value; - } + } + + private static double GetDouble1(byte[] byteMessage, int startPosition, out string info) + { + byte[] value = new byte[4]; + Array.Copy(byteMessage, startPosition, value, 0, 4); + info = BitConverter.ToString(value, 0, value.Length); + + //return BitConverter.ToDouble(byteMessage, startPosition); + return BitConverter.ToSingle(value.Reverse().ToArray(), 0);//閲囩敤浜咺EEE-754浜岃繘鍒舵诞鐐规暟绠楁湳鏍囧噯 + } #endregion } - + } -- Gitblit v1.9.3