2
// A note from Brandon Fosdick, one of the QExtSerialPort developers,
3
// to Wes Hardaker states:
5
// qesp doesn't really have a license, it's considered completely public
11
#include "qextserialport.h"
12
#include <QtCore/QMutexLocker>
13
#include <QtCore/QDebug>
14
#include "aprsconfig.h"
15
#ifdef HAVE_SYS_FILIO_H
16
#include <sys/filio.h>
17
#endif /* HAVE_SYS_FILIO_H */
19
void QextSerialPort::platformSpecificInit()
28
void QextSerialPort::platformSpecificDestruct()
32
Sets the baud rate of the serial port. Note that not all rates are applicable on
33
all platforms. The following table shows translations of the various baud rate
34
constants on Windows(including NT/2000) and POSIX platforms. Speeds marked with an *
35
are speeds that are usable on both Windows and POSIX.
38
BAUD76800 may not be supported on all POSIX systems. SGI/IRIX systems do not support
43
RATE Windows Speed POSIX Speed
44
----------- ------------- -----------
59
*BAUD19200 19200 19200
60
*BAUD38400 38400 38400
62
*BAUD57600 57600 57600
64
*BAUD115200 115200 115200
65
BAUD128000 128000 115200
66
BAUD256000 256000 115200
69
void QextSerialPort::setBaudRate(BaudRateType baudRate)
71
QMutexLocker lock(mutex);
72
if (Settings.BaudRate!=baudRate) {
75
Settings.BaudRate=BAUD9600;
79
Settings.BaudRate=BAUD38400;
85
Settings.BaudRate=BAUD57600;
87
Settings.BaudRate=baudRate;
93
Settings.BaudRate=BAUD115200;
97
Settings.BaudRate=baudRate;
106
TTY_PORTABILITY_WARNING("QextSerialPort Portability Warning: Windows does not support 50 baud operation.");
108
Posix_CommConfig.c_cflag&=(~CBAUD);
109
Posix_CommConfig.c_cflag|=B50;
111
cfsetispeed(&Posix_CommConfig, B50);
112
cfsetospeed(&Posix_CommConfig, B50);
118
TTY_PORTABILITY_WARNING("QextSerialPort Portability Warning: Windows does not support 75 baud operation.");
120
Posix_CommConfig.c_cflag&=(~CBAUD);
121
Posix_CommConfig.c_cflag|=B75;
123
cfsetispeed(&Posix_CommConfig, B75);
124
cfsetospeed(&Posix_CommConfig, B75);
131
Posix_CommConfig.c_cflag&=(~CBAUD);
132
Posix_CommConfig.c_cflag|=B110;
134
cfsetispeed(&Posix_CommConfig, B110);
135
cfsetospeed(&Posix_CommConfig, B110);
141
TTY_PORTABILITY_WARNING("QextSerialPort Portability Warning: Windows does not support 134.5 baud operation.");
143
Posix_CommConfig.c_cflag&=(~CBAUD);
144
Posix_CommConfig.c_cflag|=B134;
146
cfsetispeed(&Posix_CommConfig, B134);
147
cfsetospeed(&Posix_CommConfig, B134);
153
TTY_PORTABILITY_WARNING("QextSerialPort Portability Warning: Windows does not support 150 baud operation.");
155
Posix_CommConfig.c_cflag&=(~CBAUD);
156
Posix_CommConfig.c_cflag|=B150;
158
cfsetispeed(&Posix_CommConfig, B150);
159
cfsetospeed(&Posix_CommConfig, B150);
165
TTY_PORTABILITY_WARNING("QextSerialPort Portability Warning: Windows does not support 200 baud operation.");
167
Posix_CommConfig.c_cflag&=(~CBAUD);
168
Posix_CommConfig.c_cflag|=B200;
170
cfsetispeed(&Posix_CommConfig, B200);
171
cfsetospeed(&Posix_CommConfig, B200);
178
Posix_CommConfig.c_cflag&=(~CBAUD);
179
Posix_CommConfig.c_cflag|=B300;
181
cfsetispeed(&Posix_CommConfig, B300);
182
cfsetospeed(&Posix_CommConfig, B300);
189
Posix_CommConfig.c_cflag&=(~CBAUD);
190
Posix_CommConfig.c_cflag|=B600;
192
cfsetispeed(&Posix_CommConfig, B600);
193
cfsetospeed(&Posix_CommConfig, B600);
200
Posix_CommConfig.c_cflag&=(~CBAUD);
201
Posix_CommConfig.c_cflag|=B1200;
203
cfsetispeed(&Posix_CommConfig, B1200);
204
cfsetospeed(&Posix_CommConfig, B1200);
210
TTY_PORTABILITY_WARNING("QextSerialPort Portability Warning: Windows and IRIX do not support 1800 baud operation.");
212
Posix_CommConfig.c_cflag&=(~CBAUD);
213
Posix_CommConfig.c_cflag|=B1800;
215
cfsetispeed(&Posix_CommConfig, B1800);
216
cfsetospeed(&Posix_CommConfig, B1800);
223
Posix_CommConfig.c_cflag&=(~CBAUD);
224
Posix_CommConfig.c_cflag|=B2400;
226
cfsetispeed(&Posix_CommConfig, B2400);
227
cfsetospeed(&Posix_CommConfig, B2400);
234
Posix_CommConfig.c_cflag&=(~CBAUD);
235
Posix_CommConfig.c_cflag|=B4800;
237
cfsetispeed(&Posix_CommConfig, B4800);
238
cfsetospeed(&Posix_CommConfig, B4800);
245
Posix_CommConfig.c_cflag&=(~CBAUD);
246
Posix_CommConfig.c_cflag|=B9600;
248
cfsetispeed(&Posix_CommConfig, B9600);
249
cfsetospeed(&Posix_CommConfig, B9600);
255
TTY_WARNING("QextSerialPort: POSIX does not support 14400 baud operation. Switching to 9600 baud.");
257
Posix_CommConfig.c_cflag&=(~CBAUD);
258
Posix_CommConfig.c_cflag|=B9600;
260
cfsetispeed(&Posix_CommConfig, B9600);
261
cfsetospeed(&Posix_CommConfig, B9600);
268
Posix_CommConfig.c_cflag&=(~CBAUD);
269
Posix_CommConfig.c_cflag|=B19200;
271
cfsetispeed(&Posix_CommConfig, B19200);
272
cfsetospeed(&Posix_CommConfig, B19200);
279
Posix_CommConfig.c_cflag&=(~CBAUD);
280
Posix_CommConfig.c_cflag|=B38400;
282
cfsetispeed(&Posix_CommConfig, B38400);
283
cfsetospeed(&Posix_CommConfig, B38400);
289
TTY_WARNING("QextSerialPort: POSIX does not support 56000 baud operation. Switching to 38400 baud.");
291
Posix_CommConfig.c_cflag&=(~CBAUD);
292
Posix_CommConfig.c_cflag|=B38400;
294
cfsetispeed(&Posix_CommConfig, B38400);
295
cfsetospeed(&Posix_CommConfig, B38400);
302
Posix_CommConfig.c_cflag&=(~CBAUD);
303
Posix_CommConfig.c_cflag|=B57600;
305
cfsetispeed(&Posix_CommConfig, B57600);
306
cfsetospeed(&Posix_CommConfig, B57600);
312
TTY_PORTABILITY_WARNING("QextSerialPort Portability Warning: Windows and some POSIX systems do not support 76800 baud operation.");
314
Posix_CommConfig.c_cflag&=(~CBAUD);
317
Posix_CommConfig.c_cflag|=B76800;
319
TTY_WARNING("QextSerialPort: QextSerialPort was compiled without 76800 baud support. Switching to 57600 baud.");
320
Posix_CommConfig.c_cflag|=B57600;
324
cfsetispeed(&Posix_CommConfig, B76800);
325
cfsetospeed(&Posix_CommConfig, B76800);
327
TTY_WARNING("QextSerialPort: QextSerialPort was compiled without 76800 baud support. Switching to 57600 baud.");
328
cfsetispeed(&Posix_CommConfig, B57600);
329
cfsetospeed(&Posix_CommConfig, B57600);
337
Posix_CommConfig.c_cflag&=(~CBAUD);
338
Posix_CommConfig.c_cflag|=B115200;
340
cfsetispeed(&Posix_CommConfig, B115200);
341
cfsetospeed(&Posix_CommConfig, B115200);
347
TTY_WARNING("QextSerialPort: POSIX does not support 128000 baud operation. Switching to 115200 baud.");
349
Posix_CommConfig.c_cflag&=(~CBAUD);
350
Posix_CommConfig.c_cflag|=B115200;
352
cfsetispeed(&Posix_CommConfig, B115200);
353
cfsetospeed(&Posix_CommConfig, B115200);
359
TTY_WARNING("QextSerialPort: POSIX does not support 256000 baud operation. Switching to 115200 baud.");
361
Posix_CommConfig.c_cflag&=(~CBAUD);
362
Posix_CommConfig.c_cflag|=B115200;
364
cfsetispeed(&Posix_CommConfig, B115200);
365
cfsetospeed(&Posix_CommConfig, B115200);
369
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
374
Sets the number of data bits used by the serial port. Possible values of dataBits are:
383
This function is subject to the following restrictions:
385
5 data bits cannot be used with 2 stop bits.
387
8 data bits cannot be used with space parity on POSIX systems.
389
void QextSerialPort::setDataBits(DataBitsType dataBits)
391
QMutexLocker lock(mutex);
392
if (Settings.DataBits!=dataBits) {
393
if ((Settings.StopBits==STOP_2 && dataBits==DATA_5) ||
394
(Settings.StopBits==STOP_1_5 && dataBits!=DATA_5) ||
395
(Settings.Parity==PAR_SPACE && dataBits==DATA_8)) {
398
Settings.DataBits=dataBits;
406
if (Settings.StopBits==STOP_2) {
407
TTY_WARNING("QextSerialPort: 5 Data bits cannot be used with 2 stop bits.");
410
Settings.DataBits=dataBits;
411
Posix_CommConfig.c_cflag&=(~CSIZE);
412
Posix_CommConfig.c_cflag|=CS5;
413
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
419
if (Settings.StopBits==STOP_1_5) {
420
TTY_WARNING("QextSerialPort: 6 Data bits cannot be used with 1.5 stop bits.");
423
Settings.DataBits=dataBits;
424
Posix_CommConfig.c_cflag&=(~CSIZE);
425
Posix_CommConfig.c_cflag|=CS6;
426
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
432
if (Settings.StopBits==STOP_1_5) {
433
TTY_WARNING("QextSerialPort: 7 Data bits cannot be used with 1.5 stop bits.");
436
Settings.DataBits=dataBits;
437
Posix_CommConfig.c_cflag&=(~CSIZE);
438
Posix_CommConfig.c_cflag|=CS7;
439
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
445
if (Settings.StopBits==STOP_1_5) {
446
TTY_WARNING("QextSerialPort: 8 Data bits cannot be used with 1.5 stop bits.");
449
Settings.DataBits=dataBits;
450
Posix_CommConfig.c_cflag&=(~CSIZE);
451
Posix_CommConfig.c_cflag|=CS8;
452
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
460
Sets the parity associated with the serial port. The possible values of parity are:
462
PAR_SPACE Space Parity
470
This function is subject to the following limitations:
472
POSIX systems do not support mark parity.
474
POSIX systems support space parity only if tricked into doing so, and only with
475
fewer than 8 data bits. Use space parity very carefully with POSIX systems.
477
void QextSerialPort::setParity(ParityType parity)
479
QMutexLocker lock(mutex);
480
if (Settings.Parity!=parity) {
481
if (parity==PAR_MARK || (parity==PAR_SPACE && Settings.DataBits==DATA_8)) {
484
Settings.Parity=parity;
492
if (Settings.DataBits==DATA_8) {
493
TTY_PORTABILITY_WARNING("QextSerialPort: Space parity is only supported in POSIX with 7 or fewer data bits");
497
/*space parity not directly supported - add an extra data bit to simulate it*/
498
Posix_CommConfig.c_cflag&=~(PARENB|CSIZE);
499
switch(Settings.DataBits) {
501
Settings.DataBits=DATA_6;
502
Posix_CommConfig.c_cflag|=CS6;
506
Settings.DataBits=DATA_7;
507
Posix_CommConfig.c_cflag|=CS7;
511
Settings.DataBits=DATA_8;
512
Posix_CommConfig.c_cflag|=CS8;
518
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
522
/*mark parity - WINDOWS ONLY*/
524
TTY_WARNING("QextSerialPort: Mark parity is not supported by POSIX.");
529
Posix_CommConfig.c_cflag&=(~PARENB);
530
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
535
Posix_CommConfig.c_cflag&=(~PARODD);
536
Posix_CommConfig.c_cflag|=PARENB;
537
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
542
Posix_CommConfig.c_cflag|=(PARENB|PARODD);
543
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
550
Sets the number of stop bits used by the serial port. Possible values of stopBits are:
553
STOP_1_5 1.5 stop bits
557
This function is subject to the following restrictions:
559
2 stop bits cannot be used with 5 data bits.
561
POSIX does not support 1.5 stop bits.
564
void QextSerialPort::setStopBits(StopBitsType stopBits)
566
QMutexLocker lock(mutex);
567
if (Settings.StopBits!=stopBits) {
568
if ((Settings.DataBits==DATA_5 && stopBits==STOP_2) || stopBits==STOP_1_5) {}
570
Settings.StopBits=stopBits;
578
Settings.StopBits=stopBits;
579
Posix_CommConfig.c_cflag&=(~CSTOPB);
580
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
585
TTY_WARNING("QextSerialPort: 1.5 stop bit operation is not supported by POSIX.");
590
if (Settings.DataBits==DATA_5) {
591
TTY_WARNING("QextSerialPort: 2 stop bits cannot be used with 5 data bits");
594
Settings.StopBits=stopBits;
595
Posix_CommConfig.c_cflag|=CSTOPB;
596
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
604
Sets the flow control used by the port. Possible values of flow are:
606
FLOW_OFF No flow control
607
FLOW_HARDWARE Hardware (RTS/CTS) flow control
608
FLOW_XONXOFF Software (XON/XOFF) flow control
611
FLOW_HARDWARE may not be supported on all versions of UNIX. In cases where it is
612
unsupported, FLOW_HARDWARE is the same as FLOW_OFF.
615
void QextSerialPort::setFlowControl(FlowType flow)
617
QMutexLocker lock(mutex);
618
if (Settings.FlowControl!=flow) {
619
Settings.FlowControl=flow;
626
Posix_CommConfig.c_cflag&=(~CRTSCTS);
627
Posix_CommConfig.c_iflag&=(~(IXON|IXOFF|IXANY));
628
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
631
/*software (XON/XOFF) flow control*/
633
Posix_CommConfig.c_cflag&=(~CRTSCTS);
634
Posix_CommConfig.c_iflag|=(IXON|IXOFF|IXANY);
635
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
639
Posix_CommConfig.c_cflag|=CRTSCTS;
640
Posix_CommConfig.c_iflag&=(~(IXON|IXOFF|IXANY));
641
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
648
Sets the read and write timeouts for the port to millisec milliseconds.
649
Note that this is a per-character timeout, i.e. the port will wait this long for each
650
individual character, not for the whole read operation. This timeout also applies to the
651
bytesWaiting() function.
654
POSIX does not support millisecond-level control for I/O timeout values. Any
655
timeout set using this function will be set to the next lowest tenth of a second for
656
the purposes of detecting read or write timeouts. For example a timeout of 550 milliseconds
657
will be seen by the class as a timeout of 500 milliseconds for the purposes of reading and
658
writing the port. However millisecond-level control is allowed by the select() system call,
659
so for example a 550-millisecond timeout will be seen as 550 milliseconds on POSIX systems for
660
the purpose of detecting available bytes in the read buffer.
663
void QextSerialPort::setTimeout(long millisec)
665
QMutexLocker lock(mutex);
666
Settings.Timeout_Millisec = millisec;
667
Posix_Copy_Timeout.tv_sec = millisec / 1000;
668
Posix_Copy_Timeout.tv_usec = millisec % 1000;
671
fcntl(fd, F_SETFL, O_NDELAY);
673
//O_SYNC should enable blocking ::write()
674
//however this seems not working on Linux 2.6.21 (works on OpenBSD 4.2)
675
fcntl(fd, F_SETFL, O_SYNC);
676
tcgetattr(fd, & Posix_CommConfig);
677
Posix_CommConfig.c_cc[VTIME] = millisec/100;
678
tcsetattr(fd, TCSAFLUSH, & Posix_CommConfig);
683
Opens the serial port associated to this class.
684
This function has no effect if the port associated with the class is already open.
685
The port is also configured to the current settings, as stored in the Settings structure.
687
bool QextSerialPort::open(OpenMode mode)
689
QMutexLocker lock(mutex);
690
if (mode == QIODevice::NotOpen)
693
qDebug() << "trying to open file" << port.toAscii();
694
//note: linux 2.6.21 seems to ignore O_NDELAY flag
695
if ((fd = ::open(port.toAscii() ,O_RDWR | O_NOCTTY | O_NDELAY)) != -1) {
696
qDebug("file opened succesfully");
698
setOpenMode(mode); // Flag the port as opened
699
tcgetattr(fd, &old_termios); // Save the old termios
700
Posix_CommConfig = old_termios; // Make a working copy
703
/* the equivelent of cfmakeraw() to enable raw access */
704
#ifdef HAVE_CFMAKERAW
705
cfmakeraw(&Posix_CommConfig); // Enable raw access
707
Posix_CommConfig.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
708
| INLCR | IGNCR | ICRNL | IXON);
709
Posix_CommConfig.c_oflag &= ~OPOST;
710
Posix_CommConfig.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
711
Posix_CommConfig.c_cflag &= ~(CSIZE | PARENB);
712
Posix_CommConfig.c_cflag |= CS8;
715
/*set up other port settings*/
716
Posix_CommConfig.c_cflag|=CREAD|CLOCAL;
717
Posix_CommConfig.c_lflag&=(~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|ISIG));
718
Posix_CommConfig.c_iflag&=(~(INPCK|IGNPAR|PARMRK|ISTRIP|ICRNL|IXANY));
719
Posix_CommConfig.c_oflag&=(~OPOST);
720
Posix_CommConfig.c_cc[VMIN]= 0;
721
#ifdef _POSIX_VDISABLE // Is a disable character available on this system?
722
// Some systems allow for per-device disable-characters, so get the
723
// proper value for the configured device
724
const long vdisable = fpathconf(fd, _PC_VDISABLE);
725
Posix_CommConfig.c_cc[VINTR] = vdisable;
726
Posix_CommConfig.c_cc[VQUIT] = vdisable;
727
Posix_CommConfig.c_cc[VSTART] = vdisable;
728
Posix_CommConfig.c_cc[VSTOP] = vdisable;
729
Posix_CommConfig.c_cc[VSUSP] = vdisable;
730
#endif //_POSIX_VDISABLE
731
setBaudRate(Settings.BaudRate);
732
setDataBits(Settings.DataBits);
733
setParity(Settings.Parity);
734
setStopBits(Settings.StopBits);
735
setFlowControl(Settings.FlowControl);
736
setTimeout(Settings.Timeout_Millisec);
737
tcsetattr(fd, TCSAFLUSH, &Posix_CommConfig);
739
if (queryMode() == QextSerialPort::EventDriven) {
740
readNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
741
connect(readNotifier, SIGNAL(activated(int)), this, SIGNAL(readyRead()));
744
qDebug() << "could not open file:" << strerror(errno);
745
lastErr = E_FILE_NOT_FOUND;
752
Closes a serial port. This function has no effect if the serial port associated with the class
753
is not currently open.
755
void QextSerialPort::close()
757
QMutexLocker lock(mutex);
760
// Force a flush and then restore the original termios
762
// Using both TCSAFLUSH and TCSANOW here discards any pending input
763
tcsetattr(fd, TCSAFLUSH | TCSANOW, &old_termios); // Restore termios
764
// Be a good QIODevice and call QIODevice::close() before POSIX close()
765
// so the aboutToClose() signal is emitted at the proper time
766
QIODevice::close(); // Flag the device as closed
767
// QIODevice::close() doesn't actually close the port, so do that here
775
Flushes all pending I/O to the serial port. This function has no effect if the serial port
776
associated with the class is not currently open.
778
void QextSerialPort::flush()
780
QMutexLocker lock(mutex);
782
tcflush(fd, TCIOFLUSH);
786
This function will return the number of bytes waiting in the receive queue of the serial port.
787
It is included primarily to provide a complete QIODevice interface, and will not record errors
788
in the lastErr member (because it is const). This function is also not thread-safe - in
789
multithreading situations, use QextSerialPort::bytesWaiting() instead.
791
qint64 QextSerialPort::size() const
794
if (ioctl(fd, FIONREAD, &numBytes)<0) {
797
return (qint64)numBytes;
801
Returns the number of bytes waiting in the port's receive queue. This function will return 0 if
802
the port is not currently open, or -1 on error.
804
qint64 QextSerialPort::bytesAvailable() const
806
QMutexLocker lock(mutex);
809
if (ioctl(fd, FIONREAD, &bytesQueued) == -1) {
812
return bytesQueued + QIODevice::bytesAvailable();
818
This function is included to implement the full QIODevice interface, and currently has no
819
purpose within this class. This function is meaningless on an unbuffered device and currently
820
only prints a warning message to that effect.
822
void QextSerialPort::ungetChar(char)
824
/*meaningless on unbuffered sequential device - return error and print a warning*/
825
TTY_WARNING("QextSerialPort: ungetChar() called on an unbuffered sequential device - operation is meaningless");
829
Translates a system-specific error code to a QextSerialPort error code. Used internally.
831
void QextSerialPort::translateError(ulong error)
836
lastErr=E_INVALID_FD;
840
lastErr=E_CAUGHT_NON_BLOCKED_SIGNAL;
850
Sets DTR line to the requested state (high by default). This function will have no effect if
851
the port associated with the class is not currently open.
853
void QextSerialPort::setDtr(bool set)
855
QMutexLocker lock(mutex);
858
ioctl(fd, TIOCMGET, &status);
865
ioctl(fd, TIOCMSET, &status);
870
Sets RTS line to the requested state (high by default). This function will have no effect if
871
the port associated with the class is not currently open.
873
void QextSerialPort::setRts(bool set)
875
QMutexLocker lock(mutex);
878
ioctl(fd, TIOCMGET, &status);
885
ioctl(fd, TIOCMSET, &status);
890
Returns the line status as stored by the port function. This function will retrieve the states
891
of the following lines: DCD, CTS, DSR, and RI. On POSIX systems, the following additional lines
892
can be monitored: DTR, RTS, Secondary TXD, and Secondary RXD. The value returned is an unsigned
893
long with specific bits indicating which lines are high. The following constants should be used
894
to examine the states of individual lines:
903
LS_RTS RTS (POSIX only)
904
LS_DTR DTR (POSIX only)
905
LS_ST Secondary TXD (POSIX only)
906
LS_SR Secondary RXD (POSIX only)
909
This function will return 0 if the port associated with the class is not currently open.
911
unsigned long QextSerialPort::lineStatus()
913
unsigned long Status=0, Temp=0;
914
QMutexLocker lock(mutex);
916
ioctl(fd, TIOCMGET, &Temp);
917
if (Temp&TIOCM_CTS) {
920
if (Temp&TIOCM_DSR) {
929
if (Temp&TIOCM_DTR) {
932
if (Temp&TIOCM_RTS) {
946
Reads a block of data from the serial port. This function will read at most maxSize bytes from
947
the serial port and place them in the buffer pointed to by data. Return value is the number of
948
bytes actually read, or -1 on error.
950
\warning before calling this function ensure that serial port associated with this class
951
is currently open (use isOpen() function to check if port is open).
953
qint64 QextSerialPort::readData(char * data, qint64 maxSize)
955
QMutexLocker lock(mutex);
956
int retVal = ::read(fd, data, maxSize);
958
lastErr = E_READ_FAILED;
964
Writes a block of data to the serial port. This function will write maxSize bytes
965
from the buffer pointed to by data to the serial port. Return value is the number
966
of bytes actually written, or -1 on error.
968
\warning before calling this function ensure that serial port associated with this class
969
is currently open (use isOpen() function to check if port is open).
971
qint64 QextSerialPort::writeData(const char * data, qint64 maxSize)
973
QMutexLocker lock(mutex);
974
int retVal = ::write(fd, data, maxSize);
976
lastErr = E_WRITE_FAILED;
978
return (qint64)retVal;