np43 / qextserialport

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

qextserialport open() does not open correctly on my machine #58

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am writing a qt program on windowsxp and am having trouble opening my usb
port (COM3) using the qextserialport library. After calling
port_M->open(QextSerialPort::ReadWrite), true is returned, and isOpen()
also returns true. However, I cannot read or write!

Interestingly, if I first open the port with teraterm and then run my
program, no problems! I have even written a teraterm macro which has
teraterm connect and disconnect automatically (with lots of windows opening
and closing). However, I would rather not use the hack. Any thoughts???

Original issue reported on code.google.com by jfpen...@gmail.com on 30 Apr 2010 at 11:53

GoogleCodeExporter commented 9 years ago
I have same behavior but only on my WinXP machine. I use FTDI Virtual ComPort 
(COM8)
USB-To-Serial Bridge.

If I start my Machine and open the port via 
port->open(QextSerialPort::ReadWrite)
true is returned. If I poll port->isOpen() it is also true but no Bytes leave or
recieved.
Then I close my program and use hterm oder hyperterminal and simply do one open 
and
one close on the COM8, start my program again and all work fine like it should.

Original comment by josef.ha...@googlemail.com on 3 May 2010 at 8:16

GoogleCodeExporter commented 9 years ago
I have found out that there muste be a buffer somewhere. If I send more than 
6...8
bytes to the serial port, communication begins. But if I only send one byte, 
the byte
is not delivered after long timeout. Maybe the problem is in the 
Virtual-Com-FTDI
somewhere... But in HTerm there is no delay. 

I Open port with:
    port->setBaudRate(BAUD115200);
    port->setFlowControl(FLOW_OFF);
    port->setParity(PAR_NONE);
    port->setDataBits(DATA_8);
    port->setStopBits(STOP_1);
    port->setPortName(name);
    port->setQueryMode(QextSerialPort::Polling);
    if(port->open((QIODevice::ReadWrite | QIODevice::Unbuffered) ))

Original comment by josef.ha...@googlemail.com on 5 May 2010 at 8:16

GoogleCodeExporter commented 9 years ago
I FINALLY figured this one out. Apparently, setting the port settings has no 
effect
until the port is open. It seems like a library bug. Here is my working code:

    port_M->setPortName("COM3");
    if(port_M->open(QIODevice::ReadWrite)){
        port_M->setBaudRate(BAUD9600);
        port_M->setFlowControl(FLOW_OFF);
        port_M->setParity(PAR_NONE);
        port_M->setDataBits(DATA_8);
        port_M->setStopBits(STOP_1);
        port_M->setTimeout(100);
    }

Original comment by jfpen...@gmail.com on 5 May 2010 at 7:00

GoogleCodeExporter commented 9 years ago
It didn't work for me. FTDI as well...

Original comment by andrey.p...@gmail.com on 20 Mar 2011 at 2:15

GoogleCodeExporter commented 9 years ago
Hi!
I have met the same problem. 
Did you find a solution?

Original comment by ibrahim....@laposte.net on 7 Jul 2011 at 3:12

GoogleCodeExporter commented 9 years ago
Hi!!
I have met the same problem and I have at last resolved it.
The example of "jfpen...@gmail.com" is almost correct. Just few lines missing:

    m_port = new QextSerialPort;
    m_port->setPortName(m_portCom);
    m_port->setQueryMode(QextSerialPort::EventDriven);
    if(m_port->open(QIODevice::ReadOnly) == true)
    {
    m_port->setBaudRate(BAUD9600);
    m_port->setParity(PAR_EVEN);
    m_port->setDataBits(DATA_8);
    m_port->setStopBits(STOP_1);
    m_port->setFlowControl(FLOW_HARDWARE);
    m_nbTrames = 0;

    connect(m_port, SIGNAL(readyRead()), this, SLOT(receive()));
    connect(m_port, SIGNAL(dsrChanged(bool)), this, SLOT(statusChanged(bool)));
    }

For more details, see the attached files.

I hope it will help you!

Original comment by theWhole...@gmail.com on 9 Aug 2011 at 1:03

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the hint, I had the same problem. There really should be a hint 
somewhere as even the examples are wrong...

Original comment by ralf.dau...@gmail.com on 21 Sep 2011 at 6:44

GoogleCodeExporter commented 9 years ago
Thanks to "jfpen...@gmail.com". Now my code it's working.
Apparently, setting the port settings has no effect until the port is open. It 
seems like a library bug.

Original comment by brunoder...@hotmail.com on 7 Dec 2011 at 10:07

GoogleCodeExporter commented 9 years ago
Hi there. I´m using 1.2 WIN ALPHA and I think there are two problems.
1) On the one hand, in the function setbaudrate, if the port is open there´s a 
switch-case decision that do not includes default case, so one cannot change 
the baudrate to a user baudrate if the port is open.
2) In the open function, setbaudrate, setparity, setflowcontrol... functions 
are called before calling QIODevice::open, so neither the baudrate nor the 
others are updated in the Win_CommConfig.dcb struct and, therefore, applied, 
because the setbaudrate (and the others) function updates this struct only if 
the isOpen function returns true.

My solution:
1) write a default case that copies the baudrate to Win_CommConfig.dcb.baudrate
2) call QIODevice::open before updating the Win_CommConfig.dcb struct.

Maybe it´s not the best solution, but it works.

PS: I used sysinternals portmon to see what happens when I try to change 
baudrate, open ports, etc.

Original comment by carlos.b...@gmail.com on 22 Dec 2011 at 4:14

GoogleCodeExporter commented 9 years ago
Thanks

Original comment by dbzhang...@gmail.com on 16 Mar 2012 at 8:14