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

◆ open()

asio::error_code MayaFlux::Core::SerialTransport::open ( Stream & port,
const EndpointInfo & info )
static

Definition at line 87 of file SerialBackend.cpp.

88{
89 const SerialLineSettings& line = info.serial;
90 if (info.remote_path.empty() || line.data_bits < 5 || line.data_bits > 8) {
91 return asio::error::invalid_argument;
92 }
93
94 asio::error_code ec;
95 port.open(info.remote_path, ec);
96 if (ec) {
97 return ec;
98 }
99
100 const auto fail = [&port](const asio::error_code& cause) {
101 asio::error_code ignored;
102 port.close(ignored);
103 return cause;
104 };
105
106 port.set_option(asio::serial_port_base::character_size(line.data_bits), ec);
107 if (ec) {
108 return fail(ec);
109 }
110 port.set_option(asio::serial_port_base::parity(parity_of(line.parity)), ec);
111 if (ec) {
112 return fail(ec);
113 }
114 port.set_option(asio::serial_port_base::stop_bits(stop_bits_of(line.stop_bits)), ec);
115 if (ec) {
116 return fail(ec);
117 }
118 port.set_option(asio::serial_port_base::flow_control(flow_control_of(line.flow_control)), ec);
119 if (ec) {
120 return fail(ec);
121 }
122
123 port.set_option(asio::serial_port_base::baud_rate(line.baud_rate), ec);
124#if !defined(MAYAFLUX_PLATFORM_WINDOWS)
125 if (ec == asio::error::invalid_argument) {
126 const int error = detail::set_custom_baud(port.native_handle(), line.baud_rate);
127 ec = error == 0 ? asio::error_code {} : asio::error_code(error, asio::system_category());
128 }
129#endif
130 if (ec) {
131 return fail(ec);
132 }
133
134#if defined(MAYAFLUX_PLATFORM_WINDOWS)
135 ec = apply_lines(port, line.dtr_on_open, line.rts_on_open);
136#else
137 ec = apply_lines(port,
138 line.dtr_on_open ? std::nullopt : std::optional<bool> { false },
139 line.rts_on_open ? std::nullopt : std::optional<bool> { false });
140#endif
141 if (ec) {
142 return fail(ec);
143 }
144
145 return {};
146}
int set_custom_baud(int, uint32_t)
Set a baud rate the portable serial option table does not accept.
void error(Component component, Context context, std::source_location location, std::string_view message)
Log an error message and optionally throw an exception.
Vruta::SoundRoutine line(float start_value, float end_value, float duration_seconds, uint32_t step_duration, bool restartable)
Creates a continuous interpolation generator between two values over time.
Definition Tasks.cpp:60
Core::SerialLineSettings SerialLineSettings

References MayaFlux::Core::EndpointInfo::remote_path, MayaFlux::Core::EndpointInfo::serial, and MayaFlux::Core::detail::set_custom_baud().

Here is the call graph for this function: