Low level serial methods. More...
#include <ABBAuroraSerial.h>
Public Member Functions | |
| ABBAuroraSerial (const unsigned char &log) | |
| Default constructor. More... | |
| ~ABBAuroraSerial (void) | |
| Default destructor. More... | |
| bool | Begin (const std::string &device, const speed_t &baudrate) |
| Begin communication. More... | |
| int | ReadBytes (uint8_t *buffer, const int &length) |
| Read bytes. More... | |
| int | WriteBytes (uint8_t const *buffer, const int &length) |
| Write bytes. More... | |
| void | Flush (void) const |
| Flush buffers. More... | |
| uint16_t | Word (const uint8_t &msb, const uint8_t &lsb) const |
| Return word. More... | |
| uint16_t | Crc16 (uint8_t *data, const int &offset, const int &count) const |
| Calculate checksum. More... | |
| uint8_t | LowByte (const uint16_t &bytes) const |
| Return low byte. More... | |
| uint8_t | HighByte (const uint16_t &bytes) const |
| Return high byte. More... | |
| std::string | GetErrorMessage (void) |
| Get error message. More... | |
Private Attributes | |
| int | SerialPort |
| Serial port number. | |
| std::string | ErrorMessage |
| Error message string. | |
| unsigned char | Log |
| Log level. | |
Low level serial methods.
Methods to handle the serial communication between host and device
| ABBAuroraSerial::ABBAuroraSerial | ( | const unsigned char & | log | ) |
Default constructor.
Sets the log level of the class
| log | set log level |
| ABBAuroraSerial::~ABBAuroraSerial | ( | void | ) |
Default destructor.
Closes the serial port and deletes the serial object
| bool ABBAuroraSerial::Begin | ( | const std::string & | device, |
| const speed_t & | baudrate | ||
| ) |
Begin communication.
Opens the serial port and sets communication parameters
| device | The serial device, i.e. /dev/ttyUSB0 |
| baudrate | The serial baud rate |
| uint16_t ABBAuroraSerial::Crc16 | ( | uint8_t * | data, |
| const int & | offset, | ||
| const int & | count | ||
| ) | const |
Calculate checksum.
Calculate a CCITT CRC 16 checksum
| data | Buffer with data |
| offset | Start calucation at an offset |
| count | Number of bytes to include |
| void ABBAuroraSerial::Flush | ( | void | ) | const |
Flush buffers.
Flushes/discards data which is written but not transmitted and/or data which is received but not read by the user
| std::string ABBAuroraSerial::GetErrorMessage | ( | void | ) |
Get error message.
Returns the error message of a failure
| uint8_t ABBAuroraSerial::HighByte | ( | const uint16_t & | bytes | ) | const |
Return high byte.
Return the most significant (high) byte of a word
| bytes | Word to convert |
| uint8_t ABBAuroraSerial::LowByte | ( | const uint16_t & | bytes | ) | const |
Return low byte.
Return the least significant (low) byte of a word
| bytes | Word to convert |
| int ABBAuroraSerial::ReadBytes | ( | uint8_t * | buffer, |
| const int & | length | ||
| ) |
Read bytes.
Read bytes available in the input buffer
| buffer | Buffer to store the bytes |
| length | Number of bytes to read |
| uint16_t ABBAuroraSerial::Word | ( | const uint8_t & | msb, |
| const uint8_t & | lsb | ||
| ) | const |
Return word.
Construct a word (2 bytes) from two single bytes
| msb | Most significant (left) byte |
| lsb | Least significant (right) byte |
| int ABBAuroraSerial::WriteBytes | ( | uint8_t const * | buffer, |
| const int & | length | ||
| ) |
Write bytes.
Transmit bytes to the device
| buffer | Buffer with bytes to send |
| length | Number of bytes to send |