传感器电源开关数据绑定及下发
This commit is contained in:
parent
a6bcd7eae7
commit
52021c9ef7
49
InSituLaboratory.Entities/DataParsingModelSqlSugar.cs
Normal file
49
InSituLaboratory.Entities/DataParsingModelSqlSugar.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using LiveCharts.Wpf;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace InSituLaboratory.Entities
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 数据解析通用字段
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("DataParsingModel")]
|
||||||
|
public class DataParsingModelSqlSugar
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 主键
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnName = "Id", IsIdentity = true, IsPrimaryKey = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建时间
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public DateTime CreateTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 应答流水号
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public string? ResponseNum { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 应答ID
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public string? ResponseID { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 应答结果
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public string? ResponseResult { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
|
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
|
||||||
|
<PackageReference Include="SqlSugarCore" Version="5.1.4.156" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -331,6 +331,51 @@ namespace InSituLaboratory.Entities
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 字节数组转16进制字符串
|
||||||
|
/// <summary>
|
||||||
|
/// 字节数组转16进制字符串
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bytes"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string byteToHexStr(byte[] bytes)
|
||||||
|
{
|
||||||
|
string returnStr = "";
|
||||||
|
if (bytes != null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < bytes.Length; i++)
|
||||||
|
{
|
||||||
|
returnStr += bytes[i].ToString("X2");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnStr;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 16进制原码字符串转字节数组
|
||||||
|
/// <summary>
|
||||||
|
/// 16进制原码字符串转字节数组
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hexString">"AABBCC"或"AA BB CC"格式的字符串</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static byte[] ConvertHexStringToBytes(string hexString)
|
||||||
|
{
|
||||||
|
hexString = hexString.Replace(" ", "");
|
||||||
|
if (hexString.Length % 2 != 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("参数长度不正确");
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] returnBytes = new byte[hexString.Length / 2];
|
||||||
|
for (int i = 0; i < returnBytes.Length; i++)
|
||||||
|
{
|
||||||
|
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnBytes;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region 根据1/0 转换 True/False
|
#region 根据1/0 转换 True/False
|
||||||
public static List<bool> O_C(string o_c)
|
public static List<bool> O_C(string o_c)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -5,9 +5,7 @@
|
|||||||
</startup>
|
</startup>
|
||||||
<!--数据库连接信息-->
|
<!--数据库连接信息-->
|
||||||
<connectionStrings>
|
<connectionStrings>
|
||||||
<add name="db" connectionString="server=127.0.0.1;port=3306;user=root;password=zttZTT1234;database=0592_fjdzgcw_fbhcj;Allow User Variables=True;" />
|
<add name="db" connectionString="Data Source=data.db" />
|
||||||
<!--<add name="db" connectionString="server=10.8.2.5;port=3306;user=root;password=zttZTT123!;database=0592_fjdzgcw_fbhcj;Allow User Variables=True;" />-->
|
|
||||||
<add name="db_Sever" connectionString="server=110.42.244.149;port=3306;user=root;password=rootme;database=0592_fjdzgcw_fbhcj;Allow User Variables=True;" />
|
|
||||||
</connectionStrings>
|
</connectionStrings>
|
||||||
<appSettings>
|
<appSettings>
|
||||||
<!--文件保存路劲-->
|
<!--文件保存路劲-->
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using InSituLaboratory.Entities;
|
using InSituLaboratory.Entities;
|
||||||
using InSituLaboratory.Service;
|
using InSituLaboratory.Service;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using SqlSugar;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -14,10 +15,10 @@ namespace InSituLaboratory.Common
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class DataParsing
|
public class DataParsing
|
||||||
{
|
{
|
||||||
|
//连接钥匙
|
||||||
|
private static readonly string ConnStr = System.Configuration.ConfigurationManager.ConnectionStrings["db"].ConnectionString;
|
||||||
|
|
||||||
//public DataParsing() { }
|
public DataParsingModelSqlSugar dataParsingModel = new DataParsingModelSqlSugar();
|
||||||
|
|
||||||
public DataParsingModel dataParsingModel = new DataParsingModel();
|
|
||||||
|
|
||||||
//获取当前程序运行路径
|
//获取当前程序运行路径
|
||||||
private string Save_Path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"数据记录\";
|
private string Save_Path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"数据记录\";
|
||||||
@ -26,7 +27,7 @@ namespace InSituLaboratory.Common
|
|||||||
public static DateTime Record_firstCode = DateTime.Now;
|
public static DateTime Record_firstCode = DateTime.Now;
|
||||||
|
|
||||||
//标志位头
|
//标志位头
|
||||||
string flag = "7f";
|
byte flag = 0x7f;
|
||||||
|
|
||||||
//应答流水号
|
//应答流水号
|
||||||
string ResponseNum = "";
|
string ResponseNum = "";
|
||||||
@ -58,6 +59,14 @@ namespace InSituLaboratory.Common
|
|||||||
|
|
||||||
tools.AddLgoToTXT("原始数据报文.txt", Save_Path + System.DateTime.Now.ToString("yyyy_MM_dd") + @"\", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ---- " + NR_TXT + "\r\n");
|
tools.AddLgoToTXT("原始数据报文.txt", Save_Path + System.DateTime.Now.ToString("yyyy_MM_dd") + @"\", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ---- " + NR_TXT + "\r\n");
|
||||||
|
|
||||||
|
//SqlSugar配置文件
|
||||||
|
ConnectionConfig connectionConfig = new ConnectionConfig()
|
||||||
|
{
|
||||||
|
ConnectionString = ConnStr,
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
DbType = DbType.Sqlite
|
||||||
|
};
|
||||||
|
|
||||||
//转义
|
//转义
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (int i = 0; i < byteList.Count; i++)
|
for (int i = 0; i < byteList.Count; i++)
|
||||||
@ -89,19 +98,26 @@ namespace InSituLaboratory.Common
|
|||||||
|
|
||||||
//定义转义后的list数组
|
//定义转义后的list数组
|
||||||
List<byte> dataNew = new List<byte>();
|
List<byte> dataNew = new List<byte>();
|
||||||
|
|
||||||
string Latter_TXT = "";
|
string Latter_TXT = "";
|
||||||
for (int i = 0; i < dataTemp.Length; i++)
|
for (int i = 0; i < dataTemp.Length; i++)
|
||||||
{
|
{
|
||||||
dataNew.Add(dataTemp[i]);
|
dataNew.Add(dataTemp[i]);
|
||||||
Latter_TXT += dataTemp[i].ToString("X2") + " ";
|
Latter_TXT += dataTemp[i].ToString("X2") + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//数据域数组
|
||||||
|
List<byte> bytes = new List<byte>();
|
||||||
|
for (int i = 1; i < dataTemp.Length - 2; i++)
|
||||||
|
{
|
||||||
|
bytes.Add(dataTemp[i]);
|
||||||
|
}
|
||||||
|
|
||||||
tools.AddLgoToTXT("转义后数据报文.txt", Save_Path + System.DateTime.Now.ToString("yyyy_MM_dd") + @"\", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ---- " + Latter_TXT + "\r\n");
|
tools.AddLgoToTXT("转义后数据报文.txt", Save_Path + System.DateTime.Now.ToString("yyyy_MM_dd") + @"\", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ---- " + Latter_TXT + "\r\n");
|
||||||
|
|
||||||
nr_crc = tools.CRC(dataNew.ToArray(), 0, dataNew.Count - 1);
|
nr_crc = tools.CRC(bytes.ToArray(), 0, bytes.Count);
|
||||||
|
|
||||||
///包头包尾 crc校验
|
///包头包尾 crc校验
|
||||||
if (((dataNew[0].ToString("X2") != flag) || (dataNew[byteList.Count - 1].ToString("X2")) != flag) || dataNew[14] != nr_crc)
|
if (((dataNew[0] != flag) || (dataNew[byteList.Count - 1]) != flag) || dataNew[14] != nr_crc)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
@ -112,26 +128,37 @@ namespace InSituLaboratory.Common
|
|||||||
//应答流水号
|
//应答流水号
|
||||||
dataParsingModel.ResponseNum = dataNew[9].ToString("X2") + dataNew[10].ToString("X2");
|
dataParsingModel.ResponseNum = dataNew[9].ToString("X2") + dataNew[10].ToString("X2");
|
||||||
//应答ID
|
//应答ID
|
||||||
dataParsingModel.ResponseID = dataNew[11].ToString("X2") + dataNew[12].ToString("X2");
|
if (dataNew[11].ToString("X2") + dataNew[12].ToString("X2") == "9100")
|
||||||
//结果
|
|
||||||
switch (dataNew[13].ToString("X2"))
|
|
||||||
{
|
{
|
||||||
case "0":
|
dataParsingModel.ResponseID = "9100-时序下发";
|
||||||
|
}
|
||||||
|
else if (dataNew[11].ToString("X2") + dataNew[12].ToString("X2") == "9201")
|
||||||
|
{
|
||||||
|
dataParsingModel.ResponseID = "9201-局部控制开关";
|
||||||
|
}
|
||||||
|
//结果
|
||||||
|
switch (dataNew[13])
|
||||||
|
{
|
||||||
|
case 0x00:
|
||||||
dataParsingModel.ResponseResult = "成功/确认";
|
dataParsingModel.ResponseResult = "成功/确认";
|
||||||
break;
|
break;
|
||||||
case "1":
|
case 0x01:
|
||||||
dataParsingModel.ResponseResult = "失败/不存在";
|
dataParsingModel.ResponseResult = "失败/不存在";
|
||||||
break;
|
break;
|
||||||
case "2":
|
case 0x02:
|
||||||
dataParsingModel.ResponseResult = "消息错误";
|
dataParsingModel.ResponseResult = "消息错误";
|
||||||
break;
|
break;
|
||||||
case "3":
|
case 0x03:
|
||||||
dataParsingModel.ResponseResult = "不支持";
|
dataParsingModel.ResponseResult = "不支持";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//this.Insert<DataParsingModel>(dataParsingModel);
|
|
||||||
|
using (SqlSugarClient db = new SqlSugarClient(connectionConfig))
|
||||||
|
{
|
||||||
|
db.Insertable<DataParsingModelSqlSugar>(dataParsingModel).ExecuteCommand();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
<PackageReference Include="HandyControl" Version="3.5.1" />
|
<PackageReference Include="HandyControl" Version="3.5.1" />
|
||||||
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
|
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
|
||||||
<PackageReference Include="Prism.Unity" Version="8.1.97" />
|
<PackageReference Include="Prism.Unity" Version="8.1.97" />
|
||||||
|
<PackageReference Include="SqlSugarCore" Version="5.1.4.156" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -15,6 +15,9 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.Windows.Markup;
|
||||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||||
|
|
||||||
namespace InSituLaboratory.ViewModels.Pages
|
namespace InSituLaboratory.ViewModels.Pages
|
||||||
@ -125,7 +128,7 @@ namespace InSituLaboratory.ViewModels.Pages
|
|||||||
SocketInfo.ConnectionMessage = "连接";
|
SocketInfo.ConnectionMessage = "连接";
|
||||||
logModel = new LogModel();
|
logModel = new LogModel();
|
||||||
logModel.CreateTime = DateTime.Now;
|
logModel.CreateTime = DateTime.Now;
|
||||||
logModel.Remark = "客户端连接已关闭";
|
logModel.Remark = "服务端连接已关闭";
|
||||||
_logService.Insert<LogModel>(logModel);
|
_logService.Insert<LogModel>(logModel);
|
||||||
this.Refresh();
|
this.Refresh();
|
||||||
}
|
}
|
||||||
@ -140,7 +143,7 @@ namespace InSituLaboratory.ViewModels.Pages
|
|||||||
|
|
||||||
logModel = new LogModel();
|
logModel = new LogModel();
|
||||||
logModel.CreateTime = DateTime.Now;
|
logModel.CreateTime = DateTime.Now;
|
||||||
logModel.Remark = "连接客户端成功";
|
logModel.Remark = "连接服务端成功";
|
||||||
_logService.Insert<LogModel>(logModel);
|
_logService.Insert<LogModel>(logModel);
|
||||||
this.Refresh();
|
this.Refresh();
|
||||||
}
|
}
|
||||||
@ -148,7 +151,7 @@ namespace InSituLaboratory.ViewModels.Pages
|
|||||||
{
|
{
|
||||||
logModel = new LogModel();
|
logModel = new LogModel();
|
||||||
logModel.CreateTime = DateTime.Now;
|
logModel.CreateTime = DateTime.Now;
|
||||||
logModel.Remark = "连接客户端失败";
|
logModel.Remark = "连接服务端失败";
|
||||||
_logService.Insert<LogModel>(logModel);
|
_logService.Insert<LogModel>(logModel);
|
||||||
this.Refresh();
|
this.Refresh();
|
||||||
}
|
}
|
||||||
@ -165,6 +168,8 @@ namespace InSituLaboratory.ViewModels.Pages
|
|||||||
{
|
{
|
||||||
//工控机
|
//工控机
|
||||||
case "InComputer":
|
case "InComputer":
|
||||||
|
if (SocketInfo.ConnectionMessage == "断开")
|
||||||
|
{
|
||||||
sysSensorModel.Id = sysSensorModels.Id;
|
sysSensorModel.Id = sysSensorModels.Id;
|
||||||
sysSensorModel.InComputer = msg[1].Equals("True") ? "开" : "关";
|
sysSensorModel.InComputer = msg[1].Equals("True") ? "开" : "关";
|
||||||
sysSensorModel.CreateTime = DateTime.Now;
|
sysSensorModel.CreateTime = DateTime.Now;
|
||||||
@ -173,78 +178,611 @@ namespace InSituLaboratory.ViewModels.Pages
|
|||||||
logModel.CreateTime = DateTime.Now;
|
logModel.CreateTime = DateTime.Now;
|
||||||
logModel.Remark = "工控机已" + sysSensorModel.InComputer;
|
logModel.Remark = "工控机已" + sysSensorModel.InComputer;
|
||||||
_logService.Insert<LogModel>(logModel);
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
|
||||||
|
if (sysSensorModel.InComputer == "开")
|
||||||
|
{
|
||||||
|
Control(0x00, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x00, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
this.Refresh();
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
//灯1
|
//灯1
|
||||||
case "Light1":
|
case "Light1":
|
||||||
|
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;
|
||||||
|
logModel.Remark = "灯1已" + sysSensorModel.Light1;
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
|
||||||
|
if (sysSensorModel.Light1 == "开")
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
//灯2
|
//灯2
|
||||||
case "Light2":
|
case "Light2":
|
||||||
|
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;
|
||||||
|
logModel.Remark = "灯2已" + sysSensorModel.Light2;
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
|
||||||
|
if (sysSensorModel.Light2 == "开")
|
||||||
|
{
|
||||||
|
Control(0x02, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x02, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
//光通讯机
|
//光通讯机
|
||||||
case "LightMachine":
|
case "LightMachine":
|
||||||
|
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 == "开")
|
||||||
|
{
|
||||||
|
Control(0x03, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x03, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
//ADCP
|
//ADCP
|
||||||
case "ADCP":
|
case "ADCP":
|
||||||
|
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 == "开")
|
||||||
|
{
|
||||||
|
Control(0x04, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x04, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
//CTD
|
//CTD
|
||||||
case "CTD":
|
case "CTD":
|
||||||
|
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 == "开")
|
||||||
|
{
|
||||||
|
Control(0x05, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x05, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
//气相色谱仪
|
//气相色谱仪
|
||||||
case "SP":
|
case "SP":
|
||||||
|
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 == "开")
|
||||||
|
{
|
||||||
|
Control(0x06, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x06, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
//甲烷传感器
|
//甲烷传感器
|
||||||
case "CH4":
|
case "CH4":
|
||||||
|
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 == "开")
|
||||||
|
{
|
||||||
|
Control(0x07, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x07, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
//二氧化碳同位素分析仪
|
//二氧化碳同位素分析仪
|
||||||
case "CO2":
|
case "CO2":
|
||||||
|
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 == "开")
|
||||||
|
{
|
||||||
|
Control(0x08, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x08, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
//备用网口设备
|
//备用网口设备
|
||||||
case "NetEquipment":
|
case "NetEquipment":
|
||||||
|
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 == "开")
|
||||||
|
{
|
||||||
|
Control(0x09, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x09, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
//串口服务器
|
//串口服务器
|
||||||
case "SerialPortServer":
|
case "SerialPortServer":
|
||||||
|
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;
|
||||||
|
logModel.Remark = "串口服务器已" + sysSensorModel.SerialPortServer;
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
|
||||||
|
if (sysSensorModel.SerialPortServer == "开")
|
||||||
|
{
|
||||||
|
Control(0x0a, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x0a, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
//显微拉曼分析仪
|
//显微拉曼分析仪
|
||||||
case "RamanAnalyzer":
|
case "RamanAnalyzer":
|
||||||
|
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 == "开")
|
||||||
|
{
|
||||||
|
Control(0x0b, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x0b, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
//质谱仪
|
//质谱仪
|
||||||
case "ZP":
|
case "ZP":
|
||||||
|
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 == "开")
|
||||||
|
{
|
||||||
|
Control(0x0c, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x0c, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
// 声学定位
|
// 声学定位
|
||||||
case "AcousticPositioning":
|
case "AcousticPositioning":
|
||||||
|
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 == "开")
|
||||||
|
{
|
||||||
|
Control(0x0d, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x0d, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
//摄像1
|
//摄像1
|
||||||
case "Camera1":
|
case "Camera1":
|
||||||
|
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 == "开")
|
||||||
|
{
|
||||||
|
Control(0x0e, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x0e, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
//摄像2
|
//摄像2
|
||||||
case "Camera2":
|
case "Camera2":
|
||||||
|
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 == "开")
|
||||||
|
{
|
||||||
|
Control(0x0f, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x0f, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
//电交换机2
|
//电交换机2
|
||||||
case "ElectricSwitch2":
|
case "ElectricSwitch2":
|
||||||
|
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 == "开")
|
||||||
|
{
|
||||||
|
Control(0x10, 0x01);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Control(0x10, 0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
logModel = new LogModel();
|
||||||
|
logModel.CreateTime = DateTime.Now;
|
||||||
|
logModel.Remark = "服务端未连接";
|
||||||
|
_logService.Insert<LogModel>(logModel);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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);
|
||||||
|
|
||||||
|
string list = tools.byteToHexStr(buffer.ToArray());
|
||||||
|
byte[] bytea = tools.ConvertHexStringToBytes(list);
|
||||||
|
clientModel.SendData(bytea);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user