diff --git a/ConsoleApplication/ConsoleApplication.csproj b/ConsoleApplication/ConsoleApplication.csproj new file mode 100644 index 0000000..c635f07 --- /dev/null +++ b/ConsoleApplication/ConsoleApplication.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {D090275D-5272-4408-A97F-96DA24D568A4} + Exe + Properties + ConsoleApplication + ConsoleApplication + v4.8 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + C:\Program Files\IIS\Microsoft Web Deploy V3\Newtonsoft.Json.dll + + + + + + + + + + + + + + + diff --git a/ConsoleApplication/Program.cs b/ConsoleApplication/Program.cs new file mode 100644 index 0000000..896b4c0 --- /dev/null +++ b/ConsoleApplication/Program.cs @@ -0,0 +1,84 @@ +using System; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Security.Cryptography; +using System.Text; +using System.Threading; + +namespace ConsoleApplication +{ + internal class Program + { + + static string GetTimestamp() + { + long milliseconds = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + return milliseconds.ToString(); + } + + static string GenerateMD5(string input) + { + using (MD5 md5 = MD5.Create()) + { + byte[] inputBytes = Encoding.UTF8.GetBytes(input); + byte[] hashBytes = md5.ComputeHash(inputBytes); + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < hashBytes.Length; i++) + { + sb.Append(hashBytes[i].ToString("x2")); + } + + return sb.ToString(); + } + } + + public static void Main(string[] args) + { + //创建 HttpClient 实例 + using (HttpClient client = new HttpClient()) + { + // 设置请求的基础地址 + client.BaseAddress = new Uri("http://IP/jd/services/sendReceiveCollectionBag"); + string timeStamp = GetTimestamp(); + // 设置请求头 + client.DefaultRequestHeaders.Accept.Clear(); + client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + client.DefaultRequestHeaders.Add("JD-MachineCode", "channel-machine-test-rk-001"); + client.DefaultRequestHeaders.Add("JD-Timestamp", timeStamp); + client.DefaultRequestHeaders.Add("JD-Signature", GenerateMD5("channel-machine-test-rk-001" + timeStamp + "08F68F890E91838CE6C5D08347F17F58")); + + object parameters = new object(); + + var jsonContent = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(parameters), Encoding.UTF8, "application/json"); + + // 选择请求方式 + HttpResponseMessage response; + try + { + // 发送 POST 请求 + response = client.PostAsync("/api/endpoint", jsonContent).GetAwaiter().GetResult(); + + // 处理响应 + if (response.IsSuccessStatusCode) + { + string responseData = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();; + Console.WriteLine("Response: " + responseData); + } + else + { + Console.WriteLine("Error: " + response.ReasonPhrase); + } + } + catch (Exception e) + { + Console.WriteLine("Exception: " + e.Message); + } + } + + + Thread.Sleep(-1); + + } + } +} \ No newline at end of file diff --git a/ConsoleApplication/Properties/AssemblyInfo.cs b/ConsoleApplication/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e283a35 --- /dev/null +++ b/ConsoleApplication/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ConsoleApplication")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ConsoleApplication")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("D090275D-5272-4408-A97F-96DA24D568A4")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/DNSD_DB/DNSD_DB.csproj b/DNSD_DB/DNSD_DB.csproj index c67b71e..717ec3b 100644 --- a/DNSD_DB/DNSD_DB.csproj +++ b/DNSD_DB/DNSD_DB.csproj @@ -36,14 +36,14 @@ - - ..\packages\Chloe.5.25.0\lib\net46\Chloe.dll + + ..\packages\Chloe.5.26.0\lib\net46\Chloe.dll ..\packages\Chloe.Extension.5.25.0\lib\net46\Chloe.Extension.dll - - ..\packages\Chloe.SQLite.5.25.0\lib\net46\Chloe.SQLite.dll + + ..\packages\Chloe.SQLite.5.26.0\lib\net46\Chloe.SQLite.dll @@ -64,5 +64,8 @@ + + + \ No newline at end of file diff --git a/DNSD_DB/packages.config b/DNSD_DB/packages.config new file mode 100644 index 0000000..f656bf6 --- /dev/null +++ b/DNSD_DB/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Dll/nmodbuspc.dll b/Dll/nmodbuspc.dll new file mode 100644 index 0000000..7029c09 Binary files /dev/null and b/Dll/nmodbuspc.dll differ diff --git a/NDSD-Screwdriver/App.config b/NDSD-Screwdriver/App.config index ce6529a..2154567 100644 --- a/NDSD-Screwdriver/App.config +++ b/NDSD-Screwdriver/App.config @@ -21,6 +21,10 @@ + + + + \ No newline at end of file diff --git a/NDSD-Screwdriver/FrmSetting.cs b/NDSD-Screwdriver/FrmSetting.cs index 56f25fe..8a4aafa 100644 --- a/NDSD-Screwdriver/FrmSetting.cs +++ b/NDSD-Screwdriver/FrmSetting.cs @@ -14,6 +14,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using NDSD_TouchSocket; +using NewLife; +using TouchSocket.Core; namespace NDSD_Screwdriver { @@ -24,8 +27,15 @@ namespace NDSD_Screwdriver public FrmSetting() { InitializeComponent(); + + + var body = "00 03 08 E0 04 01 50 B8 C1 39 3A".ToHex(); + + var ssss = CRC16.ToModbus(body).ToHex(" "); + SqlLiteTool.CreateTable(AppTool.GetDb()); Init(); + } diff --git a/NDSD-Screwdriver/NDSD_Screwdriver.csproj b/NDSD-Screwdriver/NDSD_Screwdriver.csproj index 3fb4dfa..e8f126b 100644 --- a/NDSD-Screwdriver/NDSD_Screwdriver.csproj +++ b/NDSD-Screwdriver/NDSD_Screwdriver.csproj @@ -33,26 +33,50 @@ 4 - - ..\packages\Chloe.5.25.0\lib\net46\Chloe.dll + + ..\packages\Chloe.5.26.0\lib\net46\Chloe.dll - - ..\packages\Chloe.SQLite.5.25.0\lib\net46\Chloe.SQLite.dll + + ..\packages\Chloe.SQLite.5.26.0\lib\net46\Chloe.SQLite.dll ..\packages\NewLife.Core.10.10.2024.803\lib\net461\NewLife.Core.dll + + ..\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 + ..\Dll\System.Data.SQLite.dll + + ..\packages\System.IO.Ports.8.0.0\lib\net462\System.IO.Ports.dll + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll @@ -66,6 +90,12 @@ + + ..\packages\TouchSocket.2.1.0-rc.10\lib\net472\TouchSocket.dll + + + ..\packages\TouchSocket.Core.2.1.0-rc.10\lib\net472\TouchSocket.Core.dll + @@ -92,6 +122,10 @@ ScrewdriverTest.cs + + + + FrmSetting.cs @@ -140,6 +174,7 @@ + Always @@ -147,5 +182,8 @@ Always + + + \ No newline at end of file diff --git a/NDSD-Screwdriver/TestDataFactory.cs b/NDSD-Screwdriver/TestDataFactory.cs new file mode 100644 index 0000000..2d390e1 --- /dev/null +++ b/NDSD-Screwdriver/TestDataFactory.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; + +namespace NDSD_Screwdriver +{ + public class TestDataFactory + { + + + /// + /// 获取Rfid的数据 + /// + /// + public static List GetRfidList() + { + List ls = new List + { + "E0040150B8C12108", + "E0040150B8C1393A", + "E0040150B8C0512F", + "E0040150B8C170F6", + "E0040150B8C12100" + }; + + return ls; + } + } +} \ No newline at end of file diff --git a/NDSD-Screwdriver/Tool/HFIIREADER_PARAMS.cs b/NDSD-Screwdriver/Tool/HFIIREADER_PARAMS.cs new file mode 100644 index 0000000..d58f1b5 --- /dev/null +++ b/NDSD-Screwdriver/Tool/HFIIREADER_PARAMS.cs @@ -0,0 +1,49 @@ +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/SerialPortFactory.cs b/NDSD-Screwdriver/Tool/SerialPortFactory.cs new file mode 100644 index 0000000..7064f51 --- /dev/null +++ b/NDSD-Screwdriver/Tool/SerialPortFactory.cs @@ -0,0 +1,58 @@ +using System.IO.Ports; + + +namespace NDSD_Screwdriver.Tool +{ + public class SerialPortFactory + { + private SerialPort serialPortModbus; + private hfIIReader reader; + public SerialPortFactory(string portName="COM13") + { + reader = new hfIIReader(); + serialPortModbus = new SerialPort(); + serialPortModbus.BaudRate = 9600; + serialPortModbus.PortName = portName; + serialPortModbus.ReadTimeout = 0; + } + + + public string Read() + { + + if (!serialPortModbus.IsOpen) + { + serialPortModbus.Open(); + 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) + { + text6 += array6[j].ToString("X").PadLeft(4, '0'); + if (text6.Length > 0) + { + text6 += ""; + } + } + + return text6; + } + + + public void Disconnect() + { + if (!serialPortModbus.IsOpen) + { + serialPortModbus.Close(); + } + reader.Disconnect(); + } + + + } +} \ No newline at end of file diff --git a/NDSD-Screwdriver/Tool/hfIIReader.cs b/NDSD-Screwdriver/Tool/hfIIReader.cs new file mode 100644 index 0000000..0eb783d --- /dev/null +++ b/NDSD-Screwdriver/Tool/hfIIReader.cs @@ -0,0 +1,1205 @@ +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 28d5a6e..571fcd8 100644 --- a/NDSD-Screwdriver/packages.config +++ b/NDSD-Screwdriver/packages.config @@ -1,7 +1,16 @@  - - + + + + + + + + + + + \ No newline at end of file diff --git a/NDSD-Screwdriver/read.json b/NDSD-Screwdriver/read.json new file mode 100644 index 0000000..d543c6b --- /dev/null +++ b/NDSD-Screwdriver/read.json @@ -0,0 +1,2 @@ +00 03 08 E0 04 01 50 B8 C0 51 2F 43 AE +00 03 00 1C 00 04 84 1E \ No newline at end of file diff --git a/NDSD-TouchSocket/NDSD_TouchSocket.csproj b/NDSD-TouchSocket/NDSD_TouchSocket.csproj index 7887024..1bd4160 100644 --- a/NDSD-TouchSocket/NDSD_TouchSocket.csproj +++ b/NDSD-TouchSocket/NDSD_TouchSocket.csproj @@ -31,6 +31,10 @@ 4 + + + ..\packages\NewLife.Core.10.10.2024.803\lib\net461\NewLife.Core.dll + ..\NDSD-Screwdriver\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll @@ -39,6 +43,11 @@ ..\NDSD-Screwdriver\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.IO.Ports.8.0.0\lib\net462\System.IO.Ports.dll + + ..\NDSD-Screwdriver\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll @@ -47,11 +56,16 @@ ..\NDSD-Screwdriver\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll - ..\NDSD-Screwdriver\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll ..\NDSD-Screwdriver\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + + + @@ -59,10 +73,10 @@ - ..\packages\TouchSocket.2.1.0-rc.9\lib\net472\TouchSocket.dll + ..\packages\TouchSocket.2.1.0-rc.10\lib\net472\TouchSocket.dll - ..\packages\TouchSocket.Core.2.1.0-rc.9\lib\net472\TouchSocket.Core.dll + ..\packages\TouchSocket.Core.2.1.0-rc.10\lib\net472\TouchSocket.Core.dll @@ -77,7 +91,7 @@ - + \ No newline at end of file diff --git a/NDSD-TouchSocket/Utils.cs b/NDSD-TouchSocket/Utils.cs index efe0755..ff06809 100644 --- a/NDSD-TouchSocket/Utils.cs +++ b/NDSD-TouchSocket/Utils.cs @@ -52,6 +52,8 @@ namespace NDSD_TouchSocket } return builder.ToString().Trim(); } + + } public static class CRC16 @@ -129,5 +131,40 @@ namespace NDSD_TouchSocket return (uchCRCHi << 8) | uchCRCLo; // 返回校验值 } + + + + /// + /// CRC16_Modbus效验 + /// + /// 要进行计算的字节数组 + /// 计算后的数组 + public static byte[] ToModbus(byte[] byteData) + { + byte[] CRC = new byte[2]; + + UInt16 wCrc = 0xFFFF; + for (int i = 0; i < byteData.Length; i++) + { + wCrc ^= Convert.ToUInt16(byteData[i]); + for (int j = 0; j < 8; j++) + { + if ((wCrc & 0x0001) == 1) + { + wCrc >>= 1; + wCrc ^= 0xA001;//异或多项式 + } + else + { + wCrc >>= 1; + } + } + } + + CRC[1] = (byte)((wCrc & 0xFF00) >> 8);//高位在后 + CRC[0] = (byte)(wCrc & 0x00FF); //低位在前 + return CRC; + + } } } diff --git a/NDSD-TouchSocket/packages.config b/NDSD-TouchSocket/packages.config index 0cf70b2..7bf105e 100644 --- a/NDSD-TouchSocket/packages.config +++ b/NDSD-TouchSocket/packages.config @@ -1,11 +1,14 @@  + + - - + + + \ No newline at end of file