| | |
| | | using IStation.DataDockingSocket.MsgHandle; |
| | | using IStation.Model; |
| | | using IStation.Model; |
| | | using IStation.Untity; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | /// <returns></returns> |
| | | public static bool StartJob(Model.IMonitorDataDockingSession session, MonitorTestControlParas.StartContext paras) |
| | | { |
| | | if (session != null) |
| | | if (session == null) |
| | | { |
| | | NtLogHelper.Error($"开机 session:Close"); |
| | | return false; |
| | |
| | | return false; |
| | | } |
| | | /// <summary> |
| | | /// 关机指令 |
| | | /// 开机指令 |
| | | /// </summary> |
| | | static string ControlMsgOpen = "01-06-00-0F-00-01-78-09"; |
| | | /// <summary> |
| | |
| | | public static bool HandleReceive(Model.IMonitorDataDockingSession session, byte[] byteMessage) |
| | | { |
| | | if (InstructionStatus == eStartUpInstructionStatus.未发送) |
| | | { |
| | | NtLogHelper.Info("InstructionStatus==eStartUpInstructionStatus.未发送"); |
| | | return false; |
| | | } |
| | | if (InstructionStatus == eStartUpInstructionStatus.开机指令发送) |
| | | { |
| | | if (byteMessage.Length >= ControlMsgOpen.Length) |
| | | NtLogHelper.Info("InstructionStatus==eStartUpInstructionStatus.开机指令发送"); |
| | | var byteMsgOpen = Encoding.Unicode.GetBytes(ControlMsgOpen); |
| | | //if (byteMessage.Length >= byteMsgOpen.Length) |
| | | //{ |
| | | string strMessage = BitConverter.ToString(byteMessage, 0, byteMessage.Length); |
| | | if (strMessage == ControlMsgOpen) |
| | | { |
| | | string strMessage = BitConverter.ToString(byteMessage, 0, byteMessage.Length); |
| | | if (strMessage == ControlMsgOpen) |
| | | {//01-06-00-0F-00-01-78-09 |
| | | InstructionStatus = eStartUpInstructionStatus.未发送; |
| | | NtLogHelper.Info($"strMessage ({strMessage})== ControlMsgOpen ({ControlMsgOpen})"); |
| | | //01-06-00-0F-00-01-78-09 |
| | | InstructionStatus = eStartUpInstructionStatus.未发送; |
| | | |
| | | NtLogHelper.Debug("开机指令返回:" + BitTransfer.ToString(byteMessage)); |
| | | NtLogHelper.Info("开机指令返回:" + BitTransfer.ToString(byteMessage)); |
| | | if (_lastParas.OperatingValue > 0) |
| | | { |
| | | //开启自动关闭 |
| | | ShutDownMsgHelper.StartAutoClose(_lastParas.OperatingValue); |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | NtLogHelper.Info("时间小于等于0,不开启自动关闭"); |
| | | } |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | NtLogHelper.Info($"strMessage ({strMessage})!= ControlMsgOpen ({ControlMsgOpen})"); |
| | | } |
| | | //} |
| | | //else |
| | | //{ |
| | | // NtLogHelper.Info($"byteMessage.Length ({byteMessage.Length}) <= ControlMsgOpen.Length ({ControlMsgOpen.Length})"); |
| | | //} |
| | | |
| | | //返回失败, 再发送一次再确认一下 |
| | | if ((DateTime.Now - _lastOpenSendTime).TotalSeconds > 5) |
| | | { |
| | | NtLogHelper.Info($"返回失败, 再发送一次再确认一下"); |
| | | SendOpenMsg(session); |
| | | } |
| | | } |
| | | |
| | | if (InstructionStatus == eStartUpInstructionStatus.调频指令发送) |
| | | { |
| | | NtLogHelper.Info($"InstructionStatus == eStartUpInstructionStatus.调频指令发送"); |
| | | //需要判断是否是调频指令:以后再补充 |
| | | { |
| | | SendOpenMsg(session); |
| | |
| | | //返回失败, 再发送一次再确认一下 |
| | | if ((DateTime.Now - _lastHzSendTime).TotalSeconds > 5) |
| | | { |
| | | NtLogHelper.Info($"返回失败, 再发送一次再确认一下"); |
| | | StartJob(session, _lastParas); |
| | | } |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | private static void SendOpenMsg(Model.IMonitorDataDockingSession session) |
| | | private static void SendOpenMsg(Model.IMonitorDataDockingSession session) |
| | | { |
| | | byte[] bts = GetControlMsg开机(); |
| | | |
| | | |
| | | session.Send(bts, 0, bts.Length); |
| | | InstructionStatus = eStartUpInstructionStatus.开机指令发送; |
| | |
| | | public static byte[] GetControlMsg调频(double frequece) |
| | | { |
| | | var iFrequece = (int)(frequece * 10); |
| | | |
| | | byte[] commandSend = null; |
| | | |
| | | ModBusRtuHelper.BuildSendMessage06(0x01, 20, 2, |
| | | iFrequece, ref commandSend); |
| | | |