40 lines
1.8 KiB
C#
40 lines
1.8 KiB
C#
namespace ZB.MOM.WW.OtOpcUa.Driver.Modbus;
|
|
|
|
/// <summary>
|
|
/// Modbus TCP driver configuration. Bound from the driver's <c>DriverConfig</c> JSON at
|
|
/// <c>DriverHost.RegisterAsync</c>. Every register the driver exposes appears in
|
|
/// <see cref="Tags"/>; names become the OPC UA browse name + full reference.
|
|
/// </summary>
|
|
public sealed class ModbusDriverOptions
|
|
{
|
|
public string Host { get; init; } = "127.0.0.1";
|
|
public int Port { get; init; } = 502;
|
|
public byte UnitId { get; init; } = 1;
|
|
public TimeSpan Timeout { get; init; } = TimeSpan.FromSeconds(2);
|
|
|
|
/// <summary>Pre-declared tag map. Modbus has no discovery protocol — the driver returns exactly these.</summary>
|
|
public IReadOnlyList<ModbusTagDefinition> Tags { get; init; } = [];
|
|
}
|
|
|
|
/// <summary>
|
|
/// One Modbus-backed OPC UA variable. Address is zero-based (Modbus spec numbering, not
|
|
/// the documentation's 1-based coil/register conventions).
|
|
/// </summary>
|
|
/// <param name="Name">
|
|
/// Tag name, used for both the OPC UA browse name and the driver's full reference. Must be
|
|
/// unique within the driver.
|
|
/// </param>
|
|
/// <param name="Region">Coils / DiscreteInputs / InputRegisters / HoldingRegisters.</param>
|
|
/// <param name="Address">Zero-based address within the region.</param>
|
|
/// <param name="DataType">Logical data type. Int16/UInt16 = single register; Int32/UInt32/Float32 = two registers big-endian.</param>
|
|
/// <param name="Writable">When true and Region supports writes (Coils / HoldingRegisters), IWritable routes writes here.</param>
|
|
public sealed record ModbusTagDefinition(
|
|
string Name,
|
|
ModbusRegion Region,
|
|
ushort Address,
|
|
ModbusDataType DataType,
|
|
bool Writable = true);
|
|
|
|
public enum ModbusRegion { Coils, DiscreteInputs, InputRegisters, HoldingRegisters }
|
|
public enum ModbusDataType { Bool, Int16, UInt16, Int32, UInt32, Float32 }
|