Skip to content
This repository was archived by the owner on Jan 7, 2024. It is now read-only.

Commit 6fb0f38

Browse files
author
Christian Visintin
committed
Code indentation. Library fixed (ref. issue #8)
1 parent e6685b2 commit 6fb0f38

File tree

2 files changed

+433
-440
lines changed

2 files changed

+433
-440
lines changed

README.md

Lines changed: 115 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# termiWin
2-
### ~ A termios porting for Windows ~
32

4-
Current Version 1.1.3 (07/04/2018)
3+
~ A termios porting for Windows ~
4+
5+
Current Version 1.1.4 (03/11/2018)
56

67
## Introduction
78

@@ -13,140 +14,146 @@ This is possible because termios’s functions have been rewritten to be compati
1314
### The termios Structure
1415

1516
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.
2225

2326
The members of termios structure are used to set and retrieve the serial port configuration parameters.
2427
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.
2528

2629
#### Input modes flags
2730

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.
3841

3942
#### Local modes flags
4043

4144
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.
4245

4346
#### Control modes flags
4447

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
5558

5659
#### Output modes flags
5760

5861
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.
5962

6063
#### Special character array
6164

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.
7376

7477
### Serial configuration functions
7578

76-
#### Int tcgetattr(int fd, struct termios \*termios_p);
79+
#### Int tcgetattr(int fd, struct termios \*termios_p)
7780

7881
Sets in the internal DCB structures the current serial port parameters, it
7982
always has to be invoked before using tcsetattr.
8083
Returns 0 if succeded, otherwise -1.
8184

82-
#### int tcsetattr(int fd, int optional_actions, struct termios \*termios_p);
85+
#### int tcsetattr(int fd, int optional_actions, struct termios \*termios_p)
8386

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.
8689
Returns 0 if succeded, otherwise -1.
8790

88-
#### int tcsendbreak(int fd, int duration);
91+
#### int tcsendbreak(int fd, int duration)
8992

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.
9194
Returns 0 if succeded, otherwise -1.
9295

93-
#### int tcdrain(int fd);
96+
#### int tcdrain(int fd)
9497

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.
9699
Returns 0 if succeded, otherwise -1.
97100

98-
#### Int tcflush(int fd, int queue_selector);
101+
#### Int tcflush(int fd, int queue_selector)
99102

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).
104108

105109
Returns 0 if succeded, otherwise -1.
106110

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.
108119

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.
114121

115-
Returns 0 if succeded, otherwise -1.
122+
#### Void cfmakeraw(struct termios \*termios_p)
116123

117-
#### Void cfmakeraw(struct termios \*termios_p);
124+
Sets but doesn’t commit the following options for the serial port:
118125

119-
Sets but doesn’t commit the following options for the serial port:
120-
* Charset: 8 bits
121-
* StopBits: one stop bit
122-
* Parity: no parity
126+
* Charset: 8 bits
127+
* StopBits: one stop bit
128+
* Parity: no parity
123129

124130
Use tcsetattr to commit them.
125131

126-
#### speed_t cfgetispeed(const struct termios \*termios_p);
132+
#### speed_t cfgetispeed(const struct termios \*termios_p)
133+
134+
Returns the input speed, speed can assume the same values of termios (B9600, B115200, …).
127135

128-
Returns the input speed, speed can assume the same values of termios (B9600, B115200, …).
136+
#### speed_t cfgetospeed(const struct termios \*termios_p)
129137

130-
#### speed_t cfgetospeed(const struct termios \*termios_p);
138+
returns the output speed, speed can assume the same values of termios (B9600, B115200, …).
131139

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)
133141

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, …).
135144

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, …).
138145
Returns 0 if succeded, otherwise -1.
139146

140-
#### int cfsetospeed(struct termios \*termios_p, speed_t speed);
147+
#### int cfsetospeed(struct termios \*termios_p, speed_t speed)
141148

142149
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.
145152

146-
#### int cfsetsspeed(struct termios \*termios_p, speed_t speed);
153+
#### int cfsetsspeed(struct termios \*termios_p, speed_t speed)
147154

148155
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, ...).
150157
Returns 0 if succeded, otherwise -1.
151158

152159
#### Supported speed
@@ -168,42 +175,42 @@ The supported speeds are the the following (not all speeds could be implemented
168175
### Serial transmission/receiving - open/close Functions
169176

170177
**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
172180
#define TERMIWIN_DONOTREDEFINE
173-
`
181+
```
174182

175-
#### Int openSerial(char* portname, int opt);
183+
#### Int openSerial(char* portname, int opt)
176184

177185
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,
178186
O_WRONLY, O_RDWR). Returns the file descriptor (fd is actually useless in Windows with serial ports, but is set for
179187
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).
181189

182-
#### Int closeSerial(int fd);
190+
#### Int closeSerial(int fd)
183191

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).
187194

188-
#### Int writeToSerial(int fd, char* buffer, int count);
195+
#### Int writeToSerial(int fd, char* buffer, int count)
189196

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.
192199
The function can be called using write instead of writeToSerial (for termios compatibilty).
193200

194-
#### Int readFromSerial(int fd, char* buffer, int count);
201+
#### Int readFromSerial(int fd, char* buffer, int count)
195202

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.
198205
The function can be called using read instead of readFromSerial (for termios compatibilty).
199206

200-
#### Int selectSerial(int nfds, fd_set \*readfds, fd_set \*writefds, fd_set \*exceptfds, struct timeval \*timeout);
207+
#### Int selectSerial(int nfds, fd_set \*readfds, fd_set \*writefds, fd_set \*exceptfds, struct timeval \*timeout)
201208

202-
It behaves as termios select.
203-
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.
204211
The function can be called using select instead of selectSerial (for termios compatibility).
205212

206-
#### HANDLE getHandle();
213+
#### HANDLE getHandle()
207214

208215
Returns the HANDLE from the COM structure.
209216

@@ -213,27 +220,30 @@ At the moment is not possible to have more than one serial communication at the
213220

214221
---
215222

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**.
217226

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.
219232

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? ❌
224234

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
229238

230239
---
231240

232241
## Contributions
233242

234243
Everybody can contribute to this project, indeed any improvement will be appreciated.
235244

236-
### Is termiWin still supported?
245+
### Is termiWin still supported
246+
237247
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.
238248

239249
## License

0 commit comments

Comments
 (0)