ViniciusDamiati / qextserialport

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

Port sometimes doesn't read data, until I open / close by another program before. #39

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Working under Windows Vista. Sometimes the port opens normally, but doesn't 
read data, until another program opens the port too, closes it afterwards. A 
new program start, and the port is running is required. One strange behaviour 
in this context: The port doesn't read any data, but it seems to accept data, 
because when I open the other program like mentioned, I get some answers from 
the connected device, which were requested from my own program before!?

Original issue reported on code.google.com by Michael....@treggs.com on 7 Feb 2010 at 9:13

GoogleCodeExporter commented 9 years ago
Can you provide your report in a chronological list of actions?  Typically, 
only one application can have the 
device open at a time.

Original comment by lst...@gmail.com on 7 Feb 2010 at 10:10

GoogleCodeExporter commented 9 years ago
Found the problem (I remember I've read it on some forums before) ...

Old code was:

port = new QextSerialPort( "COM15", QextSerialPort::EventDriven);
port->setBaudRate(BAUD57600);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
port->setDtr( true );
port->setRts( true );    

if (port->open(QIODevice::ReadWrite | QIODevice::Unbuffered) == true)
{
    ...
}

New code is:

port = new QextSerialPort( "COM15", QextSerialPort::EventDriven);
if (port->open(QIODevice::ReadWrite | QIODevice::Unbuffered) == true)
{
    port->setBaudRate(BAUD57600);
    port->setFlowControl(FLOW_OFF);
    port->setParity(PAR_NONE);
    port->setDataBits(DATA_8);
    port->setStopBits(STOP_1);
    port->setDtr( true );
    port->setRts( true );
    ....
}

Anyway, is there a chance to increase the robustness a little bit more?

The issue can be closed from my side :)

Original comment by Michael....@treggs.com on 8 Feb 2010 at 6:21

GoogleCodeExporter commented 9 years ago
Analyzed the problem a little bit further. In fact the only problem seems to be 
the following line:

port->setDtr( true );

I need to call it after port->open() to get the port working stable. All other 
lines can be attached 
before the open() method. Here is the reduced version of the problem:

port = new QextSerialPort( "COM15", QextSerialPort::EventDriven);
port->setBaudRate(BAUD57600);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
port->setDtr( true );
port->setRts( true );

if (port->open( QIODevice::ReadWrite | QIODevice::Unbuffered ) == true)
{
    port->setDtr( true ); //XXX needs to be set after open() once more
    ...
}

Original comment by Michael....@treggs.com on 8 Feb 2010 at 7:00

GoogleCodeExporter commented 9 years ago
You might be able to find it in the documentation, but certainly in the code 
the comments say "This function will 
have no effect if the port associated with the class is not currently open."

Original comment by lst...@gmail.com on 8 Feb 2010 at 7:07