Custom protocol
A protocol is a plugin just like a driver (a DLL in the Protocols
folder). It inherits from the generic ProtocolBase<T> class, where T
is the type of data the driver hands to the protocol — e.g. string for
text lines from the TCP driver or CanFrame for CAN frames. It is this T
that makes a driver and a protocol fit together.
Protocol skeleton
public class MyProtocol : ProtocolBase<string>
{
public MyProtocol() // a parameterless constructor is mandatory
{
Specification = new SpecificationBase
{
Name = "MyProtocol",
Label = "My Protocol",
Version = "1.0.0",
};
}
public override void SetConfiguration() { /* RawSettings */ }
// Create a protocol variable from commParams ("key=value;...")
public override IProtocolVariable CreateProtocolVariable(
IVariableBase variable, string commParams, bool isCommunicated)
{
var spec = MyVariableSpecification.Create(commParams);
return new MyProtocolVariable(variable, spec, isCommunicated);
}
// Receive data from the driver and route it into variables
public override async Task AddReceivedDataToQueueAsync(
IEnumerable<string> data, CancellationToken ct) { ... }
public override void ProcessReceivedData() { ... }
// Encode variable values for sending to the device
public override IEnumerable<string> Encode(
IEnumerable<IProtocolVariable> variables) { ... }
public override Task StartAsync(CancellationToken ct) { ... }
public override Task StopAsync(CancellationToken ct) { ... }
public override void Dispose() { ... }
}
Variable specification
The addressing ("which value belongs to which variable") is defined by
a class derived from ProtVariableSpecification — e.g. the Raw CAN protocol
keeps CanId, Offset, and ByteOrder in it. The values come from the
Comm params text field the user fills in when assigning a variable.
Deployment
Copy the DLL into the Protocols folder. The protocol appears in the
Home → Project Configuration → Protocols list and is added to
a compatible driver.

