ningshuxia
2022-10-27 2b6eeda2c91f0e570b58b2799758475b46c1ad61
修改南通接口
已修改2个文件
已添加9个文件
已删除2个文件
1664 ■■■■■ 文件已修改
Socket/IStation.DataDockingSocket4NT/HandleHelper.cs 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Socket/IStation.DataDockingSocket4NT/Log/LogHelper.cs 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Socket/IStation.DataDockingSocket4NT/MsgHandle/BseMsgHelper.cs 129 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Socket/IStation.DataDockingSocket4NT/MsgHandle/HandleHelper.cs 112 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Socket/IStation.DataDockingSocket4NT/MsgHandle/MonitorMsgHelper.cs 367 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Socket/IStation.DataDockingSocket4NT/MsgHandle/ShunDownMsgHelper.cs 109 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Socket/IStation.DataDockingSocket4NT/MsgHandle/StartUpMsgHelper.cs 102 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Socket/IStation.DataDockingSocket4NT/control/SendControlJobHelper.cs 63 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Socket/IStation.DataDockingSocket4NT/helper/MsgDataHelper.cs 575 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Socket/IStation.DataDockingSocket4NT/paras/AppParasHelper.cs 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Socket/IStation.DataDockingSocket4NT/paras/eReceiveMsgType.cs 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Socket/IStation.DataDockingSocket4NT/paras/eShutDownInstructionStatus.cs 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Socket/IStation.DataDockingSocket4NT/paras/eStartUpInstructionStatus.cs 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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("关机");
                                ShunDownMsgHelper.StartJob(session);
                                break;//从辅助类中获取  å…³é—­
                            case 1: 
                                bts = MsgDataHelper.GetControlMsg开机();
                                NtLogHelper.Info("开机");
                                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
    }
}