Class DeviceMessage

Namespace
ProtoTest.Devices
Assembly
ProtoTest.Devices.dll

Writes a message type to what the device sends and reads it back, so a test builds new MeterReading("M-1", 12.5m) instead of concatenating "$MTR,M-1,12.50*4B". A type with DeviceBinaryMessageAttribute is a fixed-layout byte block; any other type is a line of text. Text values use the invariant culture.

public static class DeviceMessage
Inheritance
DeviceMessage
Inherited Members

Methods

Format<TMessage>(TMessage)

Writes a text message as its data string, checksum included.

public static string Format<TMessage>(TMessage message) where TMessage : notnull

Parameters

message TMessage

Returns

string

Type Parameters

TMessage

FromBytes<TMessage>(ReadOnlySpan<byte>)

Reads bytes as a binary TMessage, or fails naming what did not match.

public static TMessage FromBytes<TMessage>(ReadOnlySpan<byte> bytes)

Parameters

bytes ReadOnlySpan<byte>

Returns

TMessage

Type Parameters

TMessage

Exceptions

DeviceMessageFormatException

The prefix, the length, a field or the checksum does not match.

Parse<TMessage>(string)

Reads a data string as TMessage, or fails naming what did not match.

public static TMessage Parse<TMessage>(string text)

Parameters

text string

Returns

TMessage

Type Parameters

TMessage

Exceptions

DeviceMessageFormatException

The prefix, a field, the field count or the checksum does not match.

Read<TMessage>(DeviceFrame)

Reads a frame as TMessage, or fails naming what did not match.

public static TMessage Read<TMessage>(DeviceFrame frame)

Parameters

frame DeviceFrame

Returns

TMessage

Type Parameters

TMessage

ToBytes<TMessage>(TMessage)

Writes a binary message as its bytes, prefix and checksum included.

public static byte[] ToBytes<TMessage>(TMessage message) where TMessage : notnull

Parameters

message TMessage

Returns

byte[]

Type Parameters

TMessage

ToFrame<TMessage>(TMessage)

Writes a message as the frame a device sends: text for a text message, bytes for a binary one.

public static DeviceFrame ToFrame<TMessage>(TMessage message) where TMessage : notnull

Parameters

message TMessage

Returns

DeviceFrame

Type Parameters

TMessage

TryParse<TMessage>(string?, out TMessage)

Reads a data string as TMessage, or returns false when it does not match.

public static bool TryParse<TMessage>(string? text, out TMessage message)

Parameters

text string
message TMessage

Returns

bool

Type Parameters

TMessage

TryRead<TMessage>(DeviceFrame, out TMessage)

Reads a frame as TMessage, or returns false when it is another message.

public static bool TryRead<TMessage>(DeviceFrame frame, out TMessage message)

Parameters

frame DeviceFrame
message TMessage

Returns

bool

Type Parameters

TMessage