SerialUnix.h 765 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once

#include "SerialCommon.h"

#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h> //Timer
#include <fcntl.h> //Device settings
#include <termios.h> //For serial comm
#include <sys/ioctl.h> //For ioctl
#include <string.h> // needed for memset

#include <string>
#include <vector>
#include <ctime>

class Serial
{
public:
	Serial();
	void init();
	int startConnection(const char* port);
	void closeConnection();
	bool isConnected(const char* port = "");

	void writeSerial(const char* buffer);

	int manageSerial();

	std::string readSerial();
private:
	int tty_fd;
	struct termios tio;

	std::vector<std::string> _commands;
	std::string _cur_command;
	std::clock_t timer;

	std::string _port;
	bool _ready;
	bool _isConnected;
};