Skip to main content
Version: latest

SerialStream

Haply::HardwareAPI::IO::SerialStream

Provides an std::iostream compatible stream over for a serial port.

Meant to be used in conjunction with the Inverse3 and the Handle classes. The API provides the DeviceDetection class to easily find the serial ports that are currently associated with a Haply device.

OpenDevice or passing true to the parameter of SerialStream is required before the object can be used with one of the device classes.

Index

Methods

NameTypeDescription
SerialStream(const char *, bool)Constructs a SerialStream object from ...
~SerialStream()Closes the serial port and frees any associated resources.
OpenDevicechar()Opens the serial port making it usable by one of the device ...
CloseDevicevoid()This function closes the serial port.
Availableint()This function returns the number of bytes available to read ...
WriteBytesvoid(const char *, size_t)This function writes the given data to the serial port.

Methods

SerialStream

SerialStream(         const char * port,         bool open)

Constructs a SerialStream object from the given serial port.

WARNING If open is passed as and an error is raised while opening the port, an error will be written to stderr and the resulting object will not be valid.

Parameters

  • port The serial port to open. On Windows serial ports above 9 must be prefixed with to be valid. As an example, or should be used to open the serial port .

  • open If true, Opendevice will be called in the constructor.

~SerialStream

~SerialStream()

Closes the serial port and frees any associated resources.

OpenDevice

char OpenDevice()

Opens the serial port making it usable by one of the device classes.

Returns

Returns the value zero if the port was successfully opened. Returns a negative value if the serial port could not be opened and an error will be printed to stderr.

CloseDevice

void CloseDevice()

This function closes the serial port.

Called by the destructor and can be safely ignored in most circumstances.

Available

int Available()

This function returns the number of bytes available to read from the serial port.

Returns

The number of bytes available to read from the serial port.

WriteBytes

void WriteBytes(         const char * data,         size_t size)

This function writes the given data to the serial port.

Parameters

  • data The data to write to the serial port.

  • size The size of the data to write to the serial port.