27 lines
1.4 KiB
C#
27 lines
1.4 KiB
C#
using System.Threading.Tasks;
|
||
|
||
namespace TabletTester2025.Services
|
||
{
|
||
public interface IPlcService
|
||
{ //建立通讯链接
|
||
Task ConnectAsync();
|
||
//确认 PLC 当前可通讯,不能只依赖 TCP socket 状态。
|
||
Task<bool> CheckConnectionAsync();
|
||
//从 PLC 的指定起始地址,读取 1 个 32 位浮点型(float)数据。
|
||
Task<float> ReadFloatAsync(ushort startAddress);
|
||
//从 PLC 的指定起始地址,读取 1 个 32 位整型(int)数据。
|
||
Task<int> ReadIntAsync(ushort startAddress);
|
||
//向 PLC 的指定线圈地址,写入一个布尔值(开关量)。
|
||
Task WriteCoilAsync(ushort coilAddress, bool value);
|
||
//读取 PLC 指定线圈地址的布尔状态,是 WriteCoilAsync 的配套读取方法。
|
||
Task<bool> ReadCoilAsync(ushort coilAddress);
|
||
//向 PLC 的指定寄存器地址,写入 1 个 16 位无符号整型(ushort)数据。
|
||
Task WriteRegisterAsync(ushort registerAddress, ushort value);
|
||
//向 PLC 的指定起始地址,写入 1 个 32 位浮点型(float)数据。
|
||
Task WriteFloatAsync(ushort startAddress, float value);
|
||
//批量读取 PLC 的保持寄存器数据,是工业通信中最高效的批量读取方法。
|
||
Task<ushort[]> ReadHoldingRegistersAsync(ushort startAddress, ushort count);
|
||
bool IsConnected { get; }
|
||
}
|
||
}
|