MIP_SDK  latest-2-g34f3e39
MicroStrain Communications Library for embedded systems
Public Member Functions | Static Public Attributes | List of all members
microstrain::connections::SerialConnection Class Reference

Can be used on Windows, OSX, or linux to communicate with a MIP device over serial. More...

#include <serial_connection.hpp>

Inheritance diagram for microstrain::connections::SerialConnection:
microstrain::Connection microstrain::connections::UsbSerialConnection

Public Member Functions

 SerialConnection (std::string portName, uint32_t baudrate)
 Creates a Serial Connection that will communicate with a device over serial. More...
 
 ~SerialConnection () override
 Closes the underlying serial port. More...
 
bool recvFromDevice (uint8_t *buffer, size_t max_length, unsigned int wait_time_ms, size_t *length_out, EmbeddedTimestamp *timestamp_out) final
 Receives bytes from the device. More...
 
bool sendToDevice (const uint8_t *data, size_t length) final
 Sends bytes to the device. More...
 
bool isConnected () const override
 Check if the port is connected. More...
 
bool connect () override
 Connect to the port. More...
 
bool disconnect () override
 Disconnect from the port. More...
 
void connectionInfo (std::string &name, uint32_t &baudrate) const
 
uint32_t baudrate () const
 
bool setBaudrate (uint32_t baud)
 Change the baudrate. More...
 
const char * interfaceName () const override
 
uint32_t parameter () const override
 
- Public Member Functions inherited from microstrain::Connection
 Connection ()
 
virtual ~Connection ()
 
const char * type () const
 

Static Public Attributes

static constexpr const char * TYPE = "Serial"
 
- Static Public Attributes inherited from microstrain::Connection
static constexpr const char * TYPE = "None"
 

Additional Inherited Members

- Protected Attributes inherited from microstrain::Connection
const char * mType
 

Detailed Description

Can be used on Windows, OSX, or linux to communicate with a MIP device over serial.

Constructor & Destructor Documentation

◆ SerialConnection()

microstrain::connections::SerialConnection::SerialConnection ( std::string  portName,
uint32_t  baudrate 
)

Creates a Serial Connection that will communicate with a device over serial.

Parameters
portNamePath to the port to connect to. On Windows, this usually looks like "COM<N>", on linux, "/dev/tty<N>"
baudrateBaud rate to open the device at. Note that the device needs to be configured to

◆ ~SerialConnection()

microstrain::connections::SerialConnection::~SerialConnection ( )
override

Closes the underlying serial port.

Member Function Documentation

◆ baudrate()

uint32_t microstrain::connections::SerialConnection::baudrate ( ) const
inline

◆ connect()

bool microstrain::connections::SerialConnection::connect ( )
overridevirtual

Connect to the port.

Implements microstrain::Connection.

◆ connectionInfo()

void microstrain::connections::SerialConnection::connectionInfo ( std::string &  name,
uint32_t &  baudrate 
) const
inline

◆ disconnect()

bool microstrain::connections::SerialConnection::disconnect ( )
overridevirtual

Disconnect from the port.

Implements microstrain::Connection.

◆ interfaceName()

const char* microstrain::connections::SerialConnection::interfaceName ( ) const
inlineoverridevirtual

◆ isConnected()

bool microstrain::connections::SerialConnection::isConnected ( ) const
overridevirtual

Check if the port is connected.

Implements microstrain::Connection.

◆ parameter()

uint32_t microstrain::connections::SerialConnection::parameter ( ) const
inlineoverridevirtual

◆ recvFromDevice()

bool microstrain::connections::SerialConnection::recvFromDevice ( uint8_t *  buffer,
size_t  max_length,
unsigned int  wait_time_ms,
size_t *  length_out,
EmbeddedTimestamp timestamp_out 
)
finalvirtual

Receives bytes from the device.

Parameters
bufferBuffer to store the received data in
max_lengthMax number of bytes that can be read. Should be at most the length of buffer.
wait_time_msTime to wait for data in milliseconds.
length_outNumber of bytes actually read.
timestamp_outTimestamp of when the data was received

Implements microstrain::Connection.

◆ sendToDevice()

bool microstrain::connections::SerialConnection::sendToDevice ( const uint8_t *  data,
size_t  length 
)
finalvirtual

Sends bytes to the device.

Parameters
dataThe data to send to the device
lengthLength of data in bytes

Implements microstrain::Connection.

◆ setBaudrate()

bool microstrain::connections::SerialConnection::setBaudrate ( uint32_t  baud)

Change the baudrate.

Member Data Documentation

◆ TYPE

constexpr const char* microstrain::connections::SerialConnection::TYPE = "Serial"
staticconstexpr

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