Serial
Use the Outstation::CreateSerialSessionFaultTolerant
method to create an outstation bound to a serial port. In addition to the common components, this method requires
the following serial port parameters:
- Path of the serial device (e.g.,
COM3
on Windows or/dev/ttyS3
on Linux) SerialSettings
struct:- Baud rate
- Data bits
- Stop bits
- Parity
- Flow control
- Period of time for retrying the serial port if it cannot be opened or is fails because it is removed from the OS.
The method will then either open the port or fail if the port doesn't exist or is already in use. The returned Outstation
class behaves identically to other transport types.
The LinkErrorMode
is internally set to Discard
for serial communication channels since serial ports do not provide data integrity.
- Rust
- C
- C++
- Java
- C#
let outstation = spawn_outstation_serial_fault_tolerant(
// change this for a real port
"/dev/ttySIM1",
SerialSettings::default(),
get_outstation_config(),
RetryStrategy::new(Duration::from_secs(1), Duration::from_secs(60)),
// customizable trait that controls outstation behavior
Box::new(ExampleOutstationApplication),
// customizable trait to receive events about what the outstation is doing
Box::new(ExampleOutstationInformation),
// customizable trait to process control requests from the master
Box::new(ExampleControlHandler),
);
dnp3_outstation_t* outstation = NULL;
dnp3_param_error_t err = dnp3_outstation_create_serial_session_fault_tolerant(
runtime,
"/dev/pts/4", // change to a real port
dnp3_serial_settings_init(), // default settings
5000, // retry the port every 5 seconds
get_outstation_config(),
get_outstation_application(),
get_outstation_information(),
get_control_handler(),
&outstation
);
// check error
auto outstation = dnp3::Outstation::create_serial_session_fault_tolerant(
runtime,
"/dev/pts/4", // change this to a real port
dnp3::SerialSettings(), // default settings
std::chrono::seconds(5), // retry the port every 5 seconds
get_outstation_config(),
std::make_unique<MyOutstationApplication>(),
std::make_unique<MyOutstationInformation>(),
std::make_unique<MyControlHandler>()
);
Outstation outstation = Outstation.createSerialSessionFaultTolerant(
runtime,
"/dev/pts/4",
new SerialSettings(),
Duration.ofSeconds(5), // try to open the port every 5 seconds
getOutstationConfig(),
new TestOutstationApplication(),
new TestOutstationInformation(),
new TestControlHandler()
);
var outstation = Outstation.CreateSerialSessionFaultTolerant(
runtime,
"COM1",
new SerialSettings(),
TimeSpan.FromSeconds(5), // try to open the port every 5 seconds
GetOutstationConfig(),
new TestOutstationApplication(),
new TestOutstationInformation(),
new TestControlHandler()
);
There is also Outstation::CreateSerialSession
method which opens the port on the calling thread and fails if it is not immediately available. The task spawned
by this thread will also shut down of the serial port is removed from the OS, e.g. if a USB to serial adapter is physically unplugged.
The fault-tolerant variant was added in the 1.1.0
release and is the preferred way of spawning a serial outstation. The non-fault tolerant version will be
removed in the next MAJOR release.