forked from Marzac/rs232
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rs232.h
155 lines (133 loc) · 4.99 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
Cross-platform serial / RS232 library
Version 0.21, 11/10/2015
-> All platforms header
-> rs232.h
The MIT License (MIT)
Copyright (c) 2013-2015 Frédéric Meslin, Florent Touchard
Email: [email protected]
Website: www.fredslab.net
Twitter: @marzacdev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef RS232_H
#define RS232_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdlib.h>
/*****************************************************************************/
/* Doxywizard specific */
/**
* \mainpage RS232
* \section intro_sec C / C++ RS232 cross-platform serial library
* <b>Version 0.21 - 11/10/2015</b>
*
* Supported platforms:
* - Windows (XP / Win7, possibly 8 and 10)
* - Linux
* - MacOS X
*
* Copyright (c) 2013-2015 Frédéric Meslin, Florent Touchard <br>
* Email: [email protected] <br>
* Website: www.fredslab.net <br>
* Twitter: \@marzacdev <br>
*/
/*****************************************************************************/
/**
* \fn int comEnumerate()
* \brief Enumerate available serial ports (Serial, USB serial, Bluetooth serial)
* \return number of enumerated ports
*/
int comEnumerate();
/**
* \fn int comGetNoPorts()
* \brief Return the number of enumerated ports
* \return number of enumerated ports
*/
int comGetNoPorts();
/**
* \fn int comTerminate()
* \brief Release ports and memory resources used by the library
*/
void comTerminate();
/**
* \fn const char * comGetPortName(int index)
* \brief Get port user-friendly name
* \param[in] index port index
* \return null terminated port name
*/
const char * comGetPortName(int index);
/**
* \fn const char * comGetInternalName(int index)
* \brief Get port operating-system name
* \param[in] index port index
* \return null terminated port name
*/
const char * comGetInternalName(int index);
/**
* \fn int comFindPort(const char * name)
* \brief Try to find a port given its user-friendly name
* \param[in] name port name (case sensitive)
* \return index of found port or -1 if not enumerated
*/
int comFindPort(const char * name);
/*****************************************************************************/
/**
* \fn int comOpen(int index, int baudrate)
* \brief Try to open a port at a specific baudrate
* \brief (No parity, single stop bit, no hardware flow control)
* \param[in] index port index
* \param[in] baudrate port baudrate
* \return 1 if opened, 0 if not available
*/
int comOpen(int index, int baudrate);
/**
* \fn void comClose(int index)
* \brief Close an opened port
* \param[in] index port index
*/
void comClose(int index);
/**
* \fn void comCloseAll()
* \brief Close all opened ports
*/
void comCloseAll();
/*****************************************************************************/
/**
* \fn int comWrite(int index, const char * buffer, size_t len)
* \brief Write data to the port (non-blocking)
* \param[in] index port index
* \param[in] buffer pointer to transmit buffer
* \param[in] len length of transmit buffer in bytes
* \return number of bytes transferred
*/
int comWrite(int index, const char * buffer, size_t len);
/**
* \fn int comRead(int index, const char * buffer, size_t len)
* \brief Read data from the port (non-blocking)
* \param[in] index port index
* \param[in] buffer pointer to receive buffer
* \param[in] len length of receive buffer in bytes
* \return number of bytes transferred
*/
int comRead(int index, char * buffer, size_t len);
#ifdef __cplusplus
}
#endif
#endif // RS232_H