diff --git a/NDSD-Screwdriver/NDSD_Screwdriver.csproj b/NDSD-Screwdriver/NDSD_Screwdriver.csproj
index a810930..e74ae0e 100644
--- a/NDSD-Screwdriver/NDSD_Screwdriver.csproj
+++ b/NDSD-Screwdriver/NDSD_Screwdriver.csproj
@@ -39,9 +39,6 @@
..\packages\Chloe.SQLite.5.26.0\lib\net46\Chloe.SQLite.dll
-
- ..\Dll\log4net.dll
-
@@ -50,9 +47,6 @@
..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll
-
- ..\Dll\nmodbuspc.dll
-
..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll
@@ -94,10 +88,13 @@
- ..\packages\TouchSocket.2.1.0-rc.10\lib\net472\TouchSocket.dll
+ ..\packages\TouchSocket.2.1.0-rc.11\lib\net472\TouchSocket.dll
- ..\packages\TouchSocket.Core.2.1.0-rc.10\lib\net472\TouchSocket.Core.dll
+ ..\packages\TouchSocket.Core.2.1.0-rc.11\lib\net472\TouchSocket.Core.dll
+
+
+ ..\packages\TouchSocket.SerialPorts.2.1.0-rc.11\lib\net472\TouchSocket.SerialPorts.dll
@@ -125,8 +122,7 @@
-
-
+
FrmSetting.cs
@@ -185,7 +181,7 @@
-
+
\ No newline at end of file
diff --git a/NDSD-Screwdriver/Tool/HFIIREADER_PARAMS.cs b/NDSD-Screwdriver/Tool/HFIIREADER_PARAMS.cs
deleted file mode 100644
index d58f1b5..0000000
--- a/NDSD-Screwdriver/Tool/HFIIREADER_PARAMS.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-using System.Runtime.InteropServices;
-
-namespace NDSD_Screwdriver.Tool
-{
-
-// Token: 0x02000002 RID: 2
- [StructLayout(LayoutKind.Sequential, Pack = 4)]
- public struct HFIIREADER_PARAMS
- {
- // Token: 0x04000001 RID: 1
- public ushort addr;
-
- // Token: 0x04000002 RID: 2
- public ushort br;
-
- // Token: 0x04000003 RID: 3
- public ushort afiMode;
-
- // Token: 0x04000004 RID: 4
- public ushort invtTo;
-
- // Token: 0x04000005 RID: 5
- public ushort trgMode;
-
- // Token: 0x04000006 RID: 6
- public ushort opTagMode;
-
- // Token: 0x04000007 RID: 7
- public ushort opBlockRegAddr;
-
- // Token: 0x04000008 RID: 8
- public ushort opBlockRegNum;
-
- // Token: 0x04000009 RID: 9
- public ushort trgTimerTick;
-
- // Token: 0x0400000A RID: 10
- public ushort opFormat;
-
- // Token: 0x0400000B RID: 11
- public ushort frameHead;
-
- // Token: 0x0400000C RID: 12
- public ushort keppTimer;
-
- // Token: 0x0400000D RID: 13
- public ushort tagType;
- }
-}
\ No newline at end of file
diff --git a/NDSD-Screwdriver/Tool/MyFixedHeaderRequestInfo.cs b/NDSD-Screwdriver/Tool/MyFixedHeaderRequestInfo.cs
new file mode 100644
index 0000000..1fac589
--- /dev/null
+++ b/NDSD-Screwdriver/Tool/MyFixedHeaderRequestInfo.cs
@@ -0,0 +1,83 @@
+using NewLife;
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using TouchSocket.Core;
+
+namespace NDSD_Screwdriver.Tool
+{
+ public class MyFixedHeaderRequestInfo : IFixedHeaderRequestInfo
+ {
+ ///
+ /// 接口实现,标识数据长度
+ ///
+ public int BodyLength { get; private set; }
+
+ ///
+ /// 自定义属性,标识数据类型
+ ///
+ public byte DataType { get; set; }
+
+ ///
+ /// 自定义属性,标识指令类型
+ ///
+ public byte OrderType { get; set; }
+
+ ///
+ /// 自定义属性,标识实际数据
+ ///
+ public byte[] Body { get; set; }
+
+
+ public string GetBody()
+ {
+
+ // 方法1: 使用 Array.Copy
+ byte[] copiedBytes = new byte[BodyLength - 2];
+ Array.Copy(Body, 0, copiedBytes, 0, BodyLength - 2);
+ Array.Reverse(copiedBytes);
+ return copiedBytes.ToHex();
+ }
+
+
+ public bool OnParsingBody(ReadOnlySpan body)
+ {
+ if (body.Length == this.BodyLength)
+ {
+ this.Body = body.ToArray();
+ return true;
+ }
+ return false;
+ }
+
+ public bool OnParsingHeader(ReadOnlySpan header)
+ {
+ //在该示例中,第一个字节表示后续的所有数据长度,但是header设置的是3,所以后续还应当接收length-2个长度。
+ this.BodyLength = header[2] + 2;
+ this.DataType = header[0];
+ this.OrderType = header[1];
+ return true;
+ }
+ }
+
+ public class MyFixedHeaderCustomDataHandlingAdapter : CustomFixedHeaderDataHandlingAdapter
+ {
+ ///
+ /// 接口实现,指示固定包头长度
+ ///
+ public override int HeaderLength => 3;
+
+ ///
+ /// 获取新实例
+ ///
+ ///
+ protected override MyFixedHeaderRequestInfo GetInstance()
+ {
+ return new MyFixedHeaderRequestInfo();
+ }
+ }
+}
diff --git a/NDSD-Screwdriver/Tool/SerialPortFactory.cs b/NDSD-Screwdriver/Tool/SerialPortFactory.cs
index ac93982..a15083c 100644
--- a/NDSD-Screwdriver/Tool/SerialPortFactory.cs
+++ b/NDSD-Screwdriver/Tool/SerialPortFactory.cs
@@ -1,60 +1,65 @@
-using System.IO.Ports;
+using System;
+using NewLife.Log;
+using NewLife;
+
+using System.IO.Ports;
+
+using TouchSocket.Core;
+using TouchSocket.SerialPorts;
+using TouchSocket.Sockets;
namespace NDSD_Screwdriver.Tool
{
public class SerialPortFactory
{
- private SerialPort serialPortModbus;
- private hfIIReader reader;
+ SerialPortClient clientSerialPortClient = new SerialPortClient();
+ private IWaitingClient waitClient;
public SerialPortFactory(string portName="COM13")
{
- reader = new hfIIReader();
- serialPortModbus = new SerialPort();
- serialPortModbus.BaudRate = 9600;
- serialPortModbus.PortName = portName;
- serialPortModbus.ReadTimeout = 0;
+ clientSerialPortClient.Connecting = (client, e) => EasyTask.CompletedTask;//即将连接到端口
+ clientSerialPortClient.Connected = (client, e) => { return EasyTask.CompletedTask; };//成功连接到端口
+ clientSerialPortClient.Setup(new TouchSocket.Core.TouchSocketConfig()
+ .SetSerialPortOption(new SerialPortOption()
+ {
+ BaudRate = 115200, //波特率
+ DataBits = 8, //数据位
+ Parity = System.IO.Ports.Parity.None, //校验位
+ PortName = "COM13", //COM
+ StopBits = System.IO.Ports.StopBits.One //停止位
+ }).SetSerialDataHandlingAdapter(() => new MyFixedHeaderCustomDataHandlingAdapter()));
+
+ clientSerialPortClient.Connect();
+
+ waitClient = clientSerialPortClient.CreateWaitingClient(new WaitingOptions()
+ {
+ FilterFunc = response => //设置用于筛选的fun委托,当返回为true时,才会响应返回
+ true
+ });
+
+
+
}
public string Read()
{
-
-
-
-
- if (!serialPortModbus.IsOpen)
+ try
{
- serialPortModbus.Open();
+ ResponsedData responsedData = waitClient.SendThenResponse(new byte[] { 0x00, 0x03, 0x00, 0x50, 0x00, 0x04, 0x45, 0xC9 });
+ IRequestInfo requestInfo = responsedData.RequestInfo;
+ var myFixedHeaderRequestInfo = requestInfo as MyFixedHeaderRequestInfo;
+ return myFixedHeaderRequestInfo.GetBody();
}
-
- var b = reader.Connect(serialPortModbus, 2000, 0);
- string str2 = "";
- ushort[] array6 = reader.ReadTagMemory(ref str2, 28, 4);
-
- string text6 = "";
- for (int j = 0; j < 4; j += 1)
+ catch (Exception e)
{
- text6 += array6[j].ToString("X").PadLeft(4, '0');
- if (text6.Length > 0)
- {
- text6 += "";
- }
+ return "";
}
-
- return text6;
}
- public void Disconnect()
- {
- if (!serialPortModbus.IsOpen)
- {
- serialPortModbus.Close();
- }
- reader.Disconnect();
- }
+
}
diff --git a/NDSD-Screwdriver/Tool/hfIIReader.cs b/NDSD-Screwdriver/Tool/hfIIReader.cs
deleted file mode 100644
index 0eb783d..0000000
--- a/NDSD-Screwdriver/Tool/hfIIReader.cs
+++ /dev/null
@@ -1,1205 +0,0 @@
-using System;
-using System.IO.Ports;
-using System.Net.Sockets;
-using System.Text;
-using System.Threading;
-using Modbus.Device;
-
-namespace NDSD_Screwdriver.Tool
-{
- public class hfIIReader
- {
- // Token: 0x0600000F RID: 15 RVA: 0x000032BC File Offset: 0x000014BC
- public bool Connect(SerialPort serialPort, int timeout, int addr)
- {
- this.ReaderSetComType(0);
- this.master = ModbusSerialMaster.CreateRtu(serialPort);
- bool flag = this.master == null;
- bool result;
- if (flag)
- {
- result = false;
- }
- else
- {
- this.master.Transport.Retries = 1;
- this.master.Transport.ReadTimeout = timeout;
- this.deviceAddr = (byte)addr;
- this.modBusSerialPort = serialPort;
- result = true;
- }
- return result;
- }
-
- // Token: 0x06000010 RID: 16 RVA: 0x0000332C File Offset: 0x0000152C
- public void Disconnect()
- {
- bool flag = this.modBusSerialPort != null;
- if (flag)
- {
- try
- {
- this.modBusSerialPort.Close();
- }
- catch (Exception)
- {
- }
- this.modBusSerialPort = null;
- }
- bool flag2 = this.master != null;
- if (flag2)
- {
- this.master.Dispose();
- this.master = null;
- }
- }
-
- // Token: 0x06000011 RID: 17 RVA: 0x00003398 File Offset: 0x00001598
- private void ClearRxBuffer()
- {
- bool flag = this.comType == 0;
- if (flag)
- {
- string text = this.modBusSerialPort.ReadExisting();
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- NetworkStream stream = this.clientSocket.GetStream();
- stream.Flush();
- }
- }
- }
-
- // Token: 0x06000012 RID: 18 RVA: 0x000033E8 File Offset: 0x000015E8
- public int ReaderConnectTcpServer(string ipStr, string portStr, int device_Addr)
- {
- int result = -1;
- this.ReaderSetComType(1);
- try
- {
- int port = Convert.ToInt32(portStr);
- this.clientSocket = new TcpClient();
- IAsyncResult asyncResult = this.clientSocket.BeginConnect(ipStr, port, null, null);
- asyncResult.AsyncWaitHandle.WaitOne(1000);
- bool flag = !asyncResult.IsCompleted;
- if (flag)
- {
- this.clientSocket.Close();
- this.clientSocket = null;
- return -1;
- }
- this.masterIp = ModbusIpMaster.CreateIp(this.clientSocket);
- this.masterIp.Transport.Retries = 1;
- this.masterIp.Transport.ReadTimeout = 1000;
- this.deviceAddr = (byte)device_Addr;
- result = 0;
- }
- catch (Exception)
- {
- result = -1;
- }
- return result;
- }
-
- // Token: 0x06000013 RID: 19 RVA: 0x000034C0 File Offset: 0x000016C0
- public void ReaderCloseTcpServer()
- {
- try
- {
- bool flag = this.clientSocket != null;
- if (flag)
- {
- bool connected = this.clientSocket.Connected;
- if (connected)
- {
- try
- {
- this.clientSocket.Close();
- }
- catch (Exception)
- {
- }
- }
- this.clientSocket = null;
- }
- bool flag2 = this.masterIp != null;
- if (flag2)
- {
- this.masterIp.Dispose();
- this.masterIp = null;
- }
- }
- catch (Exception ex)
- {
- }
- }
-
- // Token: 0x06000014 RID: 20 RVA: 0x00003554 File Offset: 0x00001754
- private void ReaderSetComType(int mode)
- {
- bool flag = mode == 0;
- if (flag)
- {
- this.Disconnect();
- this.comType = 0;
- }
- else
- {
- bool flag2 = mode == 1;
- if (flag2)
- {
- this.ReaderCloseTcpServer();
- this.comType = 1;
- }
- }
- }
-
- // Token: 0x06000015 RID: 21 RVA: 0x00003594 File Offset: 0x00001794
- public void JmpApp()
- {
- byte[] array = new byte[]
- {
- 126,
- 85,
- 8,
- 0,
- 0,
- byte.MaxValue,
- byte.MaxValue,
- 3,
- 0,
- 213,
- 123
- };
- bool flag = this.comType == 0;
- if (flag)
- {
- this.modBusSerialPort.Write(array, 0, array.Length);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- NetworkStream stream = this.clientSocket.GetStream();
- bool canWrite = stream.CanWrite;
- if (canWrite)
- {
- stream.Write(array, 0, array.Length);
- }
- }
- }
- Thread.Sleep(200);
- }
-
- // Token: 0x06000016 RID: 22 RVA: 0x00003618 File Offset: 0x00001818
- public bool GetParams(ref HFIIREADER_PARAMS devParams, uint deviceType, ushort devieVer, int protocolType)
- {
- bool result = true;
- this.ClearRxBuffer();
- bool flag = (deviceType & 16773120U) == 3358720U && devieVer < 12288;
- ushort num;
- if (flag)
- {
- num = 9;
- }
- else
- {
- num = 12;
- }
- try
- {
- ushort[] array = new ushort[12];
- bool flag2 = this.comType == 0;
- if (flag2)
- {
- array = this.master.ReadHoldingRegisters(this.deviceAddr, 0, num);
- }
- else
- {
- bool flag3 = this.comType == 1;
- if (flag3)
- {
- array = this.masterIp.ReadHoldingRegisters(this.deviceAddr, 0, num);
- }
- }
- bool flag4 = array == null;
- if (flag4)
- {
- result = false;
- }
- else
- {
- devParams.addr = array[0];
- devParams.br = array[1];
- bool flag5 = protocolType == 0;
- if (flag5)
- {
- devParams.afiMode = array[2];
- }
- else
- {
- devParams.tagType = array[2];
- }
- devParams.invtTo = array[3];
- devParams.trgMode = array[4];
- devParams.opTagMode = array[5];
- devParams.opBlockRegAddr = array[6];
- devParams.opBlockRegNum = array[7];
- devParams.trgTimerTick = array[8];
- bool flag6 = num == 12;
- if (flag6)
- {
- devParams.opFormat = array[9];
- devParams.frameHead = array[10];
- devParams.keppTimer = array[11];
- }
- }
- }
- catch (Exception ex)
- {
- string message = ex.Message;
- result = false;
- }
- return result;
- }
-
- // Token: 0x06000017 RID: 23 RVA: 0x00003794 File Offset: 0x00001994
- public bool GetBlockParams(ref int paramsInfo)
- {
- bool result = true;
- this.ClearRxBuffer();
- try
- {
- ushort[] array = null;
- bool flag = this.comType == 0;
- if (flag)
- {
- array = this.master.ReadHoldingRegisters(this.deviceAddr, 12, 1);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- array = this.masterIp.ReadHoldingRegisters(this.deviceAddr, 12, 1);
- }
- }
- bool flag3 = array == null;
- if (flag3)
- {
- result = false;
- }
- else
- {
- paramsInfo = (int)array[0];
- }
- }
- catch (Exception ex)
- {
- string message = ex.Message;
- result = false;
- }
- return result;
- }
-
- // Token: 0x06000018 RID: 24 RVA: 0x0000383C File Offset: 0x00001A3C
- public bool GetRfPower(ref int level)
- {
- bool result = true;
- this.ClearRxBuffer();
- try
- {
- ushort[] array = null;
- bool flag = this.comType == 0;
- if (flag)
- {
- array = this.master.ReadHoldingRegisters(this.deviceAddr, 15, 1);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- array = this.masterIp.ReadHoldingRegisters(this.deviceAddr, 15, 1);
- }
- }
- bool flag3 = array == null;
- if (flag3)
- {
- result = false;
- }
- else
- {
- level = (int)array[0];
- }
- }
- catch (Exception ex)
- {
- string message = ex.Message;
- result = false;
- }
- return result;
- }
-
- // Token: 0x06000019 RID: 25 RVA: 0x000038E4 File Offset: 0x00001AE4
- public bool GetReadTagRspErrMode(ref int mode)
- {
- bool result = true;
- this.ClearRxBuffer();
- try
- {
- ushort[] array = null;
- bool flag = this.comType == 0;
- if (flag)
- {
- array = this.master.ReadHoldingRegisters(this.deviceAddr, 16, 1);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- array = this.masterIp.ReadHoldingRegisters(this.deviceAddr, 16, 1);
- }
- }
- bool flag3 = array == null;
- if (flag3)
- {
- result = false;
- }
- else
- {
- mode = (int)array[0];
- }
- }
- catch (Exception ex)
- {
- string message = ex.Message;
- result = false;
- }
- return result;
- }
-
- // Token: 0x0600001A RID: 26 RVA: 0x0000398C File Offset: 0x00001B8C
- public bool SetBlockParams(int paramsInfo)
- {
- bool result = true;
- this.ClearRxBuffer();
- try
- {
- ushort[] data = new ushort[]
- {
- (ushort)paramsInfo
- };
- bool flag = this.comType == 0;
- if (flag)
- {
- this.master.WriteMultipleRegisters(this.deviceAddr, 12, data);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- this.masterIp.WriteMultipleRegisters(this.deviceAddr, 12, data);
- }
- }
- }
- catch (Exception ex)
- {
- string message = ex.Message;
- result = false;
- }
- return result;
- }
-
- // Token: 0x0600001B RID: 27 RVA: 0x00003A28 File Offset: 0x00001C28
- public bool SetM1KeyParams(bool bSave, int type, byte[] key)
- {
- bool result = true;
- this.ClearRxBuffer();
- try
- {
- ushort[] array = new ushort[5];
- if (bSave)
- {
- array[0] = 1;
- }
- else
- {
- array[0] = 0;
- }
- array[1] = (ushort)(type & 1);
- array[2] = (ushort)((int)key[0] * 256 + (int)key[1] & 65535);
- array[3] = (ushort)((int)key[2] * 256 + (int)key[3] & 65535);
- array[4] = (ushort)((int)key[4] * 256 + (int)key[5] & 65535);
- bool flag = this.comType == 0;
- if (flag)
- {
- this.master.WriteMultipleRegisters(this.deviceAddr, 65280, array);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- this.masterIp.WriteMultipleRegisters(this.deviceAddr, 65280, array);
- }
- }
- }
- catch (Exception ex)
- {
- string message = ex.Message;
- result = false;
- }
- return result;
- }
-
- // Token: 0x0600001C RID: 28 RVA: 0x00003B24 File Offset: 0x00001D24
- public bool GetM1KeyParams(ref bool bSave, ref int type, byte[] key)
- {
- bool result = true;
- this.ClearRxBuffer();
- try
- {
- ushort[] array = null;
- bool flag = this.comType == 0;
- if (flag)
- {
- array = this.master.ReadHoldingRegisters(this.deviceAddr, 65280, 5);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- array = this.masterIp.ReadHoldingRegisters(this.deviceAddr, 65280, 5);
- }
- }
- bool flag3 = array != null;
- if (flag3)
- {
- bool flag4 = array[0] == 1;
- if (flag4)
- {
- bSave = true;
- }
- else
- {
- bSave = false;
- }
- type = (int)(array[1] & 1);
- key[0] = (byte)(array[2] >> 8 & 255);
- key[1] = (byte)(array[2] & 255);
- key[2] = (byte)(array[3] >> 8 & 255);
- key[3] = (byte)(array[3] & 255);
- key[4] = (byte)(array[4] >> 8 & 255);
- key[5] = (byte)(array[4] & 255);
- }
- }
- catch (Exception ex)
- {
- string message = ex.Message;
- result = false;
- }
- return result;
- }
-
- // Token: 0x0600001D RID: 29 RVA: 0x00003C38 File Offset: 0x00001E38
- public bool SetRfPower(int lv)
- {
- bool result = true;
- this.ClearRxBuffer();
- try
- {
- ushort[] data = new ushort[]
- {
- (ushort)lv
- };
- bool flag = this.comType == 0;
- if (flag)
- {
- this.master.WriteMultipleRegisters(this.deviceAddr, 15, data);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- this.masterIp.WriteMultipleRegisters(this.deviceAddr, 15, data);
- }
- }
- }
- catch (Exception ex)
- {
- string message = ex.Message;
- result = false;
- }
- return result;
- }
-
- // Token: 0x0600001E RID: 30 RVA: 0x00003CD4 File Offset: 0x00001ED4
- public bool SetReadTagErrMode(int mode)
- {
- bool result = true;
- this.ClearRxBuffer();
- try
- {
- ushort[] data = new ushort[]
- {
- (ushort)mode
- };
- bool flag = this.comType == 0;
- if (flag)
- {
- this.master.WriteMultipleRegisters(this.deviceAddr, 16, data);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- this.masterIp.WriteMultipleRegisters(this.deviceAddr, 16, data);
- }
- }
- }
- catch (Exception ex)
- {
- string message = ex.Message;
- result = false;
- }
- return result;
- }
-
- // Token: 0x0600001F RID: 31 RVA: 0x00003D70 File Offset: 0x00001F70
- public bool SetParams(HFIIREADER_PARAMS devParams, uint deviceType, ushort devieVer, int protocolType)
- {
- bool result = true;
- this.ClearRxBuffer();
- bool flag = (deviceType & 16773120U) == 3358720U && devieVer < 12288;
- ushort num;
- if (flag)
- {
- num = 9;
- }
- else
- {
- num = 12;
- }
- ushort[] array = new ushort[(int)num];
- array[0] = devParams.addr;
- array[1] = devParams.br;
- bool flag2 = protocolType == 0;
- if (flag2)
- {
- array[2] = devParams.afiMode;
- }
- else
- {
- array[2] = devParams.tagType;
- }
- array[3] = devParams.invtTo;
- array[4] = devParams.trgMode;
- array[5] = devParams.opTagMode;
- array[6] = devParams.opBlockRegAddr;
- array[7] = devParams.opBlockRegNum;
- array[8] = devParams.trgTimerTick;
- bool flag3 = num == 12;
- if (flag3)
- {
- array[9] = devParams.opFormat;
- array[10] = devParams.frameHead;
- array[11] = devParams.keppTimer;
- }
- try
- {
- bool flag4 = this.comType == 0;
- if (flag4)
- {
- this.master.WriteMultipleRegisters(this.deviceAddr, 0, array);
- }
- else
- {
- bool flag5 = this.comType == 1;
- if (flag5)
- {
- this.masterIp.WriteMultipleRegisters(this.deviceAddr, 0, array);
- }
- }
- }
- catch (Exception ex)
- {
- result = false;
- }
- return result;
- }
-
- // Token: 0x06000020 RID: 32 RVA: 0x00003EC0 File Offset: 0x000020C0
- public string GetVersion(ref uint deviceTypeInfo, ref ushort deviceVersionInfo)
- {
- string text = "";
- this.ClearRxBuffer();
- try
- {
- ushort[] array = new ushort[1];
- bool flag = this.comType == 0;
- if (flag)
- {
- array = this.master.ReadInputRegisters(this.deviceAddr, 0, 2);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- array = this.masterIp.ReadInputRegisters(this.deviceAddr, 0, 2);
- }
- }
- bool flag3 = array != null;
- if (flag3)
- {
- deviceTypeInfo = (uint)array[0];
- deviceTypeInfo <<= 16;
- deviceTypeInfo |= (uint)array[1];
- }
- else
- {
- deviceTypeInfo = 0U;
- }
- ushort[] array2 = new ushort[1];
- bool flag4 = this.comType == 0;
- if (flag4)
- {
- array2 = this.master.ReadInputRegisters(this.deviceAddr, 2, 1);
- }
- else
- {
- bool flag5 = this.comType == 1;
- if (flag5)
- {
- array2 = this.masterIp.ReadInputRegisters(this.deviceAddr, 2, 1);
- }
- }
- bool flag6 = array2 == null;
- if (flag6)
- {
- text = "Null";
- }
- else
- {
- deviceVersionInfo = array2[0];
- text += "获取版本:";
- text = string.Concat(new string[]
- {
- text,
- "V",
- (array2[0] >> 12 & 15).ToString("X"),
- ".",
- (array2[0] >> 8 & 15).ToString("X"),
- ".",
- (array2[0] >> 4 & 15).ToString("X"),
- ".",
- ((int)(array2[0] & 15)).ToString("X")
- });
- }
- }
- catch (Exception ex)
- {
- text = "Error";
- }
- return text;
- }
-
- // Token: 0x06000021 RID: 33 RVA: 0x00004098 File Offset: 0x00002298
- public string GetSn()
- {
- string text = "";
- this.ClearRxBuffer();
- try
- {
- ushort[] array = new ushort[6];
- bool flag = this.comType == 0;
- if (flag)
- {
- array = this.master.ReadInputRegisters(this.deviceAddr, 13, 6);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- array = this.masterIp.ReadInputRegisters(this.deviceAddr, 13, 6);
- }
- }
- int num;
- for (int i = 0; i < 6; i = num + 1)
- {
- text += array[i].ToString("X").PadLeft(4, '0');
- num = i;
- }
- }
- catch (Exception ex)
- {
- text = "";
- }
- return text;
- }
-
- // Token: 0x06000022 RID: 34 RVA: 0x00004168 File Offset: 0x00002368
- public ushort[] ReadRfInfo()
- {
- ushort[] result = null;
- this.ClearRxBuffer();
- try
- {
- bool flag = this.comType == 0;
- if (flag)
- {
- result = this.master.ReadInputRegisters(this.deviceAddr, 5, 3);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- result = this.masterIp.ReadInputRegisters(this.deviceAddr, 5, 3);
- }
- }
- }
- catch (Exception ex)
- {
- result = null;
- }
- return result;
- }
-
- // Token: 0x06000023 RID: 35 RVA: 0x000041EC File Offset: 0x000023EC
- public ushort[] ReadTagMemory(ref string strErr, ushort regAddr, ushort regNum)
- {
- ushort[] result = null;
- this.ClearRxBuffer();
- try
- {
- bool flag = this.comType == 0;
- if (flag)
- {
- result = this.master.ReadHoldingRegisters(this.deviceAddr, regAddr, regNum);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- result = this.masterIp.ReadHoldingRegisters(this.deviceAddr, regAddr, regNum);
- }
- }
- }
- catch (Exception ex)
- {
- string message = ex.Message;
- result = null;
- }
- return result;
- }
-
- // Token: 0x06000024 RID: 36 RVA: 0x00004278 File Offset: 0x00002478
- public bool WriteTagMemory(ushort regAddr, ushort[] reg, bool bWriteTagMulRes)
- {
- this.ClearRxBuffer();
- try
- {
- if (bWriteTagMulRes)
- {
- bool flag = this.comType == 0;
- if (flag)
- {
- this.master.WriteMultipleRegisters(this.deviceAddr, regAddr, reg);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- this.masterIp.WriteMultipleRegisters(this.deviceAddr, regAddr, reg);
- }
- }
- }
- else
- {
- int num;
- for (int i = 0; i < reg.Length; i = num + 1)
- {
- bool flag3 = this.comType == 0;
- if (flag3)
- {
- this.master.WriteSingleRegister(this.deviceAddr, (ushort)((int)regAddr + i), reg[i]);
- }
- else
- {
- bool flag4 = this.comType == 1;
- if (flag4)
- {
- this.masterIp.WriteSingleRegister(this.deviceAddr, (ushort)((int)regAddr + i), reg[i]);
- }
- }
- num = i;
- }
- }
- }
- catch (Exception ex)
- {
- return false;
- }
- return true;
- }
-
- // Token: 0x06000025 RID: 37 RVA: 0x00004378 File Offset: 0x00002578
- public ushort[] RwTagMemory(ushort wRegAddr, ushort[] wReg, ushort rRegAddr, ushort rRegNum)
- {
- ushort[] result = null;
- this.ClearRxBuffer();
- try
- {
- bool flag = this.comType == 0;
- if (flag)
- {
- result = this.master.ReadWriteMultipleRegisters(this.deviceAddr, rRegAddr, rRegNum, wRegAddr, wReg);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- result = this.masterIp.ReadWriteMultipleRegisters(this.deviceAddr, rRegAddr, rRegNum, wRegAddr, wReg);
- }
- }
- }
- catch (Exception ex)
- {
- }
- return result;
- }
-
- // Token: 0x06000026 RID: 38 RVA: 0x00004400 File Offset: 0x00002600
- public bool WriteCoilTrgOpTag()
- {
- this.ClearRxBuffer();
- try
- {
- this.master.WriteSingleCoil(this.deviceAddr, 1, true);
- }
- catch (Exception ex)
- {
- return false;
- }
- return true;
- }
-
- // Token: 0x06000027 RID: 39 RVA: 0x00004448 File Offset: 0x00002648
- public string ReadOpTagState()
- {
- string result = "IDLE";
- this.ClearRxBuffer();
- try
- {
- ushort[] array = new ushort[1];
- bool flag = this.comType == 0;
- if (flag)
- {
- array = this.master.ReadInputRegisters(this.deviceAddr, 3, 1);
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- array = this.masterIp.ReadInputRegisters(this.deviceAddr, 3, 1);
- }
- }
- bool flag3 = array[0] == 0;
- if (flag3)
- {
- result = "OK";
- }
- else
- {
- bool flag4 = array[0] == 1;
- if (flag4)
- {
- result = "FAIL";
- }
- else
- {
- bool flag5 = array[0] == 3;
- if (flag5)
- {
- result = "BUSY";
- }
- else
- {
- result = "ERROR";
- }
- }
- }
- }
- catch (Exception ex)
- {
- result = "";
- }
- return result;
- }
-
- // Token: 0x06000028 RID: 40 RVA: 0x00004524 File Offset: 0x00002724
- public string ReceiveAutoTagInfo()
- {
- string result = "";
- try
- {
- bool flag = this.comType == 0;
- if (flag)
- {
- result = this.modBusSerialPort.ReadExisting();
- }
- else
- {
- bool flag2 = this.comType == 1;
- if (flag2)
- {
- NetworkStream stream = this.clientSocket.GetStream();
- bool flag3 = stream.CanRead && stream.DataAvailable;
- if (flag3)
- {
- byte[] array = new byte[1024];
- int count = stream.Read(array, 0, array.Length);
- result = Encoding.ASCII.GetString(array, 0, count);
- }
- }
- }
- }
- catch (Exception ex)
- {
- }
- return result;
- }
-
- // Token: 0x04000032 RID: 50
- private ModbusSerialMaster master;
-
- // Token: 0x04000033 RID: 51
- private ModbusIpMaster masterIp = null;
-
- // Token: 0x04000034 RID: 52
- private SerialPort modBusSerialPort;
-
- // Token: 0x04000035 RID: 53
- private byte deviceAddr = 1;
-
- // Token: 0x04000036 RID: 54
- public const ushort HFIIREADER_TYPE_ADDR_VERSION = 0;
-
- // Token: 0x04000037 RID: 55
- public const ushort HFIIREADER_TYPE_NUM_VERSION = 2;
-
- // Token: 0x04000038 RID: 56
- public const ushort HFIIREADER_TYPE_ADDR_SN = 13;
-
- // Token: 0x04000039 RID: 57
- public const ushort HFIIREADER_TYPE_NUM_SN = 6;
-
- // Token: 0x0400003A RID: 58
- public const ushort HFIIREADER_REG_ADDR_VERSION = 2;
-
- // Token: 0x0400003B RID: 59
- public const ushort HFIIREADER_REG_NUM_VERSION = 1;
-
- // Token: 0x0400003C RID: 60
- public const ushort HFIIREADER_REG_ADDR_OPSTAT = 3;
-
- // Token: 0x0400003D RID: 61
- public const ushort HFIIREADER_REG_NUM_OPSTAT = 1;
-
- // Token: 0x0400003E RID: 62
- public const ushort HFIIREADER_BR_9600 = 0;
-
- // Token: 0x0400003F RID: 63
- public const ushort HFIIREADER_BR_38400 = 1;
-
- // Token: 0x04000040 RID: 64
- public const ushort HFIIREADER_BR_115200 = 2;
-
- // Token: 0x04000041 RID: 65
- public const ushort HFIIREADER_BR_19200 = 3;
-
- // Token: 0x04000042 RID: 66
- public const ushort HFIIREADER_OP_MODE_RBLOCK = 1;
-
- // Token: 0x04000043 RID: 67
- public const ushort HFIIREADER_OP_MODE_RAFI = 2;
-
- // Token: 0x04000044 RID: 68
- public const ushort HFIIREADER_OP_MODE_RDSFID = 4;
-
- // Token: 0x04000045 RID: 69
- public const ushort HFIIREADER_OP_MODE_UID = 0;
-
- // Token: 0x04000046 RID: 70
- public const ushort READER_RSPFORMAT_NONE = 0;
-
- // Token: 0x04000047 RID: 71
- public const ushort READER_RSPFORMAT_ASCII = 256;
-
- // Token: 0x04000048 RID: 72
- public const ushort READER_RSPFORMAT_PULSE = 512;
-
- // Token: 0x04000049 RID: 73
- public const ushort HFIIREADER_OP_FORMAT_HEADER = 1;
-
- // Token: 0x0400004A RID: 74
- public const ushort HFIIREADER_OP_FORMAT_ADDRESS = 2;
-
- // Token: 0x0400004B RID: 75
- public const ushort HFIIREADER_OP_FORMAT_BCC = 4;
-
- // Token: 0x0400004C RID: 76
- public const ushort HFIIREADER_OP_MODE_MASK = 15;
-
- // Token: 0x0400004D RID: 77
- public const ushort HFIIREADER_TRG_MODE_TIMER = 0;
-
- // Token: 0x0400004E RID: 78
- public const ushort HFIIREADER_TRG_MODE_RWREG = 1;
-
- // Token: 0x0400004F RID: 79
- public const ushort HFIIREADER_TRG_MODE_WCOIL = 2;
-
- // Token: 0x04000050 RID: 80
- public const ushort HFIIREADER_TRG_MODE_NUM = 3;
-
- // Token: 0x04000051 RID: 81
- public const ushort HFIIREADER_AFI_MODE_ENABLE = 256;
-
- // Token: 0x04000052 RID: 82
- public const ushort HFIIREADER_AFI_MODE_DISABLE = 0;
-
- // Token: 0x04000053 RID: 83
- public const ushort HFIIREADER_INREG_RFINFO_ADDR = 5;
-
- // Token: 0x04000054 RID: 84
- public const ushort HFIIREADER_INREG_RFINFO_NUM = 3;
-
- // Token: 0x04000055 RID: 85
- public const ushort READER_RESULT_CLR_AUTO = 0;
-
- // Token: 0x04000056 RID: 86
- public const ushort READER_RESULT_CLR_KEEP = 256;
-
- // Token: 0x04000057 RID: 87
- public const ushort HFIIREADER_HOLDREG_PARAMS_ADDR = 0;
-
- // Token: 0x04000058 RID: 88
- public const ushort HFIIREADER_HOLDREG_PARAMS_NUM = 12;
-
- // Token: 0x04000059 RID: 89
- public const ushort HFIIREADER_HOLDREG_PARAMS_NUM2 = 9;
-
- // Token: 0x0400005A RID: 90
- public const ushort HFIIREADER_HOLDREG_BLKPAR_ADDR = 12;
-
- // Token: 0x0400005B RID: 91
- public const ushort HFIIREADER_HOLDREG_BLKPAR_NUM = 1;
-
- // Token: 0x0400005C RID: 92
- public const ushort HFIIREADER_HOLDREG_BLKSIZE_MSK = 3;
-
- // Token: 0x0400005D RID: 93
- public const ushort HFIIREADER_HOLDREG_BLKNUM_MSK = 12;
-
- // Token: 0x0400005E RID: 94
- public const ushort HFIIREADER_HOLDREG_RFPWR_ADDR = 15;
-
- // Token: 0x0400005F RID: 95
- public const ushort HFIIREADER_HOLDREG_RFPWR_NUM = 1;
-
- // Token: 0x04000060 RID: 96
- public const ushort HFIIREADER_HOLDREG_ERRMOD_ADDR = 16;
-
- // Token: 0x04000061 RID: 97
- public const ushort HFIIREADER_HOLDREG_ERRMOD_NUM = 1;
-
- // Token: 0x04000062 RID: 98
- public const ushort HFIIREADER_HOLDREG_TAG_START = 26;
-
- // Token: 0x04000063 RID: 99
- public const ushort HFIIREADER_HOLDREG_DSFID_ADDR = 26;
-
- // Token: 0x04000064 RID: 100
- public const ushort HFIIREADER_HOLDREG_DSFID_NUM = 1;
-
- // Token: 0x04000065 RID: 101
- public const ushort HFIIREADER_HOLDREG_AFI_ADDR = 27;
-
- // Token: 0x04000066 RID: 102
- public const ushort HFIIREADER_HOLDREG_AFI_NUM = 1;
-
- // Token: 0x04000067 RID: 103
- public const ushort HFIIREADER_HOLDREG_UID_ADDR = 28;
-
- // Token: 0x04000068 RID: 104
- public const ushort HFIIREADER_HOLDREG_UID_NUM = 4;
-
- // Token: 0x04000069 RID: 105
- public const ushort HFIIREADER_HOLDREG_BLK_ADDR = 32;
-
- // Token: 0x0400006A RID: 106
- public const ushort HFIIREADER_HOLDREG_BLK_NUM = 1024;
-
- // Token: 0x0400006B RID: 107
- public const ushort HFIIREADER_HOLDREG_M1KEY_ADDR = 65280;
-
- // Token: 0x0400006C RID: 108
- public const ushort HFIIREADER_HOLDREG_M1KEY_NUM = 5;
-
- // Token: 0x0400006D RID: 109
- public const ushort HFIIREADER_COLIL_REG_NUM = 4;
-
- // Token: 0x0400006E RID: 110
- public const ushort HFIIREADER_COIL_ADDR_RSTSYS = 0;
-
- // Token: 0x0400006F RID: 111
- public const ushort HFIIREADER_COIL_ADDR_STARTOP = 1;
-
- // Token: 0x04000070 RID: 112
- public const ushort HFIIREADER_COIL_ADDR_RSTERR = 2;
-
- // Token: 0x04000071 RID: 113
- public const ushort HFIIREADER_COIL_ADDR_CFGMODE = 3;
-
- // Token: 0x04000072 RID: 114
- public const ushort HFIIREADER_COIL_VALUE_SET = 65280;
-
- // Token: 0x04000073 RID: 115
- public const ushort HFIIREADER_COIL_VALUE_RESET = 0;
-
- // Token: 0x04000074 RID: 116
- private byte[] txFrame = new byte[1024];
-
- // Token: 0x04000075 RID: 117
- private byte[] rxFrame = new byte[1024];
-
- // Token: 0x04000076 RID: 118
- private TcpClient clientSocket = null;
-
- // Token: 0x04000077 RID: 119
- public const int READER_COM_TYPE_UART = 0;
-
- // Token: 0x04000078 RID: 120
- public const int READER_COM_TYPE_NET = 1;
-
- // Token: 0x04000079 RID: 121
- public int comType = 0;
- }
-}
\ No newline at end of file
diff --git a/NDSD-Screwdriver/packages.config b/NDSD-Screwdriver/packages.config
index 571fcd8..71393df 100644
--- a/NDSD-Screwdriver/packages.config
+++ b/NDSD-Screwdriver/packages.config
@@ -11,6 +11,7 @@
-
-
+
+
+
\ No newline at end of file
diff --git a/NDSD-TouchSocket/NDSD_TouchSocket.csproj b/NDSD-TouchSocket/NDSD_TouchSocket.csproj
index 1bd4160..87ffcd7 100644
--- a/NDSD-TouchSocket/NDSD_TouchSocket.csproj
+++ b/NDSD-TouchSocket/NDSD_TouchSocket.csproj
@@ -73,10 +73,13 @@
- ..\packages\TouchSocket.2.1.0-rc.10\lib\net472\TouchSocket.dll
+ ..\packages\TouchSocket.2.1.0-rc.11\lib\net472\TouchSocket.dll
- ..\packages\TouchSocket.Core.2.1.0-rc.10\lib\net472\TouchSocket.Core.dll
+ ..\packages\TouchSocket.Core.2.1.0-rc.11\lib\net472\TouchSocket.Core.dll
+
+
+ ..\packages\TouchSocket.SerialPorts.2.1.0-rc.11\lib\net472\TouchSocket.SerialPorts.dll
@@ -91,7 +94,7 @@
-
+
\ No newline at end of file
diff --git a/NDSD-TouchSocket/packages.config b/NDSD-TouchSocket/packages.config
index 7bf105e..14a4e63 100644
--- a/NDSD-TouchSocket/packages.config
+++ b/NDSD-TouchSocket/packages.config
@@ -9,6 +9,7 @@
-
-
+
+
+
\ No newline at end of file
diff --git a/文档/备忘录.txt b/文档/备忘录.txt
new file mode 100644
index 0000000..9cfc940
--- /dev/null
+++ b/文档/备忘录.txt
@@ -0,0 +1,10 @@
+4545端口
+宁德时代开放协议
+MID0042/MID0043是拧紧枪使能开关的
+0061是拧紧枪发送的报文
+
+00200042000 nul
+00200043000 nul
+
+
+nul \0
\ No newline at end of file
diff --git a/文档/开放协议.pdf b/文档/开放协议.pdf
new file mode 100644
index 0000000..869f343
Binary files /dev/null and b/文档/开放协议.pdf differ