OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::Utils::Serial Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/Serial.hpp>

Inheritance diagram for Slic3r::Utils::Serial:
Collaboration diagram for Slic3r::Utils::Serial:

Public Member Functions

 Serial (boost::asio::io_context &io_service)
 Serial (boost::asio::io_context &io_service, const std::string &name, unsigned baud_rate)
 Serial (const Serial &)=delete
Serial & operator= (const Serial &)=delete
 ~Serial ()
void set_baud_rate (unsigned baud_rate)

Detailed Description

Constructor & Destructor Documentation

◆ Serial() [1/3]

Slic3r::Utils::Serial::Serial ( boost::asio::io_context & io_service)

Referenced by Serial(), and operator=().

Here is the caller graph for this function:

◆ Serial() [2/3]

Slic3r::Utils::Serial::Serial ( boost::asio::io_context & io_service,
const std::string & name,
unsigned baud_rate )

◆ Serial() [3/3]

Slic3r::Utils::Serial::Serial ( const Serial & )
delete

References Serial().

Here is the call graph for this function:

◆ ~Serial()

Slic3r::Utils::Serial::~Serial ( )
302{}

References ~Serial().

Referenced by ~Serial().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ operator=()

Serial & Slic3r::Utils::Serial::operator= ( const Serial & )
delete

References Serial().

Here is the call graph for this function:

◆ set_baud_rate()

void Slic3r::Utils::Serial::set_baud_rate ( unsigned baud_rate)
305{
306 try {
307 // This does not support speeds > 115200
308 set_option(boost::asio::serial_port_base::baud_rate(baud_rate));
309 } catch (boost::system::system_error &) {
310 auto handle = native_handle();
311
312 auto handle_errno = [](int retval) {
313 if (retval != 0) {
314 throw Slic3r::RuntimeError(
315 (boost::format("Could not set baud rate: %1%") % strerror(errno)).str()
316 );
317 }
318 };
319
320#if __APPLE__
321 termios ios;
322 handle_errno(::tcgetattr(handle, &ios));
323 handle_errno(::cfsetspeed(&ios, baud_rate));
324 speed_t newSpeed = baud_rate;
325 handle_errno(::ioctl(handle, IOSSIOSPEED, &newSpeed));
326 handle_errno(::tcsetattr(handle, TCSANOW, &ios));
327#elif __linux__
328
329 /* The following definitions are kindly borrowed from:
330 /usr/include/asm-generic/termbits.h
331 Unfortunately we cannot just include that one because
332 it would redefine the "struct termios" already defined
333 the <termios.h> already included by Boost.ASIO. */
334#define K_NCCS 19
335 struct termios2 {
336 tcflag_t c_iflag;
337 tcflag_t c_oflag;
338 tcflag_t c_cflag;
339 tcflag_t c_lflag;
340 cc_t c_line;
341 cc_t c_cc[K_NCCS];
342 speed_t c_ispeed;
343 speed_t c_ospeed;
344 };
345#ifndef BOTHER
346#define BOTHER CBAUDEX
347#endif
348
349 termios2 ios;
350 handle_errno(::ioctl(handle, TCGETS2, &ios));
351 ios.c_ispeed = ios.c_ospeed = baud_rate;
352 ios.c_cflag &= ~CBAUD;
353 ios.c_cflag |= BOTHER | CLOCAL | CREAD;
354 ios.c_cc[VMIN] = 1; // Minimum of characters to read, prevents eof errors when 0 bytes are read
355 ios.c_cc[VTIME] = 1;
356 handle_errno(::ioctl(handle, TCSETS2, &ios));
357
358#elif __OpenBSD__
359 struct termios ios;
360 handle_errno(::tcgetattr(handle, &ios));
361 handle_errno(::cfsetspeed(&ios, baud_rate));
362 handle_errno(::tcsetattr(handle, TCSAFLUSH, &ios));
363#else
364 throw Slic3r::RuntimeError("Custom baud rates are not currently supported on this OS");
365#endif
366 }
367}

References set_baud_rate().

Referenced by set_baud_rate().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/Serial.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/Serial.cpp