Socket/IStation.DataDockingSocket4NT/HandleHelper.cs
ÎļþÒÑɾ³ý Socket/IStation.DataDockingSocket4NT/Log/LogHelper.cs
@@ -24,16 +24,26 @@ var json = JsonHelper.Object2Json(rece_list); LogHelper.Custom(_logNameDebug, json); } public static void Debug(string msg) { LogHelper.Custom(_logNameDebug, msg); } private const string _logNameSrc = "socket-nt-src"; /// <summary> /// çæ /// </summary> public static void Src(byte[] bts) { if (!AppParasHelper.IsSrc()) return; if (bts == null || bts.Count() < 1) return; var message_bts = BitTransfer.ToString(bts); LogHelper.Custom(_logNameSrc, message_bts); } Socket/IStation.DataDockingSocket4NT/MsgHandle/BseMsgHelper.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,129 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.DataDockingSocket { internal class ByteMsgHelper { /// <summary> /// å符串转16è¿å¶å符2 /// </summary> /// <param name="content">å符串</param> /// <param name="encode">ç¼ç æ ¼å¼</param> /// <returns></returns> public static List<byte> StringToHexValuve(string content, out string error_info) { //å»æç©ºæ ¼ string[] arr = content.Split(' '); if (arr.Length < 3) { arr = content.Split('-'); if (arr.Length < 3) { error_info = "åç¬¦æ æ³è§£æ"; return null; } } List<byte> result = new List<byte>(); for (int i = 0; i < arr.Length; i++) { if (string.IsNullOrWhiteSpace(arr[i])) continue; var dddd = Convert.ToByte(arr[i], 16); result.Add(dddd); } error_info = null; return result; } #region æ°æ®è½¬å public static int GetInt2Byte(byte[] byteMessage, int startPosition, out string info) { byte[] value = new byte[2]; Array.Copy(byteMessage, startPosition, value, 0, 2); info = BitConverter.ToString(value, 0, value.Length); // ushort rValueP = BitConverter.ToUInt16(value.Reverse().ToArray(), 0); //short rValueP = 0; //rValueP = byteMessage[ startPosition]; //rValueP <<= 8; //rValueP += byteMessage[ startPosition + 1]; //return rValueP; return bytesToInt2(byteMessage, startPosition); } public static int GetInt4Byte(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); // ushort rValueP = BitConverter.ToUInt16(value.Reverse().ToArray(), 0); //short rValueP = 0; //rValueP = byteMessage[ startPosition]; //rValueP <<= 8; //rValueP += byteMessage[ startPosition + 1]; //return rValueP; return bytesToInt4(byteMessage, startPosition); } /** * byteæ°ç»ä¸åintæ°å¼ï¼æ¬æ¹æ³éç¨äº(ä½ä½å¨åï¼é«ä½å¨å)ç顺åºï¼ååintToBytesï¼ï¼é å¥ä½¿ç¨ * * @param src * byteæ°ç» * @param offset * 仿°ç»ç第offsetä½å¼å§ * @return intæ°å¼ */ public static int bytesToInt2_LH(byte[] src, int offset) { int value; value = src[offset] & 0xFF | (src[offset + 1] & 0xFF) << 8; return value; } /** * byteæ°ç»ä¸åintæ°å¼ï¼æ¬æ¹æ³éç¨äº(ä½ä½å¨åï¼é«ä½å¨å)ç顺åºã2个åè */ public static int bytesToInt2(byte[] src, int offset) { int value; value = (src[offset + 0] & 0xFF) << 8 | src[offset + 1] & 0xFF; return value; } /** * byteæ°ç»ä¸åintæ°å¼ï¼æ¬æ¹æ³éç¨äº(ä½ä½å¨åï¼é«ä½å¨å)ç顺åºã4个åè */ public static int bytesToInt4(byte[] src, int offset = 0) { int value; value = (src[offset] & 0xFF) << 24 | (src[offset + 1] & 0xFF) << 16 | (src[offset + 2] & 0xFF) << 8 | src[offset + 3] & 0xFF; return value; } public 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);//éç¨äºIEEE-754äºè¿å¶æµ®ç¹æ°ç®æ¯æ å } #endregion } } Socket/IStation.DataDockingSocket4NT/MsgHandle/HandleHelper.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,112 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using IStation.Model; using IStation.Untity; namespace IStation.DataDockingSocket.MsgHandle { public class HandleHelper : IDataDockingSocket.IHandleHelper { /// <summary> /// å¤ç注åç /// </summary> public void HandleRegisterCode(IMonitorDataDockingSession session) { if (session == null) return; if (!session.IsConnected) return; if (SessionHelper.Cache != null) { if (SessionHelper.Cache != session) { if (SessionHelper.Cache.IsConnected) { SessionHelper.Cache.Close($"{session.SessionName} ä¸ï¼äº§çæ°çä¼è¯ï¼"); } } } SessionHelper.Cache = session; foreach (var item in MonitorMsgHelper.GetInstructionQuerys()) { SendInstructionJobHelper.StartJob(session, item); if (item.SpaceTime >= 1) Thread.Sleep(item.SpaceTime * 1000); } SendControlJobHelper.StartJob(session); } /// <summary> /// å¤çå¿è·³å /// </summary> public void HandleHeartbeat(IMonitorDataDockingSession session) { } /// <summary> /// å¤çæ°æ® /// </summary> public void HandleData ( IMonitorDataDockingSession session, byte[] byteMessage, List<DataDockingConfigure.Mapper> mappers, Action<List<MonitorDataDockingReceiveRecord>> onReceive ) { if (session == null) return; if (!session.IsConnected) return; if (byteMessage == null || byteMessage.Length < 4) { return; } if (MonitorMsgHelper.IsCurrentMsg(byteMessage)) { var receList = MonitorMsgHelper.HandleReceive(byteMessage); if (receList == null || receList.Count == 0) return; NtLogHelper.Src(byteMessage); // NtLogHelper.Debug(src_list); //NtLogHelper.Info($"è§£ææ°æ®æ°é:{receList.Count}\n\r" + // $"{JsonHelper.Object2Json(receList)}"); onReceive(receList); return;//æåå°±è¿åæ } //ä¸è¦å else if (ShunDownMsgHelper.InstructionStatus == eShutDownInstructionStatus.å ³æºæºæä»¤åé) { ShunDownMsgHelper.HandleReceive(session,byteMessage); } //ä¸è¦å else if (StartUpMsgHelper.IsCurrentMsg(byteMessage)) { } } } } Socket/IStation.DataDockingSocket4NT/MsgHandle/MonitorMsgHelper.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,367 @@ using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; using System.Threading.Tasks; using IStation.Untity; namespace IStation.DataDockingSocket.MsgHandle { /// <summary> /// å¤çæ°æ®è¾ å©ç±» /// </summary> internal class MonitorMsgHelper { /// <summary> /// æ¯å¦æ¯å½åMSG /// </summary> /// <param name="byteMessage"></param> /// <returns></returns> public static bool IsCurrentMsg(byte[] byteMessage) { if (byteMessage[0] == 0x01 && byteMessage[1] == 0x03 && byteMessage[2] == 0x42) { return true; } else { return false; } } /// <summary> /// /// </summary> /// <returns></returns> internal static IEnumerable<QueryInstructionItem> GetInstructionQuerys() { var appParas = AppParasHelper.GetInstance(); if (appParas == null) { NtLogHelper.Error("Socket æ°æ®å¯¹æ¥ä¸ï¼NT ç¼ºå°æ°æ®å¯¹æ¥é ç½®æä»¶"); return null; } return appParas.InstructionQuerys; } /// <summary> /// è·åæ¥è¯¢æä»¤(çæ§å¼) /// </summary> /// <returns></returns> public byte[] GetMonitorMsgçæ§å¼() { return new byte[] { 0x01, 0x03, 0x00, 0x19, 0x00, 0x21, 0x54, 0x15 }; } /// <summary> /// è·åæ¥è¯¢æä»¤(ç¶æå¼):01-03-00-12-00-04-E4-0C /// </summary> /// <returns></returns> public static byte[] GetMonitorMsgç¶æå¼() { return new byte[] { 0x01, 0x03, 0x00, 0x12, 0x00, 0x04, 0xE4, 0x0C }; } /// <summary> /// è¯»åæ¶æ¯(çæ§å¼) /// </summary> /// <param name="byteMessage"></param> public static List<Model.MonitorDataDockingReceiveRecord> HandleReceive(byte[] byteMessage) { var list = new List<Model.MonitorDataDockingReceiveRecord>(); byte start = 0x1A; if (byteMessage == null) { NtLogHelper.Error($"æ°æ®è§£æå¤±è´¥!æ°æ®ä¸ºç©º"); return null; } if (byteMessage.Count() < 70) { var byteMsg = BitConverter.ToString(byteMessage); NtLogHelper.Error($"æ°æ®è§£æå¤±è´¥!{byteMsg},é¿åº¦ä¸å¤, é¿åº¦ä¸º{byteMessage.Count()},æ£å¸¸é¿åº¦71"); return null; } 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])); string msg; var now = DateTime.Now; //å½å管ç½åå list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1575030496453332992, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = (ByteMsgHelper.GetInt2Byte(byteMessage, 3, out msg) * 0.001).ToString() }); //åé¢é¢ç list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1575030605857558528, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = (ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (27 - start) * 2, out msg) * 0.1).ToString() }); //åé¢çµæµ list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301190702632960, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = (ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (28 - start) * 2, out msg) * 0.1).ToString() }); //ç空å½ååå list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1575030435430404096, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = (ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (29 - start) * 2, out msg) * 0.001).ToString() }); //Aç¸çµå list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301249292865536, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = Math.Round(ByteMsgHelper.GetDouble1(byteMessage, 3 + (30 - start) * 2, out msg), 2).ToString() }); //Bç¸çµå list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301287175819264, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = Math.Round(ByteMsgHelper.GetDouble1(byteMessage, 3 + (32 - start) * 2, out msg), 2).ToString() }); //Cç¸çµå list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301332780486656, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = Math.Round(ByteMsgHelper.GetDouble1(byteMessage, 3 + (34 - start) * 2, out msg), 2).ToString() }); //Aç¸çµæµ list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301384118767616, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = Math.Round(ByteMsgHelper.GetDouble1(byteMessage, 3 + (36 - start) * 2, out msg), 3).ToString() }); //Bç¸çµæµ list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301478792597504, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = Math.Round(ByteMsgHelper.GetDouble1(byteMessage, 3 + (38 - start) * 2, out msg), 3).ToString() }); //Cç¸çµæµ list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582301691439616000, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = Math.Round(ByteMsgHelper.GetDouble1(byteMessage, 3 + (40 - start) * 2, out msg), 3).ToString() }); //å颿³µç¶æ list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582303421711650816, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (42 - start) * 2, out msg).ToString() }); //çç©ºæ³µç¶æ list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582303241251721216, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (43 - start) * 2, out msg).ToString() }); ////çµå¨éå¼éç¶æ //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).ToString() }); ////çµå¨éå ³éç¶æ //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).ToString() }); //çµç£éç¶æ list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582303081771700224, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (46 - start) * 2, out msg).ToString() }); //æ°´ä½ç¶æ list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582303471342850048, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (47 - start) * 2, out msg).ToString() }); //è¶ åç¶æ list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582303606781120512, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (48 - start) * 2, out msg).ToString() }); //æ¥è¦ç¶æ list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582303637420511232, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (49 - start) * 2, out msg).ToString() }); //åé¢å¨ç¶æ list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1582303671927050240, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (50 - start) * 2, out msg).ToString() }); //å½åæ¶²ä½ list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1575388386963886080, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = (ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (51 - start) * 2, out msg) * 0.01).ToString() }); //ç¬æ¶æµé list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1575030320913321984, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = (ByteMsgHelper.GetInt4Byte(byteMessage, 3 + (52 - start) * 2, out msg) * 0.001).ToString() }); //累计æµé list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1584475350807744512, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = (ByteMsgHelper.GetInt4Byte(byteMessage, 3 + (54 - start) * 2, out msg) * 1.0).ToString() }); //累计æµéæååç list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1584475756476633088, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = Math.Round(ByteMsgHelper.GetDouble1(byteMessage, 3 + (56 - start) * 2, out msg), 2).ToString() }); } catch (Exception err) { var byteMsg = string.Join(',', byteMessage); NtLogHelper.Error($"æ°æ®è§£æå¼å¸¸!{byteMsg}" + $"é误æç¤º:{err.Message}"); } return list; } /// <summary> /// è¯»åæ¶æ¯(ç¶æå¼) /// </summary> /// <param name="byteMessage"></param> private static List<Model.MonitorDataDockingReceiveRecord> ReadMessageç¶æå¼(byte[] byteMessage) { var list = new List<Model.MonitorDataDockingReceiveRecord>(); byte start = 0x12; if (byteMessage == null || byteMessage.Length < 8) { return null; } 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])); string msg; var now = DateTime.Now; //æ¶²ä½éç¨ //list.Add(new Model.MonitorDataDockingReceiveRecord() //{ // SysId = , // RecordType = Model.eMonitorType.General, // SrcTime = now, // SrcValue = (GetInt2Byte(byteMessage, 3 + (19 - start), out msg )* 0.1).ToString() //}); //设å®é¢ç list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1584894751252025344, RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = (ByteMsgHelper.GetInt2Byte(byteMessage, 3 + (20 - start), out msg) * 0.1).ToString() }); } catch// (Exception err) { return null; } return list; } } } Socket/IStation.DataDockingSocket4NT/MsgHandle/ShunDownMsgHelper.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,109 @@ using IStation.DataDockingSocket.MsgHandle; using IStation.Untity; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.DataDockingSocket { internal class ShunDownMsgHelper { public static eShutDownInstructionStatus InstructionStatus = eShutDownInstructionStatus.æªåé; public static DateTime sendTime ; /// <summary> /// å¼å§å ³æº /// </summary> /// <param name="session"></param> /// <returns></returns> public static bool StartJob(Model.IMonitorDataDockingSession session) { if (session != null) { NtLogHelper.Error($"å ³æº session:Close"); return false; } if (session.IsConnected) { byte[] bts = GetControlMsg(); session.Send(bts, 0, bts.Length); InstructionStatus = eShutDownInstructionStatus.å ³æºæºæä»¤åé; sendTime = DateTime.Now; NtLogHelper.Debug("å ³æºæä»¤åé:" + session.SessionName + ":" + BitTransfer.ToString(bts) + ", åé䏿¡è¯·æ±æ§å¶æä»¤"); return true; } else { NtLogHelper.Error($"å ³æºæ¶ session:Not connected"); return false; } } /// <summary> /// æ¯å¦æ¯æ§å¶æä»¤ /// </summary> /// <param name="byteMessage"></param> /// <returns></returns> public static bool IsControlMsg(byte[] byteMessage) { return false; } /// <summary> /// è·åæ§å¶æä»¤(弿º) /// </summary> /// <returns></returns> public static byte[] GetControlMsg () { // var appParas = AppParasHelper.GetInstance(); // if (appParas == null || appParas.InstructionStartUp == null || appParas.InstructionStartUp.Content == null) { return BitTransfer.FromString("01-06-00-10-00-01-49-CF"); } // return BitTransfer.FromString(appParas.InstructionStartUp.Content); } /// <summary> /// 读åè¿åæ¶æ¯ /// </summary> /// <param name="byteMessage"></param> public static void HandleReceive(Model.IMonitorDataDockingSession session,byte[] byteMessage) { if (InstructionStatus == eShutDownInstructionStatus.æªåé) return; if (InstructionStatus == eShutDownInstructionStatus.å ³æºæºæä»¤åé) { if (byteMessage.Length == 8) { if (byteMessage[0] == 0x01 && byteMessage[1] == 0x06 && byteMessage[2] == 0x00 && byteMessage[3] == 0x10 && byteMessage[4] == 0x00 && byteMessage[5] == 0x01 && byteMessage[6] == 0x49 && byteMessage[7] == 0xCF) {//01-06-00-0F-00-01-78-09 InstructionStatus = eShutDownInstructionStatus.æªåé; NtLogHelper.Debug("å ³æºæä»¤è¿å:" + BitTransfer.ToString(byteMessage) ); return; } } //è¿å失败, ååé䏿¬¡å确认ä¸ä¸ if((DateTime.Now- sendTime).TotalSeconds > 3) { StartJob(session); } } } } } Socket/IStation.DataDockingSocket4NT/MsgHandle/StartUpMsgHelper.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,102 @@ using IStation.DataDockingSocket.MsgHandle; using IStation.Untity; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.DataDockingSocket { internal class StartUpMsgHelper { public static eStartUpInstructionStatus ShutUpInstructionStatus = eStartUpInstructionStatus.æªåé; /// <summary> /// 弿º /// </summary> /// <param name="session"></param> /// <returns></returns> public static bool StartJob(Model.IMonitorDataDockingSession session) { if (session != null) { NtLogHelper.Error($"弿º session:Close"); return false; } if (session.IsConnected) { byte[] bts = GetControlMsg弿º(); session.Send(bts, 0, bts.Length); ShutUpInstructionStatus = eStartUpInstructionStatus.è°é¢æä»¤åé; NtLogHelper.Info("弿º" + session.SessionName + ":" + BitTransfer.ToString(bts) + ", åé䏿¡è¯·æ±æ§å¶æä»¤"); return true; } else { NtLogHelper.Error($"弿ºæ¶ session:Not connected"); return false; } } /// <summary> /// /// </summary> /// <param name="byteMessage"></param> /// <returns></returns> public static bool IsCurrentMsg(byte[] byteMessage) { if(byteMessage.Length == 8) { if (byteMessage[0] == 0x01 && byteMessage[1] == 0x06 && byteMessage[2] == 0x00 && byteMessage[3] == 0x0F && byteMessage[4] == 0x00 && byteMessage[5] == 0x01 && byteMessage[6] == 0x78 && byteMessage[7] == 0x09) {//01-06-00-0F-00-01-78-09 return true; } } return false; } /// <summary> /// è·åæ§å¶æä»¤(弿º) /// </summary> /// <returns></returns> public static byte[] GetControlMsg弿º() { //var appParas = AppParasHelper.GetInstance(); //if (appParas == null || appParas.InstructionStartUp == null || appParas.InstructionStartUp.Content == null) { return BitTransfer.FromString("01-06-00-0F-00-01-78-09"); } //return BitTransfer.FromString(appParas.InstructionStartUp.Content); } /// <summary> /// è·åæ§å¶æä»¤(è°é¢) /// </summary> /// <returns></returns> public static byte[] GetControlMsgè°é¢(double frequece) { var iFrequece = (int)(frequece * 10); byte[] commandSend = null; ModBusRtuHelper.BuildSendMessage06(0x01, 20, 2, iFrequece, ref commandSend); return commandSend; } } } Socket/IStation.DataDockingSocket4NT/control/SendControlJobHelper.cs
@@ -1,4 +1,5 @@ using IStation.Untity; using IStation.DataDockingSocket.MsgHandle; using IStation.Untity; using System; using System.Collections.Generic; using System.Linq; @@ -12,6 +13,9 @@ /// </summary> public class SendControlJobHelper { /// <summary> /// ä»MQéé¢è·åæ§å¶æä»¤ è¾ å©ç±» /// </summary> private static RabbitMqExChangeHelper _queueHelper = null; /// <summary> @@ -48,58 +52,21 @@ NtLogHelper.Info("åéæ§å¶å½ä»¤ï¼æ°æ®åºåå失败"); return true; } byte[] bts = null; switch (paras.ControlType) { switch (paras.Type) {//0ä»£è¡¨å ³æº 1ä»£è¡¨å¼æº case 0: bts = MsgDataHelper.GetControlMsgå ³æº(); NtLogHelper.Info("å ³æº"); break;//ä»è¾ å©ç±»ä¸è·å å ³é case 1: bts = MsgDataHelper.GetControlMsg弿º(); NtLogHelper.Info("弿º"); ShunDownMsgHelper.StartJob(session); break;//ä»è¾ å©ç±»ä¸è·å å ³é case 1: if (string.IsNullOrEmpty(paras.Paras)) return false; StartUpMsgHelper.StartJob(session); break;//ä»è¾ å©ç±»ä¸è·å å¼å¯ case -1: { if (string.IsNullOrEmpty(paras.Context)) { NtLogHelper.Error($"[è°é¢]åæ°: null"); return false; } if (!double.TryParse(paras.Context, out double value)) { NtLogHelper.Error($"[è°é¢]åæ°å¼å¸¸:{paras.Context}"); return false; } bts = MsgDataHelper.GetControlMsgè°é¢(value); NtLogHelper.Info($"[è°é¢]åæ°:{paras.Context}"); } break;//ä»è¾ å©ç±»ä¸è·å åé¢ default: return false; } if (bts != null) { if (session != null) { if (session.IsConnected) { session.Send(bts, 0, bts.Length); NtLogHelper.Info(session.SessionName + ":" + BitTransfer.ToString(bts) + ", åé䏿¡è¯·æ±æ§å¶æä»¤"); } else { NtLogHelper.Error($"session:Not connected"); return false; } } else { NtLogHelper.Error($"session:Close"); return false; } } return true; } catch (Exception ex) @@ -109,8 +76,10 @@ } }); }); } } } Socket/IStation.DataDockingSocket4NT/helper/MsgDataHelper.cs
ÎļþÒÑɾ³ý Socket/IStation.DataDockingSocket4NT/paras/AppParasHelper.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,45 @@ using IStation.Untity; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.DataDockingSocket { internal class AppParasHelper { /// <summary> /// è·å /// </summary> /// <returns></returns> public static AppParas GetInstance() { if (_appparas == null) { var jsonFileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "paras_datadocking_socket_nt.json"); var json = FileHelper.ReadAllText(jsonFileName); _appparas = JsonHelper.Json2Object<AppParas>(json); } return _appparas; } private static AppParas _appparas = null; /// <summary> /// /// </summary> /// <returns></returns> public static bool IsSrc() { return GetInstance().Src; } /// <summary> /// /// </summary> /// <returns></returns> public static bool IsDebug() { return GetInstance().Debug; } } } Socket/IStation.DataDockingSocket4NT/paras/eReceiveMsgType.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,17 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.DataDockingSocket { public enum eReceiveMsgType { çæ§æä»¤è¿å = 0, 弿ºæä»¤è¿å = 1, å ³æºæä»¤è¿å = 2, è°é¢æä»¤è¿å = 3, æªç¥ = -1 } } Socket/IStation.DataDockingSocket4NT/paras/eShutDownInstructionStatus.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,15 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.DataDockingSocket { public enum eShutDownInstructionStatus { æªåé = 0, å ³æºæºæä»¤åé = 3, //å ³æºæä»¤è¿å = 4 } } Socket/IStation.DataDockingSocket4NT/paras/eStartUpInstructionStatus.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,17 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.DataDockingSocket { public enum eStartUpInstructionStatus { æªåé = 0, è°é¢æä»¤åé = 1, è°é¢æä»¤è¿å = 2, 弿ºæä»¤åé = 3, 弿ºæä»¤è¿å = 4 } }