forked from TroikaTronix/firmata_test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serial.h
62 lines (57 loc) · 1.3 KB
/
serial.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef __serial_h__
#define __serial_h__
#include "wx/wx.h" // MFC - changed to quotes for XCode compliance
#include <stdint.h>
// MFC - added these definitions here to we don't need to define a preprocessor macro
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#define WINDOWS
#elif __APPLE__
#define MACOSX
#elif __linux__
#define LINUS
#else
# error "Unknown compiler"
#endif
#if defined(LINUX)
#include <termios.h>
#elif defined(MACOSX)
#include <termios.h>
#elif defined(WINDOWS)
#include <windows.h>
#endif
class Serial
{
public:
Serial();
~Serial();
wxArrayString port_list();
int Open(const wxString& name);
wxString error_message();
int Set_baud(int baud);
int Set_baud(const wxString& baud_str);
int Read(void *ptr, int count);
int Write(const void *ptr, int len);
int Input_wait(int msec);
void Input_discard(void);
int Set_control(int dtr, int rts);
void Output_flush();
void Close(void);
int Is_open(void);
wxString get_name(void);
private:
int port_is_open;
wxString port_name;
int baud_rate;
wxString error_msg;
private:
#if defined(LINUX) || defined(MACOSX)
int port_fd;
struct termios settings_orig;
struct termios settings;
#elif defined(WINDOWS)
HANDLE port_handle;
COMMCONFIG port_cfg_orig;
COMMCONFIG port_cfg;
#endif
};
#endif // __serial_h__