2024-08-08 21:10:29 +02:00

44 lines
900 B
C++

#ifndef SERIAL_H
#define SERIAL_H
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#ifdef __cplusplus
#include <iostream>
#include <stdexcept>
#include <string.h>
#endif
#define BAUDRATE B38400
ssize_t sWrite(int port, char string[], size_t length);
ssize_t sWrite(int port, const char string[], size_t length);
ssize_t sRead(int port, void *buf, size_t count);
#ifdef __cplusplus
void printRates();
#endif
int serialport_set_config(int fd, int baud);
int serialport_init(const char* device, int baud = BAUDRATE, bool block = false);
#ifdef __cplusplus
class serialIoException: public std::runtime_error
{
public:
int fd;
int errorNumber;
serialIoException(int fd_, int errorNumber_):
std::runtime_error("file descriptor error, fd: " + std::to_string(fd_) + " error: " + strerror(errorNumber_) + "\n"),
fd(fd_), errorNumber(errorNumber_)
{}
};
#endif
#endif // SERIAL_H