-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrs232.h
124 lines (105 loc) · 3.34 KB
/
rs232.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
***********************************************
*
* Author: Frank Andre Moreno Vera
*
* Copyright (C) 2014 Frank Andre Moreno Vera
*
*
***********************************************
*/
#ifndef github_com_kranfix_rs232_rs232_h
#define github_com_kranfix_rs232_rs232_h
#include <stdio.h>
#include <string.h>
#ifdef __linux__
#include <termios.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <limits.h>
#else
#include <windows.h>
#endif
//#undef __cplusplus
#ifdef __cplusplus
namespace kfx {
# ifdef __linux__
const char Comports[22][13] = {"/dev/ttyACM0",
"/dev/ttyS1", "/dev/ttyS2", "/dev/ttyS3",
"/dev/ttyS4", "/dev/ttyS5", "/dev/ttyS6",
"/dev/ttyS7", "/dev/ttyS8", "/dev/ttyS9",
"/dev/ttyS10", "/dev/ttyS11", "/dev/ttyS12",
"/dev/ttyS13", "/dev/ttyS14", "/dev/ttyS15",
"/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB2",
"/dev/ttyUSB3", "/dev/ttyUSB4", "/dev/ttyUSB5"};
# else
const char Comports[16][10]={"\\\\.\\COM1",
"\\\\.\\COM2", "\\\\.\\COM3", "\\\\.\\COM4",
"\\\\.\\COM5", "\\\\.\\COM6", "\\\\.\\COM7",
"\\\\.\\COM8", "\\\\.\\COM9", "\\\\.\\COM10",
"\\\\.\\COM11", "\\\\.\\COM12", "\\\\.\\COM13",
"\\\\.\\COM14", "\\\\.\\COM15", "\\\\.\\COM16"};
# endif
class RS232
{
char devname[13]; // Device Name
int baudr, port; // Baudrate and Port Number
bool available;
struct termios ops; // old port settings
public:
RS232(char *, int);
int IsAvailable() { return available; }
char * GetDeviceName() { return devname; }
int Read(unsigned char);
int Read(unsigned char *, int);
int Write(unsigned char);
int Write(unsigned char *, int);
void Print(const char *);
void Close();
int IsCTSEnabled();
};
}
#else
// Private tipe
typedef struct kfx_RS232 {
char devname[13];
int baudr, port; // Baudrate and Port Number
int available;
# ifdef __linux__
struct termios ops;
# else
HANDLE Cport;
# endif
} kfx_RS232;
/*# ifdef __linux__
extern const char kfx_RS232_Comports[22][13] = {"/dev/ttyACM0", \
"/dev/ttyS1", "/dev/ttyS2", "/dev/ttyS3", \
"/dev/ttyS4", "/dev/ttyS5", "/dev/ttyS6", \
"/dev/ttyS7", "/dev/ttyS8", "/dev/ttyS9", \
"/dev/ttyS10", "/dev/ttyS11", "/dev/ttyS12", \
"/dev/ttyS13", "/dev/ttyS14", "/dev/ttyS15", \
"/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB2",\
"/dev/ttyUSB3", "/dev/ttyUSB4", "/dev/ttyUSB5"};
#else
extern const char kfx_RS232_Comports[16][10]={"\\\\.\\COM1",
"\\\\.\\COM2", "\\\\.\\COM3", "\\\\.\\COM4",
"\\\\.\\COM5", "\\\\.\\COM6", "\\\\.\\COM7",
"\\\\.\\COM8", "\\\\.\\COM9", "\\\\.\\COM10",
"\\\\.\\COM11", "\\\\.\\COM12", "\\\\.\\COM13",
"\\\\.\\COM14", "\\\\.\\COM15", "\\\\.\\COM16"};
#endif*/
int kfx_RS232_Init(kfx_RS232 *, char *, int);
int kfx_RS232_IsAvailable(kfx_RS232 * h);
int kfx_RS232_ReadByte(kfx_RS232 *, unsigned char);
int kfx_RS232_ReadBuf(kfx_RS232 *, unsigned char *, int);
int kfx_RS232_WriteByte(kfx_RS232 *, unsigned char);
int kfx_RS232_WriteBuf(kfx_RS232 *, unsigned char *, int);
void kfx_RS232_Close(kfx_RS232 *);
void kfx_RS232_Print(kfx_RS232 *, const char *);
int kfx_RS232_IsCTSEnabled(kfx_RS232 *);
#endif
#endif // giihub_com_kranfix_rs232_rs232_h