You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

simonb

Beginner

  • "simonb" is male
  • "simonb" started this thread

Posts: 28

Location: Jerusalem,Israel

  • Send private message

1

Sunday, August 7th 2011, 3:46pm

QextSerialPort communicatio problem

Hi, I'm using QextSerialPort in my project
I got some wierd bug.
when I'm tring to communicate throw (rs232) with my progrem I got no response from the device.
Then when I'm connecting throw the Terminal I got a response,
Then I'm tring to communicate from my program again and I got a response.

Ideas? what can it be?

Source code

1
2
3
4
5
6
7
8
    port = new QextSerialPort(portName);
    port->setBaudRate(BAUD115200);
    port->setFlowControl(FLOW_OFF);
    port->setParity(PAR_NONE);
    port->setDataBits(DATA_8);
    port->setStopBits(STOP_2);  
    port->setTimeout(100);
    port->open(QIODevice::ReadWrite);

2

Monday, August 8th 2011, 7:06am

I don't use (anymore) QextSerialPort, but I'm experiencing the exactly same problem with QSerialDevice. I need to open/close the serial port with an external terminal before my program starts work.
After some trials I ended up the problem is the baudrate settings. Please, try the following:

1) start your program and verify it doesn't communicate with the device
2) close the port and start the terminal. Open the port with a *different* baudrate setting (of course it won't communicate)
3) close the terminal and restart you program

Does it communicate now?

If no, reopen the port from the terminal, this time with the correct baudrate. Then try again with your program. Now it should work.

I don't know how this happens but it's very annoying and almost unusable. The strange thing is that the same behavior now happens also on old program, where I never experienced this.

Anyone knows why?
Marco

simonb

Beginner

  • "simonb" is male
  • "simonb" started this thread

Posts: 28

Location: Jerusalem,Israel

  • Send private message

3

Monday, August 8th 2011, 11:40am

Solved the bug

Thanx for the replay!
The solution of this bug is first to open the port and then to set all the settings
it works for me.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
port = new QextSerialPort(portName);
    port->open(QIODevice::ReadWrite);   //Must be bufferred for us
    if (! port->isOpen()) {
            qDebug("Cannot open serial port: %s Error: %s",
                    portName.toAscii().constData(),
                    port->errorString().toAscii().constData());
            close();
            return -1;
    }
    port->setBaudRate(BAUD115200);
    port->setDataBits(DATA_8);
    port->setParity(PAR_NONE);
    port->setStopBits(STOP_2);  
    port->setFlowControl(FLOW_OFF);
    port->setTimeout(SERIAL_TIMEOUT);
    port->setRts( true );
    port->setDtr( true );

4

Monday, August 8th 2011, 11:55am

I'm pretty sure I already do this. But I will double-check the code.

EDIT: I confirm I set the baudrate after opening the port. But I always need to open the port with realterm (or hyperterminal) before the right baudrate will be set.

This post has been edited 1 times, last edit by "Marco Trapanese" (Aug 10th 2011, 10:45am)


simonb

Beginner

  • "simonb" is male
  • "simonb" started this thread

Posts: 28

Location: Jerusalem,Israel

  • Send private message

5

Wednesday, November 7th 2012, 11:30am

Hey Marco,

I got the same problem as you now,

Did you figure this out?

simonb

Beginner

  • "simonb" is male
  • "simonb" started this thread

Posts: 28

Location: Jerusalem,Israel

  • Send private message

6

Thursday, November 8th 2012, 10:06am

I got a temporary solution to my problem.

I use Activex to control the RealTerm, I open RealTerm, config the port, open/close and then close the RealTerm, then I connect to the port via my connection code.

I don't like this solution I want to understand what is the real problem.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
    QAxObject *realTerm = new QAxObject ("realterm.realtermintf", this);
    realTerm->dynamicCall("Visible",0); //hide real term
    realTerm->dynamicCall("TrayIconActive",0); 
    QString com = driver->getProperty("comport").toString();
    com = com.remove("COM"); 
    realTerm->dynamicCall("baud",691200); 
    realTerm->dynamicCall("Port",com);

    realTerm->dynamicCall("PortOpen",1); //open port
    //some delay
    ...
    realTerm->dynamicCall("PortOpen",0);//close port
    delete realTerm;
}