acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
serial::serial Class Reference

#include <serial.h>

Inheritance diagram for serial::serial:
particle

Public Member Functions

 serial ()
 __creatable_from_library(directory_system, directory_system, "acme_windows_common");
virtual ~serial ()
virtual void initialize_serial (const string &port="", ::u32 baudrate=9600, struct timeout timeout=nullptr, enum_byte_size ebytesize=e_byte_size_eight, enum_parity eparity=e_parity_none, enum_stop_bit estopbit=e_stop_bit_one, enum_flow_control eflowcontrol=e_flow_control_none)
virtual void open ()
virtual bool isOpen () const
virtual void close ()
virtual::particle * read_synchronization ()
virtual::particle * write_synchronization ()
virtual size_t available ()
virtual bool waitReadable ()
virtual void waitByteTimes (size_t count)
virtual size_t read (::u8 *buffer, size_t size)
virtual size_t read (memory &buffer, size_t size=1)
virtual size_t read (string &buffer, size_t size=1)
virtual string read (size_t size=1)
virtual size_t readline (string &buffer, size_t size=65536, string eol="\n")
virtual string readline (size_t size=65536, string eol="\n")
virtual string_array_base readlines (size_t size=65536, string eol="\n")
virtual size_t write (const ::u8 *data, size_t size)
virtual size_t write (const memory &data)
virtual size_t write (const string &data)
virtual void setPort (const string &port)
virtual void _setPort (const string &port)
virtual string getPort () const
virtual void set_timeout (const struct timeout &timeout)
virtual void set_timeout (const class ::time &inter_byte_timeout, const class ::time &read_timeout_constant, ::u32 read_timeout_multiplier, const class ::time &write_timeout_constant, ::u32 write_timeout_multiplier)
virtual struct timeout getTimeout () const
virtual void setBaudrate (::u32 baudrate)
virtual::u32 getBaudrate () const
virtual void setBytesize (enum_byte_size ebytesize)
virtual enum_byte_size getBytesize () const
virtual void setParity (enum_parity eparity)
virtual enum_parity getParity () const
virtual void setStopbits (enum_stop_bit estopbit)
virtual enum_stop_bit getStopbits () const
virtual void setFlowcontrol (enum_flow_control eflowcontrol)
virtual enum_flow_control getFlowcontrol () const
virtual void flush ()
virtual void flushInput ()
virtual void flushOutput ()
virtual void sendBreak (::i32 time)
virtual void setBreak (bool level=true)
virtual void setRTS (bool level=true)
virtual void setDTR (bool level=true)
virtual bool waitForChange ()
virtual bool getCTS ()
virtual bool getDSR ()
virtual bool getRI ()
virtual bool getCD ()
virtual size_t _read (::u8 *buffer, size_t size)
virtual size_t _write (const ::u8 *data, size_t length)
virtual void _flush ()
virtual void _flushOutput ()
virtual void _flushInput ()
Public Member Functions inherited from particle
 particle (const ::particle &particle)
 particle (::particle &&particle)
bool is_null () const
bool is_set () const
bool is_ok () const
bool nok () const
void initialize (::particle *pparticle) override
void _initialize_particle (::particle *pparticle)
virtual void _on_initialize_app_consumer ()
bool _is_ok () const override
virtual bool should_run () const
virtual void on_notify (::particle *pparticle, enum_id eid)
virtual bool on_command_final (const ::atom &atom, ::user::activation_token *puseractivationtoken)
virtual bool check_pipe_node_client_executable_paths (const ::file::path &pathNode, const ::file::path &pathClient)
inline ::particle * trace_this () const
virtual enum_trace_level main_trace_level () const
bool is_debug_trace_level () const
virtual::particle * get_context_particle ()
inline ::particle * synchronization () const
void set_synchronization (::particle *pparticleSynchronization)
void defer_create_synchronization ()
void operator() (::topic *ptopic, ::handler_context *phandlercontext) override
virtual void on_initialize_particle ()
virtual::topic_pointer create_topic (const ::atom &atom)
virtual::extended_topic_pointer create_extended_topic (const ::atom &atom)
::mathematics::mathematics * mathematics () const
::prototype::prototype * prototype () const
::image::image_context * image () const
::image::imaging * imaging () const
::draw2d::draw2d * draw2d () const
::write_text::write_text * write_text () const
class::user::user * user () const
::platform::system * system () const
::platform::session * session () const
::platform::application * application () const
::platform::node * node () const
void delete_this () override
::datetime::datetime * datetime () const
::internet::internet * internet () const
::url::url_context * url () const
::crypto::crypto * crypto () const
::nano::nano * nano () const
::directory_context * directory () const
::directory_system * directory_system () const
::file_context * file () const
::file_system * file_system () const
::path_system * path_system () const
virtual::file::watcher * file_watcher () const
::pointer< ::file::item > file_item (const ::file::path &path)
::networking::networking * networking () const
::platform::http * http () const
virtual::factory::factory_pointer & factory () const
virtual::factory::factory_pointer & factory (const ::scoped_string &scopedstrLibrary) const
virtual::factory::factory_pointer & factory (const ::scoped_string &scopedstrComponent, const ::scoped_string &scopedstrImplementation) const
virtual::factory::factory * component_factory (const ::scoped_string &scopedstrComponent) const
virtual void install_message_routing (::channel *pchannel)
virtual::payload get_result_payload ()
virtual void set_finish ()
virtual bool is_branch_current () const
virtual const_char_pointer topic_text () const
virtual enum_trace_category trace_category (const ::particle *pparticle) const
virtual enum_trace_category trace_category () const
virtual::platform::tracer * tracer () const
virtual::trace_statement trace_statement () const
virtual::trace_statement & trace_statement_prefix (::trace_statement &statement) const
virtual::trace_statement log_statement () const
virtual::trace_statement debug () const
virtual::trace_statement information () const
virtual::trace_statement warning () const
virtual::trace_statement error () const
virtual::trace_statement fatal () const
virtual void tracef (enum_trace_level etracelevel, const_char_pointer pszFormat,...) const
virtual void formatf_trace (enum_trace_level etracelevel, const_char_pointer pszFormat, va_list &arguments) const
template<typename... Args>
void print_line (std::format_string< Args... > fmt, Args &&... args) const
template<typename... Args>
void err_line (std::format_string< Args... > fmt, Args &&... args) const
virtual void print_line (const ::scoped_string &scopedstr) const
virtual void print_out (const ::scoped_string &scopedstr) const
virtual void printf_line (const_char_pointer pszFormat,...) const
virtual void printf_out (const_char_pointer pszFormat,...) const
virtual void err_line (const ::scoped_string &scopedstr) const
virtual void err_out (const ::scoped_string &scopedstr) const
virtual void errf_line (const_char_pointer pszFormat,...) const
virtual void errf_out (const_char_pointer pszFormat,...) const
virtual void debugf (const_char_pointer pszFormat,...) const
virtual void informationf (const_char_pointer pszFormat,...) const
virtual void warningf (const_char_pointer pszFormat,...) const
virtual void errorf (const_char_pointer pszFormat,...) const
virtual void fatalf (const_char_pointer pszFormat,...) const
template<typename... Args>
void trace (enum_trace_level etracelevel, std::format_string< Args... > fmt, Args &&... args) const
template<typename... Args>
void debug (std::format_string< Args... > fmt, Args &&...args) const
template<typename... Args>
void information (std::format_string< Args... > fmt, Args &&... args) const
template<typename... Args>
void warning (std::format_string< Args... > fmt, Args &&... args) const
template<typename... Args>
void error (std::format_string< Args... > fmt, Args &&... args) const
template<typename... Args>
void fatal (std::format_string< Args... > fmt, Args &&... args) const
void trace (enum_trace_level etracelevel, const ::scoped_string &scopedstr) const
void debug (const scoped_string &scopedstr) const
void information (const scoped_string &scopedstr) const
void warning (const scoped_string &scopedstr) const
void error (const scoped_string &scopedstr) const
void fatal (const scoped_string &scopedstr) const
virtual lresult message_handler (::user::enum_message eusermessage, ::wparam wparam, ::lparam lparam)
 virtual void send_call(const ::call & call);
virtual void handle (::topic *ptopic, ::handler_context *phandlercontext)
virtual void handle (const ::call &call)
virtual void handle_message (::message::message *pmessage)
virtual void handle_item (::item *pitem)
virtual lresult message_call (::user::enum_message eusermessage, ::wparam wparam={}, ::lparam lparam={})
virtual void call_handle (::topic *ptopic, ::handler_context *phandlercontext)
virtual void call_handle_message (::message::message *pmessage)
virtual void call_handle_item (::item *pitem)
virtual bool _handle_uri (const ::scoped_string &scopedstrUri)
virtual bool _handle_call (::payload &payload, const ::scoped_string &scopedstrObject, const ::scoped_string &scopedstrMember, ::property_set &propertyset)
virtual void call_member (::i64 hi)
virtual::lresult call_message (const ::user::enum_message &emessage, ::wparam wparam={}, ::lparam lparam={}, ::particle *pparticle=nullptr)
virtual::lresult call_id_topic (const ::enum_id &eid, ::wparam wparam={}, ::lparam lparam={}, ::particle *pparticle=nullptr)
virtual::payload realize ()
virtual void set_generic_object_name (const ::scoped_string &scopedstrName)
virtual void set_library_name (const ::scoped_string &scopedstrLibraryName)
virtual void set_application_id (const ::scoped_string &scopedstrApplicationId)
virtual::particle * get_taskpool_container ()
virtual::task_pool * taskpool ()
virtual const_char_pointer debug_note () const
virtual bool should_run_async () const
virtual ::pointer<::user_interface::message_box > message_box (const ::scoped_string &scopedstrMessage, const ::scoped_string &scopedstrTitle=nullptr, const ::user::e_message_box &emessagebox={}, const ::scoped_string &scopedstrDetails=nullptr, const ::string_array_base *pstraIconUrl=nullptr)
virtual ::pointer<::user_interface::message_box > message_box (const ::exception &exception, const ::scoped_string &scopedstrMessage=nullptr, const ::scoped_string &scopedstrTitle=nullptr, const ::user::e_message_box &emessagebox={}, const ::scoped_string &scopedstrDetails=nullptr, const ::string_array_base *pstraIconUrl=nullptr)
virtual::file_pointer get_file (const ::payload &payloadFile, ::file::e_open eopen, ::pointer< ::file::exception > *pfileexception=nullptr)
template<typename BASE_TYPE>
inline ::pointer< BASE_TYPE > __call__create (::factory::factory *pfactory=nullptr)
template<typename TYPE>
inline ::pointer< TYPE > __call__create_new ()
template<typename TYPE>
inline ::pointer< TYPE > __call__create_new_clone (TYPE *p)
template<typename T, typename ... Args>
::pointer< T > __call__allocate_and_initialize (Args &&... args)
template<typename TYPE>
TYPE * __initialize (TYPE *p)
template<typename TYPE>
inline ::pointer< TYPE > __initialize (::pointer< TYPE > &&p)
template<typename T>
::pointer< T > create_clone (const ::pointer< T > &psource)
template<typename T>
::pointer< T > create_clone (const T *pSource)
 consumes a referer
template<typename T>
::pointer< T > __call__create_new_clone (const T *pSource)
 consumes a referer
virtual void app_post (const ::procedure &procedure)
virtual::task_pointer app_fork (const ::procedure &procedure)
virtual void task_post (const ::procedure &procedure)
virtual::task_pointer task_fork (const ::procedure &procedure)
virtual void user_send (const ::procedure &procedure)
dispatch_arrayø user_sendø ()
virtual void user_post (const ::procedure &procedure)
dispatch_arrayø user_postø ()
virtual void main_send (const ::procedure &procedure)
dispatch_arrayø main_sendø ()
virtual void main_post (const ::procedure &procedure)
dispatch_arrayø main_postø ()
virtual class::time get_default_run_timeout ()
virtual void send (const ::procedure &procedure)
dispatch_arrayø sendø ()
virtual void post (const ::procedure &procedure)
dispatch_arrayø postø ()
virtual void handle (bool bSynchronously, const ::procedure &procedure)
virtual void dispatch_procedure (enum_dispatch edispatch, const procedure &procedure)
virtual void dispatch (const dispatch_array2 &dispatcha)
template<typename BASE_TYPE>
bool __call__defer_construct (::pointer< BASE_TYPE > &ptype, ::factory::factory *pfactory=nullptr)
template<typename TYPE>
bool __calldefer_construct_newø (::pointer< TYPE > &ptype)
template<typename TYPE>
bool __call__defer_raw_construct_new (::pointer< TYPE > &ptype)
template<typename BASE_TYPE>
void __call__construct (::pointer< BASE_TYPE > &ptype, ::factory::factory *pfactory=nullptr)
template<typename BASE_TYPE>
void __call__construct_by_type (::pointer< BASE_TYPE > &ptype, const ::platform::type &type, ::factory::factory *pfactory=nullptr)
virtual ::pointer<::particle > __call__create_by_type (const ::platform::type &type, ::factory::factory *pfactory=nullptr)
virtual ::pointer<::particle > __call__create_by_custom_id (const ::type_custom_id &typecustomid, ::factory::factory *pfactory=nullptr)
virtual ::pointer<::particle > __call__create_by_ipair (const ::type_iptr_pair &ipair, ::factory::factory *pfactory=nullptr)
template<typename TYPE>
void __call__construct_new (::pointer< TYPE > &ptype)
template<typename TYPE>
void __call__raw_construct (::pointer< TYPE > &p, ::factory::factory *pfactory=nullptr COMMA_REFERENCING_DEBUGGING_PARAMETERS_DECLARATION)
template<typename T, typename ... Args>
void __call__emplace_new (::pointer< T > &p, Args &&... args)
template<typename T, typename ... Args>
void __call__emplace_new (::auto_pointer< T > &p, Args &&... args)
template<typename BASE_TYPE>
inline ::pointer< BASE_TYPE > __raw_create (::factory::factory *pfactory=nullptr)
virtual void * new_object (const_char_pointer psz)
virtual string as_string () const
virtual void kick_idle ()
particle & operator= (const particle &particle)
virtual::user::user * user ()
virtual void process_owned_procedure_list (::procedure_list_base &procedurelist, bool &bHandled)
virtual memory_file_pointer create_memory_file ()
virtual memory_file_pointer create_memory_file (::memory_base &memory)
virtual memory_file_pointer create_memory_file (const ::block &block)
virtual memory_file_pointer create_memory_file_as_copy (const memory &memory)
virtual memory_file_pointer create_memory_file_by_reading (::file::file *pfile)
virtual void assert_particle_ok () const
template<typename BASE_TYPE>
inline ::pointer< BASE_TYPE > __call__create (::factory::factory *pfactory)
template<typename TYPE>
inline ::pointer< TYPE > __call__create_new ()
template<typename TYPE>
inline ::pointer< TYPE > __call__create_new_clone (TYPE *psrc)
template<typename TYPE>
void __call__raw_construct (::pointer< TYPE > &p, ::factory::factory *pfactory COMMA_REFERENCING_DEBUGGING_PARAMETERS_DEFINITION)
template<typename BASE_TYPE>
inline ::pointer< BASE_TYPE > __raw_create (::factory::factory *pfactory)
template<typename TYPE>
bool __call__defer_construct (::pointer< TYPE > &p, ::factory::factory *pfactory)
template<typename TYPE>
void __call__construct_by_type (::pointer< TYPE > &p, const ::platform::type &type, ::factory::factory *pfactory)
virtual void call ()

Additional Inherited Members

Static Public Member Functions inherited from particle
static class::platform::platform * platform ()
Public Attributes inherited from particle
mutable::platform::application * m_papplication
mutable::particle_pointer m_pparticleSynchronization

Detailed Description

Class that provides a portable serial port interface.

Constructor & Destructor Documentation

◆ serial()

serial::serial::serial ( )

__creatable_from_library(directory_system, directory_system, "acme_windows_common");

Creates a serial matter and opens the port if a port is specified, otherwise it remains closed until serial::serial::open is called.

\lparam port A string containing the address of the serial port, which would be something like 'COM1' on Windows and '/dev/ttyS0' on Linux.

\lparam baudrate An ::u32 32-bit integer that represents the baudrate

\lparam timeout A serial::timeout struct that defines the timeout conditions for the serial port.

See also
serial::timeout

\lparam ebytesize Size of each ::u8 in the serial transmission of data, default is e_byte_size_eight, possible values are: fivebits, sixbits, sevenbits, e_byte_size_eight

\lparam eparity Method of eparity, default is e_parity_none, possible values are: e_parity_none, eparity_odd, eparity_even

\lparam estopbit Number of stop bits used, default is e_stop_bit_one, possible values are: e_stop_bit_one, e_stop_bit_one_point_five, estopbit_two

\lparam eflowcontrol Type of eflowcontrol used, default is e_flow_control_none, possible values are: e_flow_control_none, e_flow_control_software, e_flow_control_hardware

Exceptions
exception(serial::port_not_opened_exception
exception(serial::io_exception
exception(invalid_argument

◆ ~serial()

serial::serial::~serial ( )
virtual

Destructor

Member Function Documentation

◆ available()

size_t serial::serial::available ( )
virtual

Return the number of characters in the buffer.

◆ close()

void serial::serial::close ( )
virtual

Closes the serial port.

◆ flush()

void serial::serial::flush ( )
virtual

Flush the input and output buffers

◆ flushInput()

void serial::serial::flushInput ( )
virtual

Flush only the input buffer

◆ flushOutput()

void serial::serial::flushOutput ( )
virtual

Flush only the output buffer

◆ getBaudrate()

u32 serial::serial::getBaudrate ( ) const

Gets the baudrate for the serial port.

Returns
An integer that sets the baud rate for the serial port.
See also
serial::setBaudrate
Exceptions
exception(invalid_argument

◆ getBytesize()

enum_byte_size serial::serial::getBytesize ( ) const
virtual

Gets the ebytesize for the serial port.

See also
serial::setBytesize
Exceptions
exception(invalid_argument

◆ getCD()

bool serial::serial::getCD ( )
virtual

Returns the current status of the CD line.

◆ getCTS()

bool serial::serial::getCTS ( )
virtual

Returns the current status of the CTS line.

◆ getDSR()

bool serial::serial::getDSR ( )
virtual

Returns the current status of the DSR line.

◆ getFlowcontrol()

enum_flow_control serial::serial::getFlowcontrol ( ) const
virtual

Gets the flow control for the serial port.

See also
serial::setFlowcontrol
Exceptions
exception(invalid_argument

◆ getParity()

enum_parity serial::serial::getParity ( ) const
virtual

Gets the eparity for the serial port.

See also
serial::setParity
Exceptions
exception(invalid_argument

◆ getPort()

string serial::serial::getPort ( ) const
virtual

Gets the serial port identifier.

See also
serial::setPort
Exceptions
exception(invalid_argument

◆ getRI()

bool serial::serial::getRI ( )
virtual

Returns the current status of the RI line.

◆ getStopbits()

enum_stop_bit serial::serial::getStopbits ( ) const
virtual

Gets the estopbit for the serial port.

See also
serial::setStopbits
Exceptions
exception(invalid_argument

◆ getTimeout()

struct timeout serial::serial::getTimeout ( ) const
virtual

Gets the timeout for reads in seconds.

Returns
A timeout struct containing the inter_byte_timeout, and read and write timeout constants and multipliers.
See also
serial::setTimeout

◆ isOpen()

bool serial::serial::isOpen ( ) const
virtual

Gets the open status of the serial port.

Returns
Returns true if the port is open, false otherwise.

◆ open()

void serial::serial::open ( )
virtual

Opens the serial port as long as the port is set and the port isn't already open.

If the port is provided to the constructor then an explicit call to open is not needed.

See also
serial::serial
Exceptions
exception(invalid_argument
exception(serial::serial_exception
exception(serial::io_exception

◆ read() [1/4]

size_t serial::serial::read ( ::u8 * buffer,
size_t size )
virtual

Read a given amount of bytes from the serial port into a given buffer.

The read function will return in one of three cases:

  • The number of requested bytes was read.
    • In this case the number of bytes requested will match the size_t returned by read.
  • A timeout occurred, in this case the number of bytes read will not match the amount requested, but no exception will be thrown. One of two possible timeouts occurred:
    • The inter ::u8 timeout expired, this means that number of ::times elapsed between receiving bytes from the serial port exceeded the inter ::u8 timeout.
    • The total timeout expired, which is calculated by multiplying the read timeout multiplier by the number of requested bytes and then added to the read timeout constant. If that total number of ::times elapses after the initial call to read a timeout will occur.
  • An exception occurred, in this case an actual exception will be thrown.

\lparam buffer An ::u8 array of at least the requested size. \lparam i32_size A size_t defining how many bytes to be read.

Returns
A size_t representing the number of bytes read as a result of the call to read.
Exceptions
exception(serial::port_not_opened_exception
exception(serial::serial_exception

◆ read() [2/4]

size_t serial::serial::read ( memory & buffer,
size_t size = 1 )
virtual

Read a given amount of bytes from the serial port into a give buffer.

\lparam buffer A matter to a vector of ::u8. \lparam i32_size A size_t defining how many bytes to be read.

Returns
A size_t representing the number of bytes read as a result of the call to read.
Exceptions
exception(serial::port_not_opened_exception
exception(serial::serial_exception

◆ read() [3/4]

string serial::serial::read ( size_t size = 1)
virtual

Read a given amount of bytes from the serial port and return a string containing the data.

\lparam i32_size A size_t defining how many bytes to be read.

Returns
A string containing the data read from the port.
Exceptions
exception(serial::port_not_opened_exception
exception(serial::serial_exception

◆ read() [4/4]

size_t serial::serial::read ( string & buffer,
size_t size = 1 )
virtual

Read a given amount of bytes from the serial port into a give buffer.

\lparam buffer A matter to a string. \lparam i32_size A size_t defining how many bytes to be read.

Returns
A size_t representing the number of bytes read as a result of the call to read.
Exceptions
exception(serial::port_not_opened_exception
exception(serial::serial_exception

◆ readline() [1/2]

string serial::serial::readline ( size_t size = 65536,
string eol = "\n" )
virtual

Reads in a line or until a given delimiter has been processed.

Reads from the serial port until a single line has been read.

\lparam i32_size A maximum length of a line, defaults to 65536 (2^16) \lparam eol A string to match against for the EOL.

Returns
A string containing the line.
Exceptions
exception(serial::port_not_opened_exception
exception(serial::serial_exception

◆ readline() [2/2]

size_t serial::serial::readline ( string & buffer,
size_t size = 65536,
string eol = "\n" )
virtual

Reads in a line or until a given delimiter has been processed.

Reads from the serial port until a single line has been read.

\lparam buffer A string matter used to store the data. \lparam i32_size A maximum length of a line, defaults to 65536 (2^16) \lparam eol A string to match against for the EOL.

Returns
A size_t representing the number of bytes read.
Exceptions
exception(serial::port_not_opened_exception
exception(serial::serial_exception

◆ readlines()

string_array_base serial::serial::readlines ( size_t size = 65536,
string eol = "\n" )
virtual

Reads in multiple lines until the serial port times out.

This requires a timeout > 0 before it can be run. It will read until a timeout occurs and return a list_base of strings.

\lparam i32_size A maximum length of combined lines, defaults to 65536 (2^16)

\lparam eol A string to match against for the EOL.

Returns
A vector<string> containing the lines.
Exceptions
exception(serial::port_not_opened_exception
exception(serial::serial_exception

◆ sendBreak()

void serial::serial::sendBreak ( ::i32 time)
virtual

Sends the RS-232 break signal. See tcsendbreak(3).

◆ set_timeout() [1/2]

virtual void serial::serial::set_timeout ( const class ::time & inter_byte_timeout,
const class ::time & read_timeout_constant,
::u32 read_timeout_multiplier,
const class ::time & write_timeout_constant,
::u32 write_timeout_multiplier )
inlinevirtual

Sets the timeout for reads and writes.

◆ set_timeout() [2/2]

virtual void serial::serial::set_timeout ( const struct timeout & timeout)
virtual

Sets the timeout for reads and writes using the timeout struct.

There are two timeout conditions described here:

  • The inter ::u8 timeout:
    • The inter_byte_timeout component of serial::timeout defines the maximum amount of time, in ::times, between receiving bytes on the serial port that can pass before a timeout occurs. Setting this to zero will prevent inter ::u8 timeouts from occurring.
  • Total time timeout:
    • The constant and multiplier component of this timeout condition, for both read and write, are defined in serial::timeout. This timeout occurs if the total time since the read or write call was made exceeds the specified time in ::times.
    • The limit is defined by multiplying the multiplier component by the number of requested bytes and adding that product to the constant component. In this way if you want a read call, for example, to timeout after exactly one second regardless of the number of bytes you asked for then set the read_timeout_constant component of serial::timeout to 1000 and the read_timeout_multiplier to zero. This timeout condition can be used in conjunction with the inter ::u8 timeout condition with out any problems, timeout will simply occur when one of the two timeout conditions is met. This allows users to have maximum control over the trade-off between responsiveness and efficiency.

Read and write functions will return in one of three cases. When the reading or writing is complete, when a timeout occurs, or when an exception occurs.

A timeout of 0 enables non-blocking mode.

\lparam timeout A serial::timeout struct containing the inter ::u8 timeout, and the read and write timeout constants and multipliers.

See also
serial::timeout

◆ setBaudrate()

void serial::serial::setBaudrate ( ::u32 baudrate)
virtual

Sets the baudrate for the serial port.

Possible baudrates depends on the system but some safe baudrates include: 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 56000, 57600, 115200 Some other baudrates that are supported by some comports: 128000, 153600, 230400, 256000, 460800, 921600

\lparam baudrate An integer that sets the baud rate for the serial port.

Exceptions
exception(invalid_argument

◆ setBreak()

void serial::serial::setBreak ( bool level = true)
virtual

Set the break condition to a given level. Defaults to true.

◆ setBytesize()

void serial::serial::setBytesize ( enum_byte_size ebytesize)
virtual

Sets the ebytesize for the serial port.

\lparam ebytesize Size of each ::u8 in the serial transmission of data, default is e_byte_size_eight, possible values are: fivebits, sixbits, sevenbits, e_byte_size_eight

Exceptions
exception(invalid_argument

◆ setDTR()

void serial::serial::setDTR ( bool level = true)
virtual

Set the DTR handshaking line to the given level. Defaults to true.

◆ setFlowcontrol()

void serial::serial::setFlowcontrol ( enum_flow_control eflowcontrol)
virtual

Sets the flow control for the serial port.

\lparam eflowcontrol Type of eflowcontrol used, default is e_flow_control_none, possible values are: e_flow_control_none, e_flow_control_software, e_flow_control_hardware

Exceptions
exception(invalid_argument

◆ setParity()

void serial::serial::setParity ( enum_parity eparity)
virtual

Sets the eparity for the serial port.

\lparam eparity Method of eparity, default is e_parity_none, possible values are: e_parity_none, eparity_odd, eparity_even

Exceptions
exception(invalid_argument

◆ setPort()

void serial::serial::setPort ( const string & port)
virtual

Sets the serial port identifier.

\lparam port A const string matter containing the address of the serial port, which would be something like 'COM1' on Windows and '/dev/ttyS0' on Linux.

Exceptions
exception(invalid_argument

◆ setRTS()

void serial::serial::setRTS ( bool level = true)
virtual

Set the RTS handshaking line to the given level. Defaults to true.

◆ setStopbits()

void serial::serial::setStopbits ( enum_stop_bit estopbit)
virtual

Sets the estopbit for the serial port.

\lparam estopbit Number of stop bits used, default is e_stop_bit_one, possible values are: e_stop_bit_one, e_stop_bit_one_point_five, estopbit_two

Exceptions
exception(invalid_argument

◆ waitByteTimes()

void serial::serial::waitByteTimes ( size_t count)
virtual

Block for a period of time corresponding to the transmission time of count characters at present serial settings. This may be used in con- junction with waitReadable to read larger blocks of data from the port.

◆ waitForChange()

bool serial::serial::waitForChange ( )
virtual

Blocks until CTS, DSR, RI, CD changes or something interrupts it.

Can throw exception( an exception if an error occurs while waiting. You can check the status of CTS, DSR, RI, and CD once this returns. Uses TIOCMIWAIT via ioctl if available (mostly only on Linux) with a resolution of less than +-1ms and as good as +-0.2ms. Otherwise a polling method is used which can give +-2ms.

Returns
Returns true if one of the lines changed, false if something else occurred.
Exceptions
exception(serial_exception

◆ waitReadable()

bool serial::serial::waitReadable ( )
virtual

Block until there is serial data to read or read_timeout_constant number of ::times have elapsed. The return value is true when the function exits with the port in a readable state, false otherwise (due to timeout or select interruption).

◆ write() [1/3]

size_t serial::serial::write ( const ::u8 * data,
size_t size )
virtual

Write a string to the serial port.

\lparam data A const matter containing the data to be written to the serial port.

\lparam i32_size A size_t that indicates how many bytes should be written from the given data buffer.

Returns
A size_t representing the number of bytes actually written to the serial port.
Exceptions
exception(serial::port_not_opened_exception
exception(serial::serial_exception
exception(serial::io_exception

◆ write() [2/3]

size_t serial::serial::write ( const memory & data)
virtual

Write a string to the serial port.

\lparam data A const matter containing the data to be written to the serial port.

Returns
A size_t representing the number of bytes actually written to the serial port.
Exceptions
exception(serial::port_not_opened_exception
exception(serial::serial_exception
exception(serial::io_exception

◆ write() [3/3]

size_t serial::serial::write ( const string & data)
virtual

Write a string to the serial port.

\lparam data A const matter containing the data to be written to the serial port.

Returns
A size_t representing the number of bytes actually written to the serial port.
Exceptions
exception(serial::port_not_opened_exception
exception(serial::serial_exception
exception(serial::io_exception

The documentation for this class was generated from the following files: