grag38 / qextserialport

Automatically exported from code.google.com/p/qextserialport
0 stars 0 forks source link

Status of lastError() #6

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What is the status of lastError()?
I always get E_NO_ERROR even if the line s disconnected, timeout, etc., same on 
Mac or 
Windows. On Windows I have regular COM ports, on Mac I have a UC-232A serial 
converter.

I use do like this:
void 
SerialPort::PortWrite(char *message)
{
    port->write(message,3);
    lasterror = port->lastError();

}

char
SerialPort::PortRead(char *Buffer)
{
    int BytesRead = 0;
    char buf[128]="";
    Buffer[0] = Buffer[1] = NULL;
    buf[0] = buf[1] = NULL;
    do
    {
        BytesRead = port->read(buf,1);
        lasterror = port->lastError();
        if(BytesRead) {
            if(buf[0] == 0x0a) break;
            else if(buf[0] != 0x0d) strcat(Buffer, buf);
        }
    }while(BytesRead > 0);
    return *Buffer;
}

Right or wrong?

Original issue reported on code.google.com by bengt.ni...@spray.se on 19 Jun 2009 at 10:38

GoogleCodeExporter commented 8 years ago
You need to confirm the port is open before reading/writing on it, by making a 
call to isOpen().

The way it works is that the qesp specific read/write code is not even called 
if the port is not open, so it doesn't 
have a chance to set the lastError.

Original comment by lst...@gmail.com on 19 Jun 2009 at 4:56