diff --git a/InSituLaboratory.IService/Sensor/ISensorService.cs b/InSituLaboratory.IService/Sensor/ISensorService.cs index dec8c12..7b60e71 100644 --- a/InSituLaboratory.IService/Sensor/ISensorService.cs +++ b/InSituLaboratory.IService/Sensor/ISensorService.cs @@ -1,6 +1,7 @@ using InSituLaboratory.Entities; using InSituLaboratory.Entities.ExperimentalStationEntities; using InSituLaboratory.Entities.Sensor; +using InSituLaboratory.Entities.SqlSugar; using InSituLaboratory.Entities.SysData; using System; using System.Collections.Generic; @@ -196,6 +197,13 @@ namespace InSituLaboratory.IService.Sensor /// /// IEnumerable GeSysSensor(); + + + /// + /// 获取当前运行时序状态 + /// + /// + IEnumerable GetCurrentSequentiual(); #endregion } diff --git a/InSituLaboratory.Service/Sensor/SensorService.cs b/InSituLaboratory.Service/Sensor/SensorService.cs index 5a0c170..4f65f16 100644 --- a/InSituLaboratory.Service/Sensor/SensorService.cs +++ b/InSituLaboratory.Service/Sensor/SensorService.cs @@ -1,6 +1,7 @@ using InSituLaboratory.Entities; using InSituLaboratory.Entities.ExperimentalStationEntities; using InSituLaboratory.Entities.Sensor; +using InSituLaboratory.Entities.SqlSugar; using InSituLaboratory.Entities.SysData; using InSituLaboratory.IService; using InSituLaboratory.IService.Sensor; @@ -286,6 +287,15 @@ namespace InSituLaboratory.Service.Sensor { return this.Query(m => true).OrderByDescending(n => n.CreateTime).AsNoTracking(); } + + /// + /// 获取当前运行时序状态 + /// + /// + public IEnumerable GetCurrentSequentiual() + { + return this.Query(m => true).OrderByDescending(n => n.CreateTime).AsNoTracking(); + } #endregion } diff --git a/InSituLaboratory/Common/DataParsing.cs b/InSituLaboratory/Common/DataParsing.cs index 371b537..05c0a7c 100644 --- a/InSituLaboratory/Common/DataParsing.cs +++ b/InSituLaboratory/Common/DataParsing.cs @@ -42,7 +42,7 @@ namespace InSituLaboratory.Common string ResponID = ""; //通用应答消息ID - string MessageID = "1000"; + string MessageID = "0000"; //crc static byte nr_crc = 0; @@ -209,10 +209,10 @@ namespace InSituLaboratory.Common currentSequentiual.DeviceNumber += "气相色谱仪 "; break; case 0x08: - currentSequentiual.DeviceNumber += "甲烷传感器 "; + currentSequentiual.DeviceNumber += "CH4 "; break; case 0x09: - currentSequentiual.DeviceNumber += "二氧化碳同位素分析仪 "; + currentSequentiual.DeviceNumber += "CO2 "; break; case 0x0a: currentSequentiual.DeviceNumber += "备用网口设备 "; @@ -221,7 +221,7 @@ namespace InSituLaboratory.Common currentSequentiual.DeviceNumber += "ICL "; break; case 0x0c: - currentSequentiual.DeviceNumber += "显微拉曼分析仪 "; + currentSequentiual.DeviceNumber += "显微拉曼 "; break; case 0x0d: currentSequentiual.DeviceNumber += "质谱仪 "; @@ -250,7 +250,7 @@ namespace InSituLaboratory.Common - //通用应答 消息ID:0x1000 + //通用应答 消息ID:0x0000 if (MessageID == dataNew[1].ToString("X2") + dataNew[2].ToString("X2")) { dataParsingModel.CreateTime = System.DateTime.Now; diff --git a/InSituLaboratory/ViewModels/Pages/RelayViewModel.cs b/InSituLaboratory/ViewModels/Pages/RelayViewModel.cs index 10baa81..100ce63 100644 --- a/InSituLaboratory/ViewModels/Pages/RelayViewModel.cs +++ b/InSituLaboratory/ViewModels/Pages/RelayViewModel.cs @@ -3,6 +3,7 @@ using InSituLaboratory.Common; using InSituLaboratory.Controls; using InSituLaboratory.Entities; using InSituLaboratory.Entities.Sensor; +using InSituLaboratory.Entities.SqlSugar; using InSituLaboratory.IService; using InSituLaboratory.IService.Sensor; using InSituLaboratory.Models.Sendsor; @@ -20,6 +21,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Forms; using System.Windows.Markup; +using System.Windows.Media.Animation; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace InSituLaboratory.ViewModels.Pages @@ -30,12 +32,13 @@ namespace InSituLaboratory.ViewModels.Pages public class RelayViewModel : ViewModelBase { #region Entity - public ClientModel clientModel { get; set; } = new ClientModel(); - public SysSensorModel sysSensorModel { get; set; } = new SysSensorModel(); - public SysSensorModels sysSensorModels { get; set; } = new SysSensorModels(); - public LogModel logModel { get; set; } + public ClientModel clientModel { get; set; } = new ClientModel();//Socket 通信类 + public SysSensorModel sysSensorModel { get; set; } = new SysSensorModel(); // 传感器表 + public CurrentSequentiual CurrentSequentiual { get; set; } = new CurrentSequentiual(); //当前运行时序状态表 + public SysSensorModels sysSensorModels { get; set; } = new SysSensorModels(); //传感器表 + public LogModel logModel { get; set; } //日志记录表 public ObservableCollection loglist { get; set; } = new ObservableCollection(); - public PaginationModel PaginationModel { get; set; } = new PaginationModel(); + public PaginationModel PaginationModel { get; set; } = new PaginationModel(); //分页组件 public static SocketInfo SocketInfo { get; set; } = new SocketInfo() { IP = tools.GetAppSetting("IP"), @@ -73,10 +76,17 @@ namespace InSituLaboratory.ViewModels.Pages public override void Refresh() { loglist.Clear(); + + //获取日志记录数据 var Loglist = _logService.GetLogData(SearchKey, PaginationModel.PageSize, PaginationModel.PageIndex, out int totalCount); + + //获取传感器电源开关数据 var SysSensorlist = _sensorService.GeSysSensor(); - ///列表清单数据 + //获取当前运行时序状态表 + var CurrentSequentiualList = _sensorService.GetCurrentSequentiual(); + + //日志列表清单数据 int index = 0; foreach (var item in Loglist) { @@ -89,7 +99,7 @@ namespace InSituLaboratory.ViewModels.Pages }); } - ///状态监控 + //传感器电源开关数据 if (SysSensorlist.Count() != 0) { var data = _sensorService.GeSysSensor().FirstOrDefault(); @@ -115,6 +125,16 @@ namespace InSituLaboratory.ViewModels.Pages sysSensorModel.ElectricSwitch2 = sysSensorModels.ElectricSwitch2 = data.ElectricSwitch2; } + //当前运行时序状态数据 + if (CurrentSequentiualList.Count() != 0) + { + var data = _sensorService.GetCurrentSequentiual().FirstOrDefault(); + + CurrentSequentiual.Number = data.Number; + CurrentSequentiual.DeviceNumber = data.DeviceNumber; + CurrentSequentiual.Status = data.Status; + } + // 刷新分页组件的页码 PaginationModel.FillPageNumbers(totalCount); } @@ -931,7 +951,7 @@ namespace InSituLaboratory.ViewModels.Pages opendata += data[i]; opendata = opendata + "、"; } - if (System.Windows.Forms.MessageBox.Show("当前处于打开状态的设备有" + opendata +"确认需要一键还原吗?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) + if (System.Windows.Forms.MessageBox.Show("当前处于打开状态的设备有" + opendata + "确认需要一键还原吗?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { if (System.Windows.Forms.MessageBox.Show("再次确定需要一键还原吗?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { @@ -1097,5 +1117,112 @@ namespace InSituLaboratory.ViewModels.Pages } } + /// + /// 时间同步 + /// + public override void DoSynchronization() + { + ulong senddate; + ulong year; + ulong month; + ulong day; + ulong hour; + ulong min; + ulong sec; + ulong minsec; + + //定义消息体数组 + byte[] byteaq = new byte[16]; + DateTime dateTime = DateTime.Now; + year = (ulong)dateTime.Year * 10000000000000UL; + month = (ulong)dateTime.Month * 100000000000; + day = (ulong)dateTime.Day * 1000000000L; + hour = (ulong)dateTime.Hour * 10000000; + min = (ulong)dateTime.Minute * 100000; + sec = (ulong)dateTime.Second * 1000; + minsec = (ulong)dateTime.Millisecond; + senddate = year + month + day + hour + min + sec + minsec; + + byteaq[0] = 0x90; + byteaq[1] = 0x02; + byteaq[2] = 0x10; + byteaq[3] = 0x01; + byteaq[4] = 0x00; + byteaq[5] = 0x00; + byteaq[6] = 0x00; + byteaq[7] = 0x00; + byteaq[8] = (byte)((senddate >> 56) & 0xff); + byteaq[9] = (byte)((senddate >> 48) & 0xff); + byteaq[10] = (byte)((senddate >> 40) & 0xff); + byteaq[11] = (byte)((senddate >> 32) & 0xff); + byteaq[12] = (byte)((senddate >> 24) & 0xff); + byteaq[13] = (byte)((senddate >> 16) & 0xff); + byteaq[14] = (byte)((senddate >> 8) & 0xff); + byteaq[15] = (byte)(senddate & 0xff); + + //标志位 + byte head = 0x7f; + //crc + byte nr_crc = 0; + nr_crc = tools.CRC(byteaq.ToArray(), 0, byteaq.Length); + + ///转义 + int j = 0; + List tBuffer = byteaq.ToList(); + tBuffer.Add(nr_crc); + int length = tBuffer.ToArray().Length; + byte[] newAnswer = tBuffer.ToArray(); + for (int i = 0; i < length; i++) + { + if (newAnswer[i] == 0x7e || newAnswer[i] == 0x7f) + { + j++; + } + } + byte[] newSendBuffer = new byte[length + j]; + for (int i = 0; i < length; i++) + { + newSendBuffer[i] = newAnswer[i]; + } + for (int i = 0; i < length + j; i++) + { + if (newSendBuffer[i] == 0x7e) + { + for (int k = length + j - 1; k > i + 1; k--) + { + newSendBuffer[k] = newSendBuffer[k - 1]; + } + newSendBuffer[i + 1] = 0x01; + } + if (newSendBuffer[i] == 0x7f) + { + newSendBuffer[i] = 0x7e; + for (int k = length + j - 1; k > i + 1; k--) + { + newSendBuffer[k] = newSendBuffer[k - 1]; + } + newSendBuffer[i + 1] = 0x02; + } + } + + List buffer = new List(); + buffer.Add(head); + for (int i = 0; i < newSendBuffer.Length; i++) + { + buffer.Add(newSendBuffer[i]); + } + buffer.Add(head); + + string list = tools.byteToHexStr(buffer.ToArray()); + byte[] bytea = tools.ConvertHexStringToBytes(list); + clientModel.SendData(bytea); + + logModel = new LogModel(); + logModel.CreateTime = DateTime.Now; + logModel.Remark = "时间同步指令已下发"; + _logService.Insert(logModel); + this.Refresh(); + } + } } diff --git a/InSituLaboratory/ViewModels/Pages/ViewModelBase.cs b/InSituLaboratory/ViewModels/Pages/ViewModelBase.cs index 1620801..b84fa74 100644 --- a/InSituLaboratory/ViewModels/Pages/ViewModelBase.cs +++ b/InSituLaboratory/ViewModels/Pages/ViewModelBase.cs @@ -62,6 +62,7 @@ namespace InSituLaboratory.ViewModels.Pages public DelegateCommand ConnectionCommand { get; set; } public DelegateCommand ReductionCommand { get; set; } //一键还原 public DelegateCommand StartCommand { get; set; }//一键启动 + public DelegateCommand SynchronizationCommand { get; set; }//时间同步 #region 时序1-5 刷新 新增/编辑 删除 下发 @@ -107,6 +108,7 @@ namespace InSituLaboratory.ViewModels.Pages ConnectionCommand = new DelegateCommand(DoConnection); ReductionCommand = new DelegateCommand(DoReduction); StartCommand = new DelegateCommand(DoStart); + SynchronizationCommand = new DelegateCommand(DoSynchronization); #region 时序1-5 刷新 新增/编辑 删除 下发 @@ -155,6 +157,7 @@ namespace InSituLaboratory.ViewModels.Pages public virtual void DoConnection(object model) { } public virtual void DoReduction() { } public virtual void DoStart() { } + public virtual void DoSynchronization() { } private string PageName { get; set; } diff --git a/InSituLaboratory/Views/Pages/RelayView.xaml b/InSituLaboratory/Views/Pages/RelayView.xaml index d1193f2..c2e6cff 100644 --- a/InSituLaboratory/Views/Pages/RelayView.xaml +++ b/InSituLaboratory/Views/Pages/RelayView.xaml @@ -87,12 +87,13 @@ + - + @@ -108,7 +109,7 @@ - + @@ -116,7 +117,7 @@ - + - + @@ -508,7 +553,7 @@ - + @@ -679,7 +724,7 @@ - +