MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ open_serial_port()

MAYAFLUX_API std::optional< Core::InputDeviceInfo > MayaFlux::open_serial_port ( const Core::SerialPortConfig & port)

List a serial port, apply its line setup and protocol, and open it.

The port is read the way port.protocol says and opened with port.line. A port already listed under the same path keeps its id and takes the new settings unless it is open. Needs GlobalInputConfig::serial and GlobalNetworkConfig::serial enabled.

Parameters
portThe port, as written by hand or returned by choose_serial_port().
Returns
The device, ready for InputDeviceInfo::to_binding() or bind_serial(), or nothing when serial input is not enabled or the port cannot be opened.

Definition at line 227 of file Input.cpp.

228{
229 auto* backend = require_serial_backend("open_serial_port");
230 if (!backend) {
231 return std::nullopt;
232 }
233
234 const uint32_t id = backend->add_port(port);
235 if (id == 0 || !backend->open_device(id)) {
236 return std::nullopt;
237 }
238
239 for (auto& device : backend->get_devices()) {
240 if (device.id == id) {
241 return device;
242 }
243 }
244 return std::nullopt;
245}