43 std::string deviceName;
47 serial::Timeout timeout = serial::Timeout::simpleTimeout(
serialTimeout);
55 throw std::runtime_error(
"UC-board connection not established/lost.");
65 throw std::runtime_error(
"UC-board connection not established/lost.");
80 std::string devicePath;
82 struct dirent** fileList;
83 int numOfFiles = scandir(serialDevices.c_str(), &fileList, NULL, alphasort);
86 throw std::runtime_error(
"No serial devices found.");
89 for (
int i = 0; i < numOfFiles; i++)
92 if (std::string(fileList[i]->d_name).find(
deviceTag) != std::string::npos)
94 devicePath.append(serialDevices);
95 devicePath.append(std::string(fileList[i]->d_name));
100 if (devicePath.length() <= 0)
102 throw std::runtime_error(
"UC-board is not connected.");
105 char buffer1[PATH_MAX + 1];
106 size_t len = readlink(devicePath.c_str(), buffer1,
sizeof(buffer1) - 1);
111 char buffer2[PATH_MAX + 1];
112 char* rp = realpath(serialDevices.append(std::string(buffer1)).c_str(), buffer2);
113 deviceName = std::string(buffer2);
serial::Serial serialConnection
unsigned int serialTimeout
void setSerialTimeout(unsigned int serialTimeout)
Setter for the serial timeout.
void setMaxLineLength(unsigned int maxLineLength)
Setter for the maximum line length.
void disconnect()
try to close the connection to the serial device
std::string serialDevicesFolder
unsigned int maxLineLength
void setBaudRate(unsigned int baudRate)
Setter for the baudrate, which defines the bandwith of the communication.
void findDeviceName(std::string &deviceName)
Header file for the SerialInterface class.
SerialInterface()
SerialInterface default constructor.
void setDeviceTag(const std::string &deviceTag)
Setter for the device tag, which is an identifier a the connected serial device.
void connect()
try to open a connection to the serial device
void setSerialDevicesFolder(const std::string &serialDevicesFolder)
Setter for the path to the devices folder.
void send(std::string &message)
try to send a message to the serial device
void read(std::string &message, std::string &delimiter)
read a message from the serial input buffer