This page is for choosing and using the public library entrypoints.
Design Summary
The library design is intentionally simple:
- no exceptions
- no RTTI
- no dynamic allocation in the library
- caller-owned buffers via
std::span
- transport-agnostic client state machine
Entry Paths
1. High-level helpers
Use mcprotocol/serial/high_level.hpp if you want:
- baseline
ProtocolConfig presets
- string-address parsing such as
D100, M100, X10
- request builders for common contiguous, sparse random, and monitor operations
Smallest helper-based setup:
#include <array>
Single-include entry point for the public serial client API.
constexpr ProtocolConfig make_c4_binary_protocol(PlcSeries series=PlcSeries::Q_L) noexcept
Returns a practical default for Q/L-era Format5 / Binary / C4.
Status make_batch_read_words_request(std::string_view head_device, std::uint16_t points, BatchReadWordsRequest &out_request) noexcept
Builds a contiguous word-read request from a string address such as D100.
Top-level protocol configuration shared by codecs and client requests.
RouteConfig route
Route header fields used for every encoded request.
std::uint8_t station_no
Target station number on multidrop serial links.
Result object returned by most public APIs.
2. Synchronous host-side facade
Use mcprotocol/serial/host_sync.hpp if you want a small blocking host-side bring-up path on Windows or POSIX.
It wraps PosixSerialPort and MelsecSerialClient into a single helper for:
cpu-model
remote_run
remote_stop
remote_pause
remote_latch_clear
unlock_remote_password
lock_remote_password
clear_error_information
remote_reset
- contiguous
read_words
- contiguous
read_bits
- contiguous
write_words
- contiguous
write_bits
- sparse
random_read
- sparse
random_write_words
- sparse
random_write_bits
register_monitor and read_monitor
Smallest synchronous host-side setup:
#if defined(_WIN32)
#else
.device_path = "/dev/ttyUSB0",
#endif
.baud_rate = 19200,
.data_bits = 8,
.stop_bits = 2,
.parity = 'E',
};
Host-side synchronous convenience wrapper built on PosixSerialPort and MelsecSerialClient.
Status random_read(std::span< const highlevel::RandomReadSpec > items, std::span< std::uint32_t > out_values) noexcept
Reads sparse word/dword items synchronously from string-address specs.
Status open(const PosixSerialConfig &serial_config, const ProtocolConfig &protocol_config) noexcept
Opens the serial port and configures the underlying MC protocol client.
Status read_words(std::string_view head_device, std::uint16_t points, std::span< std::uint16_t > out_words) noexcept
Reads contiguous words synchronously from a string address such as D100.
Host-side serial-port configuration used by PosixSerialPort.
std::string_view device_path
On Windows, pass COM3-style names. On POSIX hosts, pass /dev/ttyUSB0-style device paths.
3. Low-level async client
Use MelsecSerialClient directly if you want the full async state machine and plan to integrate your own UART layer or scheduler.
Normal workflow:
- Configure
MelsecSerialClient
- Start an async request
- Send
pending_tx_frame() with your UART layer
- Call
notify_tx_complete()
- Feed received bytes through
on_rx_bytes()
- Call
poll() for timeout handling
Example Index