-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrs232.h
53 lines (44 loc) · 1.67 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
#ifndef __RS232_H
#define __RS232_H
#define RS232_CONFIG_STOPBIT_2 0x40
#define RS232_CONFIG_STOPBIT_1 0x00
#define RS232_CONFIG_PARITY_MASK 0x30
#define RS232_CONFIG_PARITY_EVEN 0x20
#define RS232_CONFIG_PARITY_ODD 0x10
#define RS232_CONFIG_PARITY_NO 0x00
#define RS232_CONFIG_CS_MASK 0x0F
#define RS232_CONFIG_CS8 8
#define RS232_CONFIG_CS7 7
#define RS232_CONFIG_CS6 6
#define RS232_CONFIG_CS5 5
#define RS232_CONFIG_DEFAULT (RS232_CONFIG_CS8 | RS232_CONFIG_PARITY_NO | RS232_CONFIG_STOPBIT_1)
#ifdef _WIN32
#include <Windows.h>
typedef SSIZE_T ssize_t;
typedef unsigned int speed_t;
typedef void* HCOM;
#define RS232_IS_INVALID(hCom) (hCom == INVALID_HANDLE_VALUE)
#else
#include <fcntl.h> /* File Control Definitions */
#include <termios.h> /* POSIX Terminal Control Definitions */
#include <unistd.h> /* UNIX Standard Definitions */
#include <errno.h> /* ERROR Number Definitions */
#include <sys/ioctl.h> /* ioctl() */
typedef int HCOM;
#define RS232_IS_INVALID(hCom) (hCom == -1)
#endif
// Valid bauds: 110, 300, 600, 1200, 2400, 4800, 9600, 19200, 38400
// 57600, 115200, 128000, 256000, 500000, 1000000
HCOM RS232_Open(const unsigned char* name);
void RS232_Config(HCOM hCom, speed_t baud, unsigned char config);
ssize_t RS232_Write(HCOM hCom, const void* buf, size_t count);
ssize_t RS232_Read(HCOM hCom, void *buf, size_t count);
ssize_t RS232_ReadLine(HCOM hCom, char *buffer, size_t count);
void RS232_RTS_Set(HCOM hCom);
void RS232_RTS_Clr(HCOM hCom);
void RS232_DTR_Set(HCOM hCom);
void RS232_DTR_Clr(HCOM hCom);
int RS232_CTS(HCOM hCom);
int RS232_DSR(HCOM hCom);
void RS232_Close(HCOM hCom);
#endif // !__RS232_H