You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 7, 2024. It is now read-only.
@@ -13,140 +14,146 @@ This is possible because termios’s functions have been rewritten to be compati
13
14
### The termios Structure
14
15
15
16
This is the main structure of the library and it’s often passed as argument to the functions, it has the following members:
16
-
* tcflag_t c_iflag; /\*input modes\*/</br>
17
-
* tcflag_t c_oflag; /\*output modes\*/</br>
18
-
* tcflag_t c_cflag; /\*control modes\*/</br>
19
-
* tcflag_t c_lflag; /\*local modes\*/</br>
20
-
* cc_t c_cc[NCCS]; /\*special character\*/</br>
21
-
where tcflag_t is defined as an unsigned integer.</br>
17
+
18
+
* tcflag_t c_iflag; /\*input modes\*/
19
+
* tcflag_t c_oflag; /\*output modes\*/
20
+
* tcflag_t c_cflag; /\*control modes\*/
21
+
* tcflag_t c_lflag; /\*local modes\*/
22
+
* cc_t c_cc[NCCS]; /\*special character\*/
23
+
24
+
where tcflag_t is defined as an unsigned integer.
22
25
23
26
The members of termios structure are used to set and retrieve the serial port configuration parameters.
24
27
There five types of flags, sorted by mode; they are implemented in the same way as they are in termios, except for some, which are not used.
25
28
26
29
#### Input modes flags
27
30
28
-
* INPCK – Not implemented, use PARENB instead.
29
-
* IGNPAR – Not implemented, disable PARENB instead.
30
-
* PARMRK – Not implemented, use PARENB instead.
31
-
* ISTRIP – Not implemented, use CS7 instead.
32
-
* IGNBRK – Not implemented.
33
-
* IGNCR – Not implemented.
34
-
* ICRNL – Not implemented.
35
-
* INLCR – Not implemented.
36
-
* IXOFF - If this bit is set, start/stop control on input is enabled. In other words, the computer sends STOP and START characters as necessary to prevent input from coming in faster than programs are reading it. The idea is that the actual terminal hardware that is generating the input data responds to a STOP character by suspending transmission, and to a START character by resuming transmission.
37
-
* IXON - If this bit is set, start/stop control on output is enabled. In other words, if the computer receives a STOP character, it suspends output until a START character is received. In this case, the STOP and START characters are never passed to the application program. If this bit is not set, then START and STOP can be read as ordinary characters.
31
+
* INPCK – Not implemented, use PARENB instead.
32
+
* IGNPAR – Not implemented, disable PARENB instead.
33
+
* PARMRK – Not implemented, use PARENB instead.
34
+
* ISTRIP – Not implemented, use CS7 instead.
35
+
* IGNBRK – Not implemented.
36
+
* IGNCR – Not implemented.
37
+
* ICRNL – Not implemented.
38
+
* INLCR – Not implemented.
39
+
* IXOFF - If this bit is set, start/stop control on input is enabled. In other words, the computer sends STOP and START characters as necessary to prevent input from coming in faster than programs are reading it. The idea is that the actual terminal hardware that is generating the input data responds to a STOP character by suspending transmission, and to a START character by resuming transmission.
40
+
* IXON - If this bit is set, start/stop control on output is enabled. In other words, if the computer receives a STOP character, it suspends output until a START character is received. In this case, the STOP and START characters are never passed to the application program. If this bit is not set, then START and STOP can be read as ordinary characters.
38
41
39
42
#### Local modes flags
40
43
41
44
Since there’s no way to implement them in Windows, they have asbolutely no effect using termiWin, but you can keep the same you use in Linux for compatibilty.
42
45
43
46
#### Control modes flags
44
47
45
-
* CSTOPB - If this bit is set, two stop bits are used. Otherwise, only one stop bit is used.
46
-
* PARENB - If this bit is set, generation and detection of a parity bit are enabled.
47
-
* PARODD - This bit is only useful if PARENB is set. If PARODD is set, odd parity is used, otherwise even parity is used.
48
-
* CSIZE - This is a mask for the number of bits per character.
49
-
* CS5 - This specifies five bits per byte.
50
-
* CS6 – This specifies six bits per byte.
51
-
* CS7 – This specifies seven bits per byte.
52
-
* CS8 – This specifies eight bits per byte.
53
-
* CLOCAL – Is used in termios for ignoring the data carrier detected, but in Windows it can't be implemented
54
-
* CREAD – In termios, if not set, no character will be received, but in Windows it can't be implemented
48
+
* CSTOPB - If this bit is set, two stop bits are used. Otherwise, only one stop bit is used.
49
+
* PARENB - If this bit is set, generation and detection of a parity bit are enabled.
50
+
* PARODD - This bit is only useful if PARENB is set. If PARODD is set, odd parity is used, otherwise even parity is used.
51
+
* CSIZE - This is a mask for the number of bits per character.
52
+
* CS5 - This specifies five bits per byte.
53
+
* CS6 – This specifies six bits per byte.
54
+
* CS7 – This specifies seven bits per byte.
55
+
* CS8 – This specifies eight bits per byte.
56
+
* CLOCAL – Is used in termios for ignoring the data carrier detected, but in Windows it can't be implemented
57
+
* CREAD – In termios, if not set, no character will be received, but in Windows it can't be implemented
55
58
56
59
#### Output modes flags
57
60
58
61
Since there’s no way to implement them in Windows, they have asbolutely no effect using termiWin, but you can keep the same you use in Linux for compatibilty.
59
62
60
63
#### Special character array
61
64
62
-
* VEOF – Is the EOF character to be used during the communication.
63
-
* VEOL – Not implemented.
64
-
* VERASE – Not implemented.
65
-
* VINTR – Interrupt character.
66
-
* VKILL – Not implemented.
67
-
* VMIN – If set to 0, the port is set to not-blocking, otherwise to blocking.
68
-
* VQUIT – Not implemented.
69
-
* VSTART – Not implemented.
70
-
* VSTOP – Not implemented.
71
-
* VSUSP – Not implemented.
72
-
* VTIME – Timeout for reading operations when COM is set to not-blocking.
65
+
* VEOF – Is the EOF character to be used during the communication.
66
+
* VEOL – Not implemented.
67
+
* VERASE – Not implemented.
68
+
* VINTR – Interrupt character.
69
+
* VKILL – Not implemented.
70
+
* VMIN – If set to 0, the port is set to not-blocking, otherwise to blocking.
71
+
* VQUIT – Not implemented.
72
+
* VSTART – Not implemented.
73
+
* VSTOP – Not implemented.
74
+
* VSUSP – Not implemented.
75
+
* VTIME – Timeout for reading operations when COM is set to not-blocking.
73
76
74
77
### Serial configuration functions
75
78
76
-
#### Int tcgetattr(int fd, struct termios \*termios_p);
79
+
#### Int tcgetattr(int fd, struct termios \*termios_p)
77
80
78
81
Sets in the internal DCB structures the current serial port parameters, it
79
82
always has to be invoked before using tcsetattr.
80
83
Returns 0 if succeded, otherwise -1.
81
84
82
-
#### int tcsetattr(int fd, int optional_actions, struct termios \*termios_p);
85
+
#### int tcsetattr(int fd, int optional_actions, struct termios \*termios_p)
83
86
84
-
Reads the flags set in the termios structure and sets the properly
85
-
parameters in the DCB structure and eventually it applies the parameters to the serial port.
87
+
Reads the flags set in the termios structure and sets the properly
88
+
parameters in the DCB structure and eventually it applies the parameters to the serial port.
86
89
Returns 0 if succeded, otherwise -1.
87
90
88
-
#### int tcsendbreak(int fd, int duration);
91
+
#### int tcsendbreak(int fd, int duration)
89
92
90
-
Sends a break character to the serial port; duration is not implemented.
93
+
Sends a break character to the serial port; duration is not implemented.
91
94
Returns 0 if succeded, otherwise -1.
92
95
93
-
#### int tcdrain(int fd);
96
+
#### int tcdrain(int fd)
94
97
95
-
Waits until all output written to the serial port has been transmitted.
98
+
Waits until all output written to the serial port has been transmitted.
96
99
Returns 0 if succeded, otherwise -1.
97
100
98
-
#### Int tcflush(int fd, int queue_selector);
101
+
#### Int tcflush(int fd, int queue_selector)
99
102
100
-
Discards data on serial port. queue_selector can assume the following values:
101
-
* TCIFLUSH (discards data received but still not read).
102
-
* TCOFLUSH (discards data written but still not transmitted),
103
-
* TCIOFLUSH (discards both data received but still not read and data written but still not transmitted).
103
+
Discards data on serial port. queue_selector can assume the following values:
104
+
105
+
* TCIFLUSH (discards data received but still not read).
106
+
* TCOFLUSH (discards data written but still not transmitted),
107
+
* TCIOFLUSH (discards both data received but still not read and data written but still not transmitted).
104
108
105
109
Returns 0 if succeded, otherwise -1.
106
110
107
-
#### Int tcflow(int fd, int action);
111
+
#### Int tcflow(int fd, int action)
112
+
113
+
Suspends transmission or receptions of data on serial port based on action. Action can assume the following values:
114
+
115
+
* TCOON restarts suspended output.
116
+
* TCIOFF transmits a STOP character.
117
+
* TCION transmits a START character.
118
+
* TCOOF suspends output.
108
119
109
-
Suspends transmission or receptions of data on serial port based on action. Action can assume the following values:
110
-
* TCOON restarts suspended output.
111
-
* TCIOFF transmits a STOP character.
112
-
* TCION transmits a START character.
113
-
* TCOOF suspends output.
120
+
Returns 0 if succeded, otherwise -1.
114
121
115
-
Returns 0 if succeded, otherwise -1.
122
+
#### Void cfmakeraw(struct termios \*termios_p)
116
123
117
-
#### Void cfmakeraw(struct termios \*termios_p);
124
+
Sets but doesn’t commit the following options for the serial port:
118
125
119
-
Sets but doesn’t commit the following options for the serial port:
returns the output speed, speed can assume the same values of termios (B9600, B115200, …).
131
139
132
-
returns the output speed, speed can assume the same values of termios (B9600, B115200, …).
140
+
#### int cfsetispeed(struct termios \*termios_p, speed_t speed)
133
141
134
-
#### int cfsetispeed(struct termios \*termios_p, speed_t speed);
142
+
Sets, but doesn’t commits the parameter of speed for the serial port (in Windows there’s no distinction between
143
+
input/output /control), speed can assume the same values of termios (B9600, B115200, …).
135
144
136
-
Sets, but doesn’t commits the parameter of speed for the serial port (in Windows there’s no distinction between
137
-
input/output /control), speed can assume the same values of termios (B9600, B115200, …).
138
145
Returns 0 if succeded, otherwise -1.
139
146
140
-
#### int cfsetospeed(struct termios \*termios_p, speed_t speed);
147
+
#### int cfsetospeed(struct termios \*termios_p, speed_t speed)
141
148
142
149
Sets, but doesn’t commits the parameter of speed for the serial port (in Windows there’s no distinction between input/output
143
-
/control), speed can assume the same values of termios (B9600, B115200, ...).
144
-
Returns 0 if succeded, otherwise -1.
150
+
/control), speed can assume the same values of termios (B9600, B115200, ...).
151
+
Returns 0 if succeded, otherwise -1.
145
152
146
-
#### int cfsetsspeed(struct termios \*termios_p, speed_t speed);
153
+
#### int cfsetsspeed(struct termios \*termios_p, speed_t speed)
147
154
148
155
Sets, but doesn’t commits the parameter of speed for the serial port (in Windows there’s no distinction between input/output
149
-
/control), speed can assume the same values of termios (B9600, B115200, ...).
156
+
/control), speed can assume the same values of termios (B9600, B115200, ...).
150
157
Returns 0 if succeded, otherwise -1.
151
158
152
159
#### Supported speed
@@ -168,42 +175,42 @@ The supported speeds are the the following (not all speeds could be implemented
168
175
### Serial transmission/receiving - open/close Functions
169
176
170
177
**You can use open/close/write/read/select instead of these names by default. If it causes to you conflicts with another library you can deactivate these definitions defining in your project:**
171
-
`C
178
+
179
+
```C
172
180
#defineTERMIWIN_DONOTREDEFINE
173
-
`
181
+
```
174
182
175
-
#### Int openSerial(char* portname, int opt);
183
+
#### Int openSerial(char* portname, int opt)
176
184
177
185
Open the serial port which name is portname with opt set for the port to be read only, write only or both read/write (O_RDONLY,
178
186
O_WRONLY, O_RDWR). Returns the file descriptor (fd is actually useless in Windows with serial ports, but is set for
179
187
compatibilty). The function can be called using open instead of openSerial (for termios compatibilty).
180
-
The portname must be in the format "COMnumber" (e.g. COM2, COM11).
188
+
The portname must be in the format "COMnumber" (e.g. COM2, COM11).
181
189
182
-
#### Int closeSerial(int fd);
190
+
#### Int closeSerial(int fd)
183
191
184
-
Closes the serial port.
185
-
Returns 0 if succeded, otherwise -1. The function can be called using close instead of closeSerial
186
-
(for termios compatibilty).
192
+
Closes the serial port.
193
+
Returns 0 if succeded, otherwise -1. The function can be called using close instead of closeSerial. (for termios compatibilty).
187
194
188
-
#### Int writeToSerial(int fd, char* buffer, int count);
195
+
#### Int writeToSerial(int fd, char* buffer, int count)
189
196
190
-
Writes to serial “count” characters contained in buffer.
191
-
Returns the number of transmitted characters or -1 if transmission failed.
197
+
Writes to serial “count” characters contained in buffer.
198
+
Returns the number of transmitted characters or -1 if transmission failed.
192
199
The function can be called using write instead of writeToSerial (for termios compatibilty).
193
200
194
-
#### Int readFromSerial(int fd, char* buffer, int count);
201
+
#### Int readFromSerial(int fd, char* buffer, int count)
195
202
196
-
Reads “count” bytes from serial port and put them into buffer.
197
-
Returns the number of read bytes or -1 if read failed.
203
+
Reads “count” bytes from serial port and put them into buffer.
204
+
Returns the number of read bytes or -1 if read failed.
198
205
The function can be called using read instead of readFromSerial (for termios compatibilty).
Returns the file descriptor ready for the chosen operation or -1 if failed.
209
+
It behaves as termios select.
210
+
Returns the file descriptor ready for the chosen operation or -1 if failed.
204
211
The function can be called using select instead of selectSerial (for termios compatibility).
205
212
206
-
#### HANDLE getHandle();
213
+
#### HANDLE getHandle()
207
214
208
215
Returns the HANDLE from the COM structure.
209
216
@@ -213,27 +220,30 @@ At the moment is not possible to have more than one serial communication at the
213
220
214
221
---
215
222
216
-
## What is termiWin intended for?
223
+
## What is termiWin intended for
224
+
225
+
termiWin is just a simple library which executes termios functions using Windows libsock functions, because of that, any particular behaviour in the communication with the serial device, could not work properly. **termiWin is intended just for simple communications**.
217
226
218
-
termiWin is just a simple library which executes termios functions using Windows libsock functions, because of that, any particular behaviour in the communication with the serial device, could not work properly. **termiWin is intended just for simple communications**.
227
+
When termiWin *can be* a good choice? ✅
228
+
229
+
* ✅ - When you have to do a quick project without particular requirements.
230
+
* ✅ - When you don't need performance and high reliability.
231
+
* ✅ - When the communication between you and the serial device doesn't require a particular configuration.
219
232
220
-
When termiWin *can be* a good choice? ✅
221
-
* ✅ - When you have to do a quick project without particular requirements.
222
-
* ✅ - When you don't need performance and high reliability.
223
-
* ✅ - When the communication between you and the serial device doesn't require a particular configuration.
233
+
When termiWin **Is NOT** a good choice? ❌
224
234
225
-
When termiWin **Is NOT** a good choice? ❌
226
-
* ❌ - When you need multiple device communications. termiWin just doesn't support this feature at the moment.
227
-
* ❌ - When you need performance - since termiWin has to convert termios to windows instructions, it won't be faster than a program with windows instructions wrote by the developer.
228
-
* ❌ - When you require particular configuration and to use particular functions (such as tcdrain, tcflush etc) - they could work, but I can't assure
235
+
* ❌ - When you need multiple device communications. termiWin just doesn't support this feature at the moment.
236
+
* ❌ - When you need performance - since termiWin has to convert termios to windows instructions, it won't be faster than a program with windows instructions wrote by the developer.
237
+
* ❌ - When you require particular configuration and to use particular functions (such as tcdrain, tcflush etc) - they could work, but I can't assure
229
238
230
239
---
231
240
232
241
## Contributions
233
242
234
243
Everybody can contribute to this project, indeed any improvement will be appreciated.
235
244
236
-
### Is termiWin still supported?
245
+
### Is termiWin still supported
246
+
237
247
Well, I'm not working on it anymore, but I will answer to your questions and I will submit pull requests if they can be an improvement to the library.
0 commit comments