Details
-
Bug
-
Resolution: Unresolved
-
P4: Low
-
None
-
5.7
-
None
-
Windows 10, VC 2013, Qt 5.7.1, QSerialPort
Description
Observation: when communicating with a Linux g_serial based device from Windows 10 I get Windows error 87 "Wrong Parameter" if the QByteArray passed to QSerialPort::write is 4.2 MB or greater, but it works if 4.1 MB or smaller.
Analysis: _q_startAsyncWrite seems to hand over the original QByteArray 1:1 to ::WriteFile. The code does not assume any buffer size limitation and indeed I did not find any MS documentation or forum posts indicating such a limitation. But there seems to be one on Windows, even if undocumented. The issue does not occur on macOS.
Work-around: I can avoid the Windows error using the following adapter:
static int serialWriteAdapter( QSerialPort* port, const QByteArray& buf ){ #ifdef Q_OS_WIN const int winBufferSizeLimit = 4100000; int i = 0; while( i < buf.size() ) { const int res = port->write( buf.mid(i,winBufferSizeLimit) ); if( res < 0 ) return -1; i += res; } return i; #else return port->write(buf); #endif }
The work-around also works on Windows 7.
Attachments
Gerrit Reviews
For Gerrit Dashboard: QTBUG-69229 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
233708,3 | Restrict maximum write chunk size with 32768 bytes on Windows | 5.11 | qt/qtserialport | Status: DEFERRED | -1 | 0 |