File serial_reader.hppΒΆ

Wrapper for reading new-line terminated list of values from serial port.

Author

Julian Viereck

Date

2020

Copyright

Copyright (c) 2020, New York University and Max Planck Gesellschaft.

namespace blmc_drivers

This namespace is the standard namespace of the package.

class SerialReader
#include <serial_reader.hpp>

Public Functions

SerialReader(const std::string &serial_port, const int &num_values)
Parameters

serial_port – The address of the serial port to use. @pparam num_values The number of values to read in each line.

~SerialReader()
int fill_vector(std::vector<int> &values)

Fills a vector with the latest values.

Parameters

values – Vector to place values into.

Returns

How often fill_vector was called without new data.

Private Functions

void loop()

This is the real time thread that streams the data to/from the main board.

Private Members

bool is_loop_active_

This boolean makes sure that the loop is stopped upon destruction of this object.

real_time_tools::RealTimeThread rt_thread_

This is the thread object that allow to spwan a real-time thread or not dependening on the current OS.

int fd_

Holds the device serial port.

bool has_error_

If false, the communication is workinng as expected.

bool is_active_

If the communication is active.

int new_data_counter_
int missed_data_counter_
std::vector<int> latest_values_

Holds vector with the latest double values.

std::mutex mutex_

mutex_ multithreading safety

Private Static Functions

static inline THREAD_FUNCTION_RETURN_TYPE loop(void *instance_pointer)

This is the helper function used for spawning the real time thread.

Parameters

instance_pointer – is the current object in this case.

Returns

THREAD_FUNCTION_RETURN_TYPE depends on the current OS.