2024-06-17 10:12:16 +00:00
|
|
|
|
|
|
|
|
|
|
using Azure;
|
2024-06-12 10:17:01 +00:00
|
|
|
|
using InSituLaboratory.Common;
|
2024-05-20 10:46:43 +00:00
|
|
|
|
using InSituLaboratory.Controls;
|
2024-05-17 10:37:55 +00:00
|
|
|
|
using InSituLaboratory.Entities;
|
2024-05-20 10:46:43 +00:00
|
|
|
|
using InSituLaboratory.Entities.Sensor;
|
2024-06-13 10:17:25 +00:00
|
|
|
|
using InSituLaboratory.Entities.SqlSugar;
|
2024-05-20 10:46:43 +00:00
|
|
|
|
using InSituLaboratory.IService;
|
|
|
|
|
|
using InSituLaboratory.IService.Sensor;
|
|
|
|
|
|
using InSituLaboratory.Models.Sendsor;
|
|
|
|
|
|
using InSituLaboratory.Service;
|
|
|
|
|
|
using InSituLaboratory.Service.Sensor;
|
|
|
|
|
|
using Prism.Commands;
|
2024-05-17 10:37:55 +00:00
|
|
|
|
using Prism.Regions;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2024-05-20 10:46:43 +00:00
|
|
|
|
using System.Collections.ObjectModel;
|
2024-06-12 10:17:01 +00:00
|
|
|
|
using System.Diagnostics.Eventing.Reader;
|
2024-05-17 10:37:55 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2024-05-22 10:37:51 +00:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using System.Windows.Markup;
|
2024-06-13 10:17:25 +00:00
|
|
|
|
using System.Windows.Media.Animation;
|
2024-05-20 10:46:43 +00:00
|
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
2024-05-17 10:37:55 +00:00
|
|
|
|
|
|
|
|
|
|
namespace InSituLaboratory.ViewModels.Pages
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 局部电源开关控制
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class RelayViewModel : ViewModelBase
|
|
|
|
|
|
{
|
2024-05-20 10:46:43 +00:00
|
|
|
|
#region Entity
|
2024-06-19 06:01:51 +00:00
|
|
|
|
public static ClientModel clientModel { get; set; } = new ClientModel();//Socket 通信类
|
2024-06-13 10:17:25 +00:00
|
|
|
|
public SysSensorModel sysSensorModel { get; set; } = new SysSensorModel(); // 传感器表
|
|
|
|
|
|
public SysSensorModels sysSensorModels { get; set; } = new SysSensorModels(); //传感器表
|
|
|
|
|
|
public LogModel logModel { get; set; } //日志记录表
|
2024-05-20 10:46:43 +00:00
|
|
|
|
public ObservableCollection<LogModel> loglist { get; set; } = new ObservableCollection<LogModel>();
|
2024-06-13 10:17:25 +00:00
|
|
|
|
public PaginationModel PaginationModel { get; set; } = new PaginationModel(); //分页组件
|
2024-05-17 10:37:55 +00:00
|
|
|
|
public static SocketInfo SocketInfo { get; set; } = new SocketInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
IP = tools.GetAppSetting("IP"),
|
2024-05-20 10:46:43 +00:00
|
|
|
|
Port = Convert.ToInt32(tools.GetAppSetting("Port")),
|
|
|
|
|
|
ConnectionMessage = "连接"
|
2024-05-17 10:37:55 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-05-20 10:46:43 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
public DelegateCommand<object> RelayCommand { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ILogService _logService;
|
|
|
|
|
|
ISensorService _sensorService;
|
|
|
|
|
|
public RelayViewModel(IRegionManager regionManager, ILogService logService, ISensorService sensorService) : base(regionManager)
|
2024-05-17 10:37:55 +00:00
|
|
|
|
{
|
|
|
|
|
|
this.PageTitle = "通信与电源控制";
|
2024-05-20 10:46:43 +00:00
|
|
|
|
_logService = logService;
|
|
|
|
|
|
_sensorService = sensorService;
|
|
|
|
|
|
|
|
|
|
|
|
PaginationModel.NavCommand = new DelegateCommand<object>(index =>
|
|
|
|
|
|
{
|
|
|
|
|
|
PaginationModel.PageIndex = int.Parse(index.ToString());
|
|
|
|
|
|
this.Refresh();
|
|
|
|
|
|
});
|
|
|
|
|
|
RelayCommand = new DelegateCommand<object>(DoRelay);
|
|
|
|
|
|
|
|
|
|
|
|
this.Refresh();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 数据刷新
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public override void Refresh()
|
|
|
|
|
|
{
|
|
|
|
|
|
loglist.Clear();
|
2024-06-13 10:17:25 +00:00
|
|
|
|
|
|
|
|
|
|
//获取日志记录数据
|
2024-05-20 10:46:43 +00:00
|
|
|
|
var Loglist = _logService.GetLogData(SearchKey, PaginationModel.PageSize, PaginationModel.PageIndex, out int totalCount);
|
2024-06-13 10:17:25 +00:00
|
|
|
|
|
|
|
|
|
|
//获取传感器电源开关数据
|
2024-05-20 10:46:43 +00:00
|
|
|
|
var SysSensorlist = _sensorService.GeSysSensor();
|
|
|
|
|
|
|
2024-06-13 10:17:25 +00:00
|
|
|
|
//日志列表清单数据
|
2024-05-20 10:46:43 +00:00
|
|
|
|
int index = 0;
|
|
|
|
|
|
foreach (var item in Loglist)
|
|
|
|
|
|
{
|
|
|
|
|
|
index++;
|
|
|
|
|
|
loglist.Add(new LogModel
|
|
|
|
|
|
{
|
|
|
|
|
|
DataIdNum = index + (PaginationModel.PageIndex - 1) * PaginationModel.PageSize,
|
|
|
|
|
|
CreateTime = item.CreateTime,
|
|
|
|
|
|
Remark = item.Remark
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-13 10:17:25 +00:00
|
|
|
|
//传感器电源开关数据
|
2024-05-20 10:46:43 +00:00
|
|
|
|
if (SysSensorlist.Count() != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var data = _sensorService.GeSysSensor().FirstOrDefault();
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id = data.Id;
|
|
|
|
|
|
sysSensorModel.CreateTime = sysSensorModels.CreateTime = data.CreateTime;
|
|
|
|
|
|
sysSensorModel.InComputer = sysSensorModels.InComputer = data.InComputer;
|
2024-06-12 10:17:01 +00:00
|
|
|
|
sysSensorModel.CMSpectrometry = sysSensorModels.CMSpectrometry = data.CMSpectrometry;
|
2024-05-20 10:46:43 +00:00
|
|
|
|
sysSensorModel.Light1 = sysSensorModels.Light1 = data.Light1;
|
|
|
|
|
|
sysSensorModel.Light2 = sysSensorModels.Light2 = data.Light2;
|
|
|
|
|
|
sysSensorModel.LightMachine = sysSensorModels.LightMachine = data.LightMachine;
|
|
|
|
|
|
sysSensorModel.ADCP = sysSensorModels.ADCP = data.ADCP;
|
|
|
|
|
|
sysSensorModel.CTD = sysSensorModels.CTD = data.CTD;
|
|
|
|
|
|
sysSensorModel.SP = sysSensorModels.SP = data.SP;
|
|
|
|
|
|
sysSensorModel.CH4 = sysSensorModels.CH4 = data.CH4;
|
|
|
|
|
|
sysSensorModel.CO2 = sysSensorModels.CO2 = data.CO2;
|
|
|
|
|
|
sysSensorModel.NetEquipment = sysSensorModels.NetEquipment = data.NetEquipment;
|
|
|
|
|
|
sysSensorModel.SerialPortServer = sysSensorModels.SerialPortServer = data.SerialPortServer;
|
|
|
|
|
|
sysSensorModel.RamanAnalyzer = sysSensorModels.RamanAnalyzer = data.RamanAnalyzer;
|
|
|
|
|
|
sysSensorModel.ZP = sysSensorModels.ZP = data.ZP;
|
|
|
|
|
|
sysSensorModel.AcousticPositioning = sysSensorModels.AcousticPositioning = data.AcousticPositioning;
|
|
|
|
|
|
sysSensorModel.Camera1 = sysSensorModels.Camera1 = data.Camera1;
|
|
|
|
|
|
sysSensorModel.Camera2 = sysSensorModels.Camera2 = data.Camera2;
|
|
|
|
|
|
sysSensorModel.ElectricSwitch2 = sysSensorModels.ElectricSwitch2 = data.ElectricSwitch2;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 刷新分页组件的页码
|
|
|
|
|
|
PaginationModel.FillPageNumbers(totalCount);
|
2024-05-17 10:37:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-20 10:46:43 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 通信连接
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="o"></param>
|
2024-05-17 10:37:55 +00:00
|
|
|
|
public override void DoConnection(object o)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (clientModel.IsConnected)
|
|
|
|
|
|
{
|
2024-05-20 10:46:43 +00:00
|
|
|
|
clientModel.DisConnect();
|
|
|
|
|
|
SocketInfo.ConnectionMessage = "连接";
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
2024-05-22 10:37:51 +00:00
|
|
|
|
logModel.Remark = "服务端连接已关闭";
|
2024-05-20 10:46:43 +00:00
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
this.Refresh();
|
2024-05-17 10:37:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-05-20 10:46:43 +00:00
|
|
|
|
if (clientModel.DoConnect(SocketInfo))
|
2024-05-17 10:37:55 +00:00
|
|
|
|
{
|
2024-05-20 10:46:43 +00:00
|
|
|
|
//更新下App.config中的配置信息
|
|
|
|
|
|
tools.UpdateAppSettings("IP", SocketInfo.IP);
|
|
|
|
|
|
tools.UpdateAppSettings("Port", SocketInfo.Port.ToString());
|
|
|
|
|
|
SocketInfo.ConnectionMessage = "断开";
|
2024-05-17 10:37:55 +00:00
|
|
|
|
|
2024-05-20 10:46:43 +00:00
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
2024-05-22 10:37:51 +00:00
|
|
|
|
logModel.Remark = "连接服务端成功";
|
2024-05-20 10:46:43 +00:00
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
this.Refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
2024-05-22 10:37:51 +00:00
|
|
|
|
logModel.Remark = "连接服务端失败";
|
2024-05-20 10:46:43 +00:00
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
this.Refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-17 10:37:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-12 10:17:01 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 电源开关控制
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="o"></param>
|
2024-05-20 10:46:43 +00:00
|
|
|
|
public void DoRelay(object o)
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] msg = o.ToString().Split(',');
|
|
|
|
|
|
int switchNum = msg[1].Equals("True") ? 1 : 0;
|
|
|
|
|
|
string MessageContent = "";
|
|
|
|
|
|
switch (msg[0])
|
|
|
|
|
|
{
|
|
|
|
|
|
//工控机
|
|
|
|
|
|
case "InComputer":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.InComputer = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "工控机已" + sysSensorModel.InComputer;
|
|
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.InComputer == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
Control(0x00, 0x01);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Control(0x00, 0x00);
|
2024-06-12 10:17:01 +00:00
|
|
|
|
}
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
|
|
|
|
|
break;
|
|
|
|
|
|
//色质联用
|
|
|
|
|
|
case "CMSpectrometry":
|
|
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.CMSpectrometry = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "色质联用已" + sysSensorModel.CMSpectrometry;
|
2024-05-22 10:37:51 +00:00
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
2024-06-12 10:17:01 +00:00
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.CMSpectrometry == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
Control(0x01, 0x01);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Control(0x01, 0x00);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
|
|
|
|
|
//_logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
2024-05-20 10:46:43 +00:00
|
|
|
|
this.Refresh();
|
|
|
|
|
|
break;
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//备用串口1
|
2024-05-20 10:46:43 +00:00
|
|
|
|
case "Light1":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.Light1 = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
2024-06-12 10:17:01 +00:00
|
|
|
|
logModel.Remark = "备用串口1已" + sysSensorModel.Light1;
|
2024-05-22 10:37:51 +00:00
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.Light1 == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x02, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x02, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//_logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//备用串口2
|
2024-05-20 10:46:43 +00:00
|
|
|
|
case "Light2":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.Light2 = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
2024-06-12 10:17:01 +00:00
|
|
|
|
logModel.Remark = "备用串口2已" + sysSensorModel.Light2;
|
2024-05-22 10:37:51 +00:00
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.Light2 == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x03, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x03, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
// _logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
//光通讯机
|
|
|
|
|
|
case "LightMachine":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.LightMachine = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "光通讯机已" + sysSensorModel.LightMachine;
|
|
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.LightMachine == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x04, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x04, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//_logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
//ADCP
|
|
|
|
|
|
case "ADCP":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.ADCP = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "ADCP已" + sysSensorModel.ADCP;
|
|
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.ADCP == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x05, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x05, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//_logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
//CTD
|
|
|
|
|
|
case "CTD":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.CTD = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "CTD已" + sysSensorModel.CTD;
|
|
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.CTD == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x06, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x06, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//_logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
//气相色谱仪
|
|
|
|
|
|
case "SP":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.SP = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "气相色谱仪已" + sysSensorModel.SP;
|
|
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.SP == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x07, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x07, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//_logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
//甲烷传感器
|
|
|
|
|
|
case "CH4":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.CH4 = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "甲烷传感器已" + sysSensorModel.CH4;
|
|
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.CH4 == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x08, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x08, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//_logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
//二氧化碳同位素分析仪
|
|
|
|
|
|
case "CO2":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.CO2 = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "二氧化碳同位素分析仪已" + sysSensorModel.CO2;
|
|
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.CO2 == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x09, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x09, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//_logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
//备用网口设备
|
|
|
|
|
|
case "NetEquipment":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.NetEquipment = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "备用网口设备已" + sysSensorModel.NetEquipment;
|
|
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.NetEquipment == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x0a, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x0a, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//_logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//ICL
|
2024-05-20 10:46:43 +00:00
|
|
|
|
case "SerialPortServer":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.SerialPortServer = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
2024-06-12 10:17:01 +00:00
|
|
|
|
logModel.Remark = "ICL已" + sysSensorModel.SerialPortServer;
|
2024-05-22 10:37:51 +00:00
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.SerialPortServer == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x0b, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x0b, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//_logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
//显微拉曼分析仪
|
|
|
|
|
|
case "RamanAnalyzer":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.RamanAnalyzer = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "显微拉曼分析仪已" + sysSensorModel.RamanAnalyzer;
|
|
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.RamanAnalyzer == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x0c, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x0c, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//_logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
//质谱仪
|
|
|
|
|
|
case "ZP":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.ZP = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "质谱仪已" + sysSensorModel.ZP;
|
|
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.ZP == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x0d, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x0d, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//_logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
// 声学定位
|
|
|
|
|
|
case "AcousticPositioning":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.AcousticPositioning = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "声学定位已" + sysSensorModel.AcousticPositioning;
|
|
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.AcousticPositioning == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x0e, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x0e, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//_logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
//摄像1
|
|
|
|
|
|
case "Camera1":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.Camera1 = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "摄像1已" + sysSensorModel.Camera1;
|
|
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.Camera1 == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x0f, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x0f, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
// _logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
//摄像2
|
|
|
|
|
|
case "Camera2":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.Camera2 = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "摄像2已" + sysSensorModel.Camera2;
|
|
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.Camera2 == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x10, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x10, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
// _logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
//电交换机2
|
|
|
|
|
|
case "ElectricSwitch2":
|
2024-05-22 10:37:51 +00:00
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
sysSensorModel.Id = sysSensorModels.Id;
|
|
|
|
|
|
sysSensorModel.ElectricSwitch2 = msg[1].Equals("True") ? "开" : "关";
|
|
|
|
|
|
sysSensorModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
_sensorService.Update(sysSensorModel);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "电交换机2已" + sysSensorModel.ElectricSwitch2;
|
|
|
|
|
|
_logService.Insert<LogModel>(logModel);
|
|
|
|
|
|
|
|
|
|
|
|
if (sysSensorModel.ElectricSwitch2 == "开")
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x11, 0x01);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-06-12 10:17:01 +00:00
|
|
|
|
Control(0x11, 0x00);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
2024-06-12 10:17:01 +00:00
|
|
|
|
//_logService.Insert<LogModel>(logModel);
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
this.Refresh();
|
2024-05-20 10:46:43 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2024-05-22 10:37:51 +00:00
|
|
|
|
}
|
2024-05-20 10:46:43 +00:00
|
|
|
|
|
2024-05-22 10:37:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 远程控制
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="kind"> 传感器识别码</param>
|
|
|
|
|
|
/// <param name="operation">操作</param>
|
|
|
|
|
|
private void Control(byte kind, byte operation)
|
|
|
|
|
|
{
|
|
|
|
|
|
//标志位
|
|
|
|
|
|
byte head = 0x7f;
|
|
|
|
|
|
//crc
|
|
|
|
|
|
byte nr_crc = 0;
|
|
|
|
|
|
//消息体
|
|
|
|
|
|
byte[] byteaq = new byte[] { 0x92, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x02, kind, operation };
|
|
|
|
|
|
|
|
|
|
|
|
nr_crc = tools.CRC(byteaq.ToArray(), 0, byteaq.Length);
|
|
|
|
|
|
|
|
|
|
|
|
///转义
|
|
|
|
|
|
int j = 0;
|
|
|
|
|
|
List<byte> 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<byte> buffer = new List<byte>();
|
|
|
|
|
|
buffer.Add(head);
|
|
|
|
|
|
for (int i = 0; i < newSendBuffer.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
buffer.Add(newSendBuffer[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
buffer.Add(head);
|
2024-05-20 10:46:43 +00:00
|
|
|
|
|
2024-05-22 10:37:51 +00:00
|
|
|
|
string list = tools.byteToHexStr(buffer.ToArray());
|
|
|
|
|
|
byte[] bytea = tools.ConvertHexStringToBytes(list);
|
|
|
|
|
|
clientModel.SendData(bytea);
|
2024-05-20 10:46:43 +00:00
|
|
|
|
}
|
2024-05-22 10:37:51 +00:00
|
|
|
|
|
2024-06-12 10:17:01 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 一键还原
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public override void DoReduction()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
List<string> data = new List<string>();
|
|
|
|
|
|
//从数据库中取出集合
|
|
|
|
|
|
var SysSensorlist = _sensorService.GeSysSensor();
|
|
|
|
|
|
foreach (var item in SysSensorlist)
|
|
|
|
|
|
{
|
|
|
|
|
|
#region 逻辑判断 判断值为开的,增加到data集合中
|
|
|
|
|
|
if (item.InComputer == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("工控机");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.CMSpectrometry == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("色质联用");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.Light1 == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("备用串口1");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.Light2 == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("备用串口2");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.LightMachine == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("光通讯机");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.ADCP == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("ADCP");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.CTD == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("CTD");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.SP == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("SP");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.CH4 == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("CH4");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.CO2 == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("CO2");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.NetEquipment == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("备用网口设备");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.SerialPortServer == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("ICL");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.RamanAnalyzer == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("显微拉曼分析仪");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.ZP == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("质谱仪");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.AcousticPositioning == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("声学定位");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.Camera1 == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("摄像1");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.Camera2 == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("摄像2");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (item.ElectricSwitch2 == "开")
|
|
|
|
|
|
{
|
|
|
|
|
|
data.Add("电交换机2");
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
string opendata = "";
|
|
|
|
|
|
for (int i = 0; i < data.Count(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
opendata += data[i];
|
|
|
|
|
|
opendata = opendata + "、";
|
|
|
|
|
|
}
|
2024-06-22 03:33:16 +00:00
|
|
|
|
DialogResult s1= System.Windows.Forms.MessageBox.Show("当前处于打开状态的设备有" + opendata + "确认需要一键还原且进行强制关闭吗?", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
|
|
|
|
|
|
if (s1 == DialogResult.Yes)
|
2024-06-12 10:17:01 +00:00
|
|
|
|
{
|
2024-06-22 03:33:16 +00:00
|
|
|
|
//消息体
|
|
|
|
|
|
//强制关闭
|
|
|
|
|
|
byte[] byteaq = new byte[] { 0x93, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01 };
|
2024-06-12 10:17:01 +00:00
|
|
|
|
|
2024-06-22 03:33:16 +00:00
|
|
|
|
List<byte> buffer = Escape(byteaq);
|
|
|
|
|
|
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>(logModel);
|
|
|
|
|
|
this.Refresh();
|
2024-06-12 10:17:01 +00:00
|
|
|
|
|
2024-06-22 03:33:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (s1 == DialogResult.No)
|
|
|
|
|
|
{
|
|
|
|
|
|
//非强制关闭
|
|
|
|
|
|
byte[] byteaq = new byte[] { 0x93, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
|
|
|
|
|
|
|
|
List<byte> buffer = Escape(byteaq);
|
|
|
|
|
|
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>(logModel);
|
|
|
|
|
|
this.Refresh();
|
2024-06-12 10:17:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
|
|
|
|
|
}
|
2024-06-22 03:33:16 +00:00
|
|
|
|
|
2024-06-12 10:17:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 一键启动
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public override void DoStart()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (SocketInfo.ConnectionMessage == "断开")
|
|
|
|
|
|
{
|
|
|
|
|
|
if (System.Windows.Forms.MessageBox.Show("确定一键启动吗?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
|
|
|
|
|
|
{
|
|
|
|
|
|
//消息体
|
|
|
|
|
|
byte[] byteaq = new byte[] { 0x93, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
|
|
|
2024-06-17 10:12:16 +00:00
|
|
|
|
List<byte> buffer = Escape(byteaq);
|
2024-06-12 10:17:01 +00:00
|
|
|
|
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>(logModel);
|
|
|
|
|
|
this.Refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
|
|
|
logModel = new LogModel();
|
|
|
|
|
|
logModel.CreateTime = DateTime.Now;
|
|
|
|
|
|
logModel.Remark = "服务端未连接";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-13 10:17:25 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 时间同步
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public override void DoSynchronization()
|
|
|
|
|
|
{
|
|
|
|
|
|
ulong senddate;
|
|
|
|
|
|
ulong year;
|
|
|
|
|
|
ulong month;
|
|
|
|
|
|
ulong day;
|
|
|
|
|
|
ulong hour;
|
|
|
|
|
|
ulong min;
|
|
|
|
|
|
ulong sec;
|
|
|
|
|
|
|
|
|
|
|
|
//定义消息体数组
|
|
|
|
|
|
byte[] byteaq = new byte[16];
|
|
|
|
|
|
DateTime dateTime = DateTime.Now;
|
2024-06-19 02:19:37 +00:00
|
|
|
|
year = (ulong)dateTime.Year * 10000000000UL;
|
|
|
|
|
|
month = (ulong)dateTime.Month * 100000000UL;
|
|
|
|
|
|
day = (ulong)dateTime.Day * 1000000UL;
|
|
|
|
|
|
hour = (ulong)dateTime.Hour * 10000UL;
|
|
|
|
|
|
min = (ulong)dateTime.Minute * 100UL;
|
|
|
|
|
|
sec = (ulong)dateTime.Second;
|
|
|
|
|
|
senddate = year + month + day + hour + min + sec;
|
2024-06-13 10:17:25 +00:00
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
2024-06-17 10:12:16 +00:00
|
|
|
|
List<byte> buffer = Escape(byteaq);
|
|
|
|
|
|
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>(logModel);
|
|
|
|
|
|
this.Refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 转义封装
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="bytes"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public List<byte> Escape(byte[] bytes)
|
|
|
|
|
|
{
|
2024-06-13 10:17:25 +00:00
|
|
|
|
//标志位
|
|
|
|
|
|
byte head = 0x7f;
|
|
|
|
|
|
//crc
|
|
|
|
|
|
byte nr_crc = 0;
|
2024-06-17 10:12:16 +00:00
|
|
|
|
nr_crc = tools.CRC(bytes.ToArray(), 0, bytes.Length);
|
2024-06-13 10:17:25 +00:00
|
|
|
|
|
|
|
|
|
|
///转义
|
|
|
|
|
|
int j = 0;
|
2024-06-17 10:12:16 +00:00
|
|
|
|
List<byte> tBuffer = bytes.ToList();
|
2024-06-13 10:17:25 +00:00
|
|
|
|
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<byte> buffer = new List<byte>();
|
|
|
|
|
|
buffer.Add(head);
|
|
|
|
|
|
for (int i = 0; i < newSendBuffer.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
buffer.Add(newSendBuffer[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
buffer.Add(head);
|
|
|
|
|
|
|
2024-06-17 10:12:16 +00:00
|
|
|
|
return buffer;
|
2024-06-13 10:17:25 +00:00
|
|
|
|
}
|
2024-05-17 10:37:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|