|
|
@@ -1,11 +1,11 @@
|
|
|
-using IoTServer.Common;
|
|
|
-using Newtonsoft.Json;
|
|
|
+using Newtonsoft.Json;
|
|
|
using System;
|
|
|
using System.IO.Ports;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
+using YSAI.Modbus.service.Common;
|
|
|
|
|
|
-namespace IoTServer.Servers.Modbus
|
|
|
+namespace YSAI.Modbus.service
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// ModbusAscii 服务端模拟
|
|
|
@@ -62,7 +62,7 @@ namespace IoTServer.Servers.Modbus
|
|
|
|
|
|
byte[] tempData = new byte[requetData.Length - 3];
|
|
|
Buffer.BlockCopy(requetData, 1, tempData, 0, tempData.Length);
|
|
|
- var requetAsciiData = DataConvert.AsciiArrayToByteArray(tempData);
|
|
|
+ var requetAsciiData = tempData.AsciiArrayToByteArray();
|
|
|
|
|
|
var type = $"{requetData[3].ToString("X2")}{requetData[4].ToString("X2")}";
|
|
|
switch (type)
|
|
|
@@ -76,7 +76,7 @@ namespace IoTServer.Servers.Modbus
|
|
|
//没有存储过的数据的,默认响应false
|
|
|
if (bytes == null)
|
|
|
{
|
|
|
- data = DataConvert.StringToByteArray("01 01 01 00");
|
|
|
+ data = "01 01 01 00".StringToByteArray();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -89,13 +89,13 @@ namespace IoTServer.Servers.Modbus
|
|
|
|
|
|
byte[] asciiData = new byte[bytes.Length - 3];
|
|
|
Buffer.BlockCopy(bytes, 1, asciiData, 0, asciiData.Length);
|
|
|
- var byteDataArray = DataConvert.AsciiArrayToByteArray(asciiData);
|
|
|
+ var byteDataArray = asciiData.AsciiArrayToByteArray();
|
|
|
|
|
|
//true
|
|
|
if (byteDataArray[4].ToString("X2") == "FF" && byteDataArray[5].ToString("X2") == "00")
|
|
|
- data = DataConvert.StringToByteArray("01 01 01 01");
|
|
|
+ data = "01 01 01 01".StringToByteArray();
|
|
|
else//false
|
|
|
- data = DataConvert.StringToByteArray("01 01 01 00");
|
|
|
+ data = "01 01 01 00".StringToByteArray();
|
|
|
}
|
|
|
|
|
|
var dataString = string.Join("", LRC.GetLRC(data).Select(t => t.ToString("X2")));
|
|
|
@@ -138,7 +138,7 @@ namespace IoTServer.Servers.Modbus
|
|
|
|
|
|
byte[] asciiData = new byte[bytes.Length - 3];
|
|
|
Buffer.BlockCopy(bytes, 1, asciiData, 0, asciiData.Length);
|
|
|
- var byteDataArray = DataConvert.AsciiArrayToByteArray(asciiData);
|
|
|
+ var byteDataArray = asciiData.AsciiArrayToByteArray();
|
|
|
data = new byte[byteDataArray[6] + 3];
|
|
|
data[2] = byteDataArray[6];//数据长度
|
|
|
Buffer.BlockCopy(byteDataArray, 7, data, 3, data.Length - 3);
|