Class real_time_tools::UsbStream

class real_time_tools::UsbStream

This class has for purpose to interact with devices and files alike as the linux philosophie does.

Depending on the current Operating system it uses the available real time APIs.

Public Functions

UsbStream()

Construct a new fstream object.

~UsbStream()

Destroy the fstream object.

bool open_device(const std::string &file_name)

This method allows you to open a port or a file.

Parameters

file_name

bool set_port_config(const PortConfig &user_config)

Set the _port_config object parametrize the port configuration.

Parameters

user_config – is the configuration of the port. (see struct PortConfig)

Returns

true

Returns

false

bool close_device()

Stop the device communication.

Returns

true success

Returns

false problem occured

bool read_device(std::vector<uint8_t> &msg, const bool stream_on = true)

Read the port or the file.

Parameters
  • msg – is the command sent before this command was executed.

  • stream_on – define if we just read on the fly or we wait until we get the correct amount of data.

Returns

true

Returns

false

bool write_device(const std::vector<uint8_t> &msg)

Write msg in the port or the file.

Returns

true success

Returns

false problem occured

bool activate_stream_mode()

Activate the stream mode.

The read method is not blocking.

Returns

true success

Returns

false problem occured

bool set_poll_mode_timeout(double timeout_in_second)

Set the poll mode timeout.

The read_device method is blocking until timeout.

Returns

true success

Returns

false problem occured

bool flush(int duration_ms = 150)

Flush the current port.

Returns

true

Returns

false

Public Static Functions

static std::string msg_debug_string(const std::vector<uint8_t> &msg, long int until = -1)

Display the uint8_t message in hexadecimal format.

Parameters
  • msg – is the message to be displayed

  • until – is a bound on the number of displayed bytes. “-1” means display all.

Returns

std::string the debug string

static bool test_msg_equal(const std::vector<uint8_t> &msg1, const std::vector<uint8_t> &msg2)

Test if two message are the same or not.

Parameters
  • msg1

  • msg2

Returns

true

Returns

false

Private Members

std::string file_name_

Private methods.

Attributes

This is the path tot the device file

int file_id_

This is the port id.

ssize_t return_value_

This is the return value of the different POSIX/Xenomai methods.

bool timeout_set_

Verify that the timeout value has been set.

double timeout_

The timeout for the poll mode in seconds.

std::vector<uint8_t> buffer_

Internal buffer that is supposed to be much bigger than the message sent or received to avoid memory problems.