Espia.h 1.02 KB
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
#ifndef ESPIA_H
#define ESPIA_H

#include "Exceptions.h"
#include "espia_lib.h"
#include <string>

namespace lima
{

class Espia
{
 public:
	enum {
		Invalid = -1,
	};

	Espia(int dev_nr);
	~Espia();

	void serWrite(const std::string& buffer, 
		      int block_size = 0, double block_delay = 0, 
		      bool no_wait = false);
ahoms's avatar
ahoms committed
24
25
	void serRead(std::string& buffer, int len, double timeout);
	void serReadStr(std::string& buffer, int len, 
26
			const std::string& term, double timeout);
ahoms's avatar
ahoms committed
27
	void serFlush();
28
29
30
31
32
33
34

	static void throwError(int ret, std::string file, std::string func, 
			       int line);

 private:
	void open(int dev_nr);
	void close();
ahoms's avatar
ahoms committed
35
36
	unsigned long sec2us(double sec);

37
38
39
40
41
42
43
44
45
46
	int m_dev_nr;
	espia_t m_dev;

};

#define ESPIA_CHECK_CALL(ret)						\
	do {								\
		int aux_ret = (ret);					\
		if (aux_ret < 0)					\
			Espia::throwError(aux_ret, __FILE__,		\
ahoms's avatar
ahoms committed
47
					  __FUNCTION__, __LINE__);	\
48
49
50
	} while (0)


ahoms's avatar
ahoms committed
51
52
53
54
55
56
inline unsigned long Espia::sec2us(double sec)
{
	return (unsigned long) (sec * 1e6);
}


57
58
59
} // namespace lima

#endif // ESPIA_H