SerialPortFactory

master
杨威 3 months ago
parent 07bb9f4c0b
commit 72b258db65

@ -47,6 +47,9 @@
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="nModbusPC">
<HintPath>..\Dll\nmodbuspc.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> <Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath> <HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
@ -118,6 +121,9 @@
<DependentUpon>ScrewdriverTest.cs</DependentUpon> <DependentUpon>ScrewdriverTest.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="FormUtils.cs" /> <Compile Include="FormUtils.cs" />
<Compile Include="Tool\hfIIReader.cs" />
<Compile Include="Tool\HFIIREADER_PARAMS.cs" />
<Compile Include="Tool\SerialPortFactory.cs" />
<EmbeddedResource Include="FrmSetting.resx"> <EmbeddedResource Include="FrmSetting.resx">
<DependentUpon>FrmSetting.cs</DependentUpon> <DependentUpon>FrmSetting.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>

@ -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;
}
}

@ -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();
}
}
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save