Use BinaryParsec.Protocols.Modbus.ModbusTcp when application code needs an MBAP-aware Modbus TCP parser with a shared PDU model.
open BinaryParsec.Protocols.Modbus
match ModbusTcp.TryParseFrame frameBytes with
| Ok frame ->
printfn "transaction=%d unit=%d function=%d payload-bytes=%d"
frame.TransactionId
frame.UnitId
frame.Pdu.FunctionCode
frame.Pdu.Payload.Length
| Error error ->
printfn "parse failed at byte %d: %s" error.Position.ByteOffset error.Messageopen BinaryParsec.Protocols.Modbus
let frame = ModbusTcp.ParseFrame frameBytesParseFrame raises InvalidDataException when the MBAP framing fields or shared PDU bytes are invalid.
TransactionIdandUnitIdstay on the transport frame model.Pduexposes the shared Modbus payload after MBAP framing is removed.Pdu.FunctionCodereports the logical function code.Pdu.RawFunctionCodepreserves the transmitted function byte.