| | |
| | | |
| | | SessionHelper.Cache = session; |
| | | |
| | | var appParas = AppParasHelper.Get(); |
| | | if (appParas == null) |
| | | { |
| | | LogHelper.Error("Socket æ°æ®å¯¹æ¥ä¸ï¼NT ç¼ºå°æ°æ®å¯¹æ¥é
ç½®æä»¶"); |
| | | return; |
| | | } |
| | | foreach (var item in appParas.InstructionItems) |
| | | |
| | | foreach (var item in MsgDataHelper.GetInstructionQuerys()) |
| | | { |
| | | SendInstructionJobHelper.StartJob(session, item); |
| | | Thread.Sleep(appParas.InstructionSendSpace * 1000); |
| | | if(item.SpaceTime>0) |
| | | Thread.Sleep(item.SpaceTime * 1000); |
| | | } |
| | | |
| | | SendControlJobHelper.StartJob(session); |
| | |
| | | return; |
| | | if (bytes == null) |
| | | return; |
| | | var appParas = AppParasHelper.Get(); |
| | | if (appParas == null) |
| | | { |
| | | LogHelper.Error("Socket æ°æ®å¯¹æ¥ä¸ï¼NT ç¼ºå°æ°æ®å¯¹æ¥é
ç½®æä»¶"); |
| | | return; |
| | | } |
| | | |
| | | |
| | | var receList = HandleDataHelper.HandleData(bytes); |
| | | var receList = MsgDataHelper.HandleData(bytes); |
| | | if (receList != null && receList.Count > 0) |
| | | { |
| | | receive(receList); |
| | | } |
| | | |
| | | if (appParas.Src) |
| | | if (MsgDataHelper.IsSrc()) |
| | | { |
| | | SrcHelper.Src(bytes); |
| | | } |
| | | if (appParas.Debug) |
| | | if (MsgDataHelper.IsDebug()) |
| | | { |
| | | DebugHelper.Debug(receList); |
| | | } |
ÎļþÃû´Ó Socket/IStation.DataDockingSocket4NT/helper/HandleDataHelper.cs ÐÞ¸Ä |
| | |
| | | /// <summary> |
| | | /// å¤çæ°æ®è¾
å©ç±» |
| | | /// </summary> |
| | | internal class HandleDataHelper |
| | | internal class MsgDataHelper |
| | | { |
| | | |
| | | /// <summary> |
| | | /// è·å |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static AppParas GetAppParas() |
| | | { |
| | | 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 GetAppParas().Src; |
| | | } |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static bool IsDebug() |
| | | { |
| | | return GetAppParas().Debug; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¤çæ°æ® |
| | | /// </summary> |
| | |
| | | } |
| | | //else if (byteMessage[2] == 0x46) |
| | | //{ |
| | | // return ReadMessageçæ§å¼(byteMessage); |
| | | // return ReadMessageç¶æå¼(byteMessage); |
| | | //} |
| | | else |
| | | { |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | internal static IEnumerable<QueryInstructionItem> GetInstructionQuerys() |
| | | { |
| | | var appParas = GetAppParas(); |
| | | if (appParas == null) |
| | | { |
| | | LogHelper.Error("Socket æ°æ®å¯¹æ¥ä¸ï¼NT ç¼ºå°æ°æ®å¯¹æ¥é
ç½®æä»¶"); |
| | | return null; |
| | | } |
| | | return appParas.InstructionQuerys; |
| | | } |
| | | /// <summary> |
| | | /// è·åæ§å¶æä»¤(è°é¢) |
| | | /// </summary> |
| | |
| | | |
| | | |
| | | /// <summary> |
| | | /// è·åæ¥è¯¢æä»¤(ç¶æå¼) |
| | | /// è·åæ¥è¯¢æä»¤(ç¶æå¼):01-03-00-12-00-04-E4-0C |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static byte[] GetMonitorMsgç¶æå¼() |
| | | { |
| | | return new byte[] { 0x01, 0x03, 0x00, 0x19, 0x00, 0x23, 0xD5, 0xD4 }; |
| | | return new byte[] { 0x01, 0x03, 0x00, 0x12, 0x00, 0x04, 0xE4, 0x0C }; |
| | | } |
| | | |
| | | |
| | |
| | | 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 = (GetInt2Byte(byteMessage, 3 + (20 - start), out msg) * 0.1).ToString() |
| | | }); |
| | | } |
| | | catch// (Exception err) |
| | | { |
| | | return null; |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | |
| | | #region MyRegion |
| | | private static int GetInt2Byte(byte[] byteMessage, int startPosition, out string info) |
| | | { |
| | |
| | | //return BitConverter.ToDouble(byteMessage, startPosition); |
| | | return BitConverter.ToSingle(value.Reverse().ToArray(), 0);//éç¨äºIEEE-754äºè¿å¶æµ®ç¹æ°ç®æ¯æ å |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | } |
| | | |
| | |
| | | /// <summary> |
| | | /// å¼å§ä»»å¡ |
| | | /// </summary> |
| | | public static async void StartJob(Model.IMonitorDataDockingSession session, InstructionItem item) |
| | | public static async void StartJob(Model.IMonitorDataDockingSession session, QueryInstructionItem item) |
| | | { |
| | | if (session == null) |
| | | return; |
| | |
| | | return; |
| | | if (item == null) |
| | | return; |
| | | if (string.IsNullOrEmpty(item.Instruction)) |
| | | if (string.IsNullOrEmpty(item.Content)) |
| | | return; |
| | | |
| | | LogHelper.Info($"{session.SessionName} å¼å§å¤çåéæä»¤ä»»å¡ï¼æä»¤:{item.Instruction} !"); |
| | | LogHelper.Info($"{session.SessionName} å¼å§å¤çåéæä»¤ä»»å¡ï¼æä»¤:{item.Content} !"); |
| | | |
| | | var jobName = SendInstructionJobNameHelper.GetJobName(session, item.Instruction); |
| | | var jobGroupName = SendInstructionJobNameHelper.GetJobGroupName(session, item.Instruction); |
| | | var triggerName = SendInstructionJobNameHelper.GetTriggerName(session, item.Instruction); |
| | | var jobName = SendInstructionJobNameHelper.GetJobName(session, item.Name); |
| | | var jobGroupName = SendInstructionJobNameHelper.GetJobGroupName(session, item.Name); |
| | | var triggerName = SendInstructionJobNameHelper.GetTriggerName(session, item.Name); |
| | | |
| | | //夿æ¯å¦åå¨ |
| | | if (_sched != null) |
| | |
| | | var triggerKey = new TriggerKey(triggerName, jobGroupName); |
| | | if (await _sched.CheckExists(triggerKey)) |
| | | { |
| | | LogHelper.Info($"{session.SessionName} ä¸ï¼æä»¤ï¼{item.Instruction} ç主å¨è¯·æ±æ°æ®ä»»å¡å·²ç»å¼å¯ï¼æ ééå¤å¼å¯ï¼"); |
| | | LogHelper.Info($"{session.SessionName} ä¸ï¼æä»¤ï¼{item.Content} ç主å¨è¯·æ±æ°æ®ä»»å¡å·²ç»å¼å¯ï¼æ ééå¤å¼å¯ï¼"); |
| | | return; |
| | | } |
| | | } |
| | |
| | | .WithIdentity(jobName, jobGroupName) |
| | | .Build(); |
| | | job.JobDataMap.Put(SendInstructionJob.Session, session); |
| | | job.JobDataMap.Put(SendInstructionJob.Instruction, BitTransfer.FromString(item.Instruction)); |
| | | job.JobDataMap.Put(SendInstructionJob.Instruction, BitTransfer.FromString(item.Content)); |
| | | |
| | | //4.å建Trigger |
| | | var trigger = TriggerBuilder.Create() |
| | |
| | | |
| | | //5.å å
¥è°åº¦ç®¡çå¨ |
| | | await _sched.ScheduleJob(job, trigger); |
| | | session.SessionClosedEvent += () => CancelJob(session, item.Instruction); |
| | | LogHelper.Info($"{session.SessionName} ä¸ï¼æä»¤:{item.Instruction} ç主å¨è¯·æ±æ°æ®çº¿ç¨å¼å¯æåï¼"); |
| | | session.SessionClosedEvent += () => CancelJob(session, item); |
| | | LogHelper.Info($"{session.SessionName} ä¸ï¼æä»¤:{item.Content} ç主å¨è¯·æ±æ°æ®çº¿ç¨å¼å¯æåï¼"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åæ¶ä»»å¡ |
| | | /// </summary> |
| | | private static async void CancelJob(Model.IMonitorDataDockingSession session, string instruction) |
| | | private static async void CancelJob(Model.IMonitorDataDockingSession session, QueryInstructionItem item) |
| | | { |
| | | if (_sched == null) |
| | | return; |
| | | LogHelper.Info($"{session.SessionName} æ£æç®ç»æ¢ä¸»å¨è¯·æ±æ°æ®ä»»å¡"); |
| | | var triggerName = SendInstructionJobNameHelper.GetTriggerName(session, instruction); |
| | | var jobGroupName = SendInstructionJobNameHelper.GetJobGroupName(session, instruction); |
| | | var triggerName = SendInstructionJobNameHelper.GetTriggerName(session, item.Name); |
| | | var jobGroupName = SendInstructionJobNameHelper.GetJobGroupName(session, item.Name); |
| | | var triggerKey = new TriggerKey(triggerName, jobGroupName); |
| | | if (await _sched.CheckExists(triggerKey)) |
| | | { |
| | | await _sched.UnscheduleJob(triggerKey); |
| | | LogHelper.Info($"{session.SessionName},æä»¤:{instruction} 主å¨è¯·æ±æ°æ®ä»»å¡ç»æ¢æå"); |
| | | LogHelper.Info($"{session.SessionName},æä»¤:{item.Name} 主å¨è¯·æ±æ°æ®ä»»å¡ç»æ¢æå"); |
| | | } |
| | | else |
| | | { |
| | | LogHelper.Info($"{session.SessionName},æä»¤:{instruction} 主å¨è¯·æ±æ°æ®ä»»å¡ä¸åå¨"); |
| | | LogHelper.Info($"{session.SessionName},æä»¤:{item.Name} 主å¨è¯·æ±æ°æ®ä»»å¡ä¸åå¨"); |
| | | } |
| | | } |
| | | |
| | |
| | | public class AppParas |
| | | { |
| | | /// <summary> |
| | | /// æä»¤åéé´é |
| | | /// æ¥è¯¢æä»¤é¡¹ |
| | | /// </summary> |
| | | public int InstructionSendSpace { get; set; } |
| | | public List<QueryInstructionItem> InstructionQuerys { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æä»¤é¡¹å表 |
| | | /// 弿ºæä»¤ |
| | | /// </summary> |
| | | public List<InstructionItem> InstructionItems { get; set; } |
| | | public CtrlInstructionItem InstructionStartUp { get; set; } |
| | | |
| | | /// <summary> |
| | | /// å
³æºæä»¤ |
| | | /// </summary> |
| | | public CtrlInstructionItem InstructionShutDown { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ¯å¦ä¿ååå§ |
| | |
| | | /// æ¯å¦è°è¯ |
| | | /// </summary> |
| | | public bool Debug { get; set; } |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ¥è¯¢æä»¤é¡¹ |
| | | /// </summary> |
| | | public class QueryInstructionItem |
| | | { |
| | | /// <summary> |
| | | /// æä»¤å |
| | | /// </summary> |
| | | public string Name { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æä»¤ |
| | | /// </summary> |
| | | public string Content { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æä»¤åéé¢ç ç§ |
| | | /// </summary> |
| | | public int Frequency { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æä»¤åéé´é |
| | | /// </summary> |
| | | public int SpaceTime { get; set; } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ§å¶æä»¤é¡¹ |
| | | /// </summary> |
| | | public class CtrlInstructionItem |
| | | { |
| | | /// <summary> |
| | | /// æä»¤ |
| | | /// </summary> |
| | | public string Content { get; set; } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// æä»¤é¡¹ |
| | | /// </summary> |
| | | public class InstructionItem |
| | | { |
| | | /// <summary> |
| | | /// æä»¤ |
| | | /// </summary> |
| | | public string Instruction { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æä»¤åéé¢ç ç§ |
| | | /// </summary> |
| | | public int Frequency { get; set; } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | /// </summary> |
| | | internal class AppParasHelper |
| | | { |
| | | /// <summary> |
| | | /// jsonæä»¶åç§° |
| | | /// </summary> |
| | | public static string JsonFileName |
| | | { |
| | | get |
| | | { |
| | | if (string.IsNullOrEmpty(_jsonFileName)) |
| | | { |
| | | _jsonFileName= System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "paras_datadocking_socket_nt.json"); |
| | | } |
| | | return _jsonFileName; |
| | | } |
| | | } |
| | | private static string _jsonFileName = null; |
| | | |
| | | /// <summary> |
| | | /// è·å |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static AppParas Get() |
| | | { |
| | | if (_appparas == null) |
| | | { |
| | | var json = FileHelper.ReadAllText(JsonFileName); |
| | | _appparas = JsonHelper.Json2Object<AppParas>(json); |
| | | } |
| | | return _appparas; |
| | | } |
| | | private static AppParas _appparas = null; |
| | | |
| | | } |
| | | } |
| | |
| | | { |
| | | "InstructionSendSpace": 10, |
| | | "InstructionItems": [ |
| | | "InstructionQuerys": [ |
| | | { |
| | | "Instruction": "01-03-00-19-00-19-55-C7", |
| | | "Frequency": 60 |
| | | }, |
| | | { |
| | | "Instruction": "01-03-00-00-00-16-C4-04", |
| | | "Frequency": 60 |
| | | "Name": "Data", |
| | | "Content": "01-03-00-19-00-19-55-C7", |
| | | "Frequency": 60, |
| | | "SpaceTime": 0 |
| | | } |
| | | // , |
| | | //{ |
| | | // "Instruction": "01-03-00-00-00-16-C4-04", |
| | | // "Frequency": 60 |
| | | //} |
| | | ], |
| | | "InstructionStartUp": { |
| | | "Content": "01-03-00-19-00-19-55-C7" |
| | | }, |
| | | "InstructionShutDown": { |
| | | "Content": "01-03-00-19-00-19-55-C7" |
| | | }, |
| | | "Debug": true, |
| | | "Src": true |
| | | } |
| | |
| | | /// å é度 |
| | | /// </summary> |
| | | [Display(Name = "å é度")] |
| | | å é度 = 26, |
| | | |
| | | å é度 = 26, |
| | | /// <summary> |
| | | /// è´¨é |
| | | /// </summary> |
| | | [Display(Name = "è´¨é")] |
| | | è´¨é = 27, |
| | | /// <summary> |
| | | /// èªå®ä¹ |
| | | /// </summary> |