IOT纯后端项目改造

This commit is contained in:
“hsc”
2026-08-21 16:14:58 +08:00
parent fa2f9f64c5
commit 21addffdde
64 changed files with 16 additions and 3667 deletions
+1
View File
@@ -14,6 +14,7 @@
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
<ProjectReference Include="..\Logger\Logger.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
-108
View File
@@ -1,108 +0,0 @@
using DeviceCommand.Base;
public class Others : ModbusTcp
{
private readonly byte _slaveId;
/// <summary>
/// 通道1PV
/// </summary>
private const ushort CH1_PV = 100;
/// <summary>
/// 通道2PV
/// </summary>
private const ushort CH2_PV = 102;
/// <summary>
/// 通道3PV
/// </summary>
private const ushort CH3_PV = 104;
/// <summary>
/// 通道4PV
/// </summary>
private const ushort CH4_PV = 106;
public Others(
byte slaveId,
string ip,
int port = 508,
int sendTimeoutMs = 3000,
int receiveTimeoutMs = 3000)
: base()
{
_slaveId = slaveId;
ConfigureDevice(ip, port, sendTimeoutMs, receiveTimeoutMs);
}
/// <summary>
/// 读取通道1PV
/// </summary>
public async Task<float> ReadCH1Async(CancellationToken ct = default)
{
return await ReadRealAsync(CH1_PV, ct);
}
/// <summary>
/// 读取通道2PV
/// </summary>
public async Task<float> ReadCH2Async(CancellationToken ct = default)
{
return await ReadRealAsync(CH2_PV, ct);
}
/// <summary>
/// 读取通道3PV
/// </summary>
public async Task<float> ReadCH3Async(CancellationToken ct = default)
{
return await ReadRealAsync(CH3_PV, ct);
}
/// <summary>
/// 读取通道4PV
/// </summary>
public async Task<float> ReadCH4Async(CancellationToken ct = default)
{
return await ReadRealAsync(CH4_PV, ct);
}
/// <summary>
/// 一次读取4个通道PV
/// </summary>
public async Task<(float ch1, float ch2, float ch3, float ch4)> ReadAllAsync(CancellationToken ct = default)
{
ushort[] raw = await ReadHoldingRegistersAsync(_slaveId, 100, 8, ct);
return
(
ToFloat(raw[0], raw[1]),
ToFloat(raw[2], raw[3]),
ToFloat(raw[4], raw[5]),
ToFloat(raw[6], raw[7])
);
}
private async Task<float> ReadRealAsync(ushort address, CancellationToken ct)
{
ushort[] raw = await ReadHoldingRegistersAsync(_slaveId, address, 2, ct);
return ToFloat(raw[0], raw[1]);
}
private static float ToFloat(ushort high, ushort low)
{
byte[] bytes =
{
(byte)(high >> 8),
(byte)high,
(byte)(low >> 8),
(byte)low
};
if (BitConverter.IsLittleEndian)
Array.Reverse(bytes);
return BitConverter.ToSingle(bytes, 0);
}
}
+1 -1
View File
@@ -13,7 +13,7 @@ namespace DeviceCommand.Devices
public class THC1100 : S7Device
{
#region THC设备默认连接参数
private const string DefaultIpAddress = "192.168.0.1";
private const string DefaultIpAddress = "192.168.1.3";
private const CpuType DefaultCpuType = CpuType.S71200;
private const short DefaultRack = 0;
private const short DefaultSlot = 1;