Skip to main content

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.

note

The LinkErrorMode is internally set to Discard for serial communication channels since serial ports do not provide data integrity.

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),
);
danger

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.