Configuration

Transport Options

var options = new TransportOptions
{
    // Serial
    PortName = "COM3",
    BaudRate = 9600,
    DataBits = 8,

    // TCP
    Host = "192.168.1.100",
    Port = 1153,

    // Timeouts
    ReadTimeoutMs = 5000,
    WriteTimeoutMs = 5000,
    ReceiveBufferSize = 4096
};

PSEM Session Parameters

await client.ConnectAsync(
    userId: 2,                        // Default: 2
    userName: "SharpMeter",           // Max 10 chars
    password: passwordBytes,          // Max 20 bytes
    baudRates: new[]                  // Negotiated baud rates
    {
        BaudRate.Baud9600,
        BaudRate.Baud19200,
        BaudRate.Baud38400
    });

DLMS Client Options

var options = new DlmsClientOptions
{
    ClientAddress = HdlcAddress.PublicClient,     // Default: 16
    ServerAddress = HdlcAddress.MeterServer,      // Default: 1/0
    Authentication = AuthenticationMechanism.None,
    Password = Array.Empty<byte>(),
    ResponseTimeoutMs = 10000,
    MaxPduSize = 65535
};

Logging

SharpMeter uses Microsoft.Extensions.Logging:

// With DI
services.AddLogging(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Debug));

// Manual
using var loggerFactory = LoggerFactory.Create(builder =>
    builder.AddConsole().SetMinimumLevel(LogLevel.Debug));

var transport = new SerialTransport(options, loggerFactory.CreateLogger<SerialTransport>());
var client = new PsemClient(transport, loggerFactory.CreateLogger<PsemClient>());

Protocol Constants

Key constants from PsemConstants:

Constant Value Description
MaxPacketLength 128 Max negotiable packet size
MaxNumberOfPackets 254 Max packets per transfer
DefaultMaxPacketSize 64 Default packet size
DefaultResponseTimeout 5000ms Default timeout
DefaultRetryCount 3 Default retries
StandardTableMax 2047 Max standard table ID
ManufacturingTableOffset 2048 MT ID offset
Last updated: 2026-04-08
Was this page helpful?