22 lines
375 B
C
22 lines
375 B
C
|
|
// SerialPort.h
|
||
|
|
#pragma once
|
||
|
|
#include <string>
|
||
|
|
#include <termios.h>
|
||
|
|
|
||
|
|
class SerialPort
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
SerialPort();
|
||
|
|
~SerialPort();
|
||
|
|
|
||
|
|
bool openPort(const std::string &portName, int baudrate);
|
||
|
|
void closePort();
|
||
|
|
bool writeData(const uint8_t *data, size_t size);
|
||
|
|
|
||
|
|
private:
|
||
|
|
int fd;
|
||
|
|
termios tty;
|
||
|
|
|
||
|
|
speed_t getBaudrate(int baudrate);
|
||
|
|
};
|