Logo Search packages:      
Sourcecode: qtemu version File versions  Download package

qint64 Win_QextSerialPort::writeData ( const char *  data,
qint64  maxSize 
) [protected, virtual]

Writes a block of data to the serial port. This function will write len bytes from the buffer pointed to by data to the serial port. Return value is the number of bytes actually written, or -1 on error.

before calling this function ensure that serial port associated with this class is currently open (use isOpen() function to check if port is open).

Implements QextSerialBase.

Definition at line 388 of file win_qextserialport.cpp.

References _bytesToWrite, bytesToWriteLock, and QextSerialBase::queryMode().

    DWORD retVal;

    QMutexLocker lock( mutex );

    retVal = 0;
    if (queryMode() == QextSerialBase::EventDriven) {

        OVERLAPPED *newOverlapWrite = new OVERLAPPED;
        ZeroMemory(newOverlapWrite, sizeof(OVERLAPPED));
        newOverlapWrite->hEvent = CreateEvent(NULL, true, false, NULL);

        bool success = WriteFile(Win_Handle, (void*)data, (DWORD)maxSize, & retVal, newOverlapWrite);
        if(success) {
            delete newOverlapWrite;
        } else if (!success && (GetLastError() == ERROR_IO_PENDING)) {
            // writing asynchronously...not an error
            // keep track of the OVERLAPPED structure so we can delete it when the write is complete
            QWriteLocker writelocker(bytesToWriteLock);
            _bytesToWrite += maxSize;
        } else {
            qDebug() << "serialport write error:" << GetLastError();
            lastErr = E_WRITE_FAILED;
            retVal = (DWORD)-1;
                qDebug() << "serialport: couldn't cancel IO";
            delete newOverlapWrite;
    } else if (!WriteFile(Win_Handle, (void*)data, (DWORD)maxSize, & retVal, NULL)) {
        lastErr = E_WRITE_FAILED;
        retVal = (DWORD)-1;
    return (qint64)retVal;

Generated by  Doxygen 1.6.0   Back to index