Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial works in LabView and not in C++

Hey,
I’m using Qextserialport 1.2 alpha in my project. (QT C++ programing)


I got invalid data when I use other windows application while I’m recording the data at hight rate of 400hz.
BUT, when I first open the port via HyperTerminal or LabView and then I connect throw my SW, the problem is vanished.

The problem doesn happend in low rate (1h,10h)

 

Any Idea?!?

 

 port = new QextSerialPort(portName,QextSerialPort::EventDriven);
 
    if(!port->open(QIODevice::ReadOnly )) {
        qDebug("Cannot open serial port: %s Error: %s",
               portName.toAscii().constData(),
               port->errorString().toAscii().constData());
        return -1;
    }
    connect( port, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    port->setBaudRate(BAUD921600);
    port->setDataBits(DATA_8);
    port->setParity(PAR_NONE);
    port->setStopBits(STOP_2);
    port->setFlowControl (FLOW_OFF);
    port->setRts( true );
    port->setDtr( true );

 

My setup:
Win XP sp3
QT 4.7.0

Thanx!

 

0 Kudos
Message 1 of 10
(7,692 Views)

Hello Simon,

 

It is a little unclear what your end goal is in this situation. Is it necessary to use the other windows applications if they are not returning valid data? Moreover, if you are able to utilize LabVIEW to get the results you need do you need to even consider the other applications?

Ian M.
National Instruments
0 Kudos
Message 2 of 10
(7,667 Views)

Thanks for your replay.


I'll try to be more clear about what I mean in "windows application".
While I'm recording data with my SW, each change that happened i.e. maximize or minimize the SW window or opening other document can damage the recording data.
This doesn't happened when I first open the LabView SW then connect and disconnect from the serial comport.
And then open my SW, connect the serial port start recording data and I can maximize or minimize the SW while recording and it won't damage the record.

 

P.S. I need to record the data with my SW and not with LabView.

0 Kudos
Message 3 of 10
(7,661 Views)

So, essentially, when you are working with the com port connections with the software as a standalone environment you have issues but if there are other software environments open then there isn't an issue?

Ian M.
National Instruments
0 Kudos
Message 4 of 10
(7,646 Views)

 I need to open/close the serial port with an external terminal (LabView / RealTerm) before my program starts work.

 

 

0 Kudos
Message 5 of 10
(7,640 Views)

Are you sure that the baud rate you are using is best suited for your application? That baud rate is only supported by certain serial devices/interfaces and its possible that when you open Hyperterminal or LabVIEW the baud rate you set in your code is being overwritten by default baud rate settings that the other programs use.

Ian M.
National Instruments
0 Kudos
Message 6 of 10
(7,631 Views)

Yes, I need to work with 691200 baud rate.

It's works well when I'm using LabView / RealTerm.

 

 

The procedure to get my software work is.

 

1. Reset the PC

2. Open / Close port from the RealTerm / LabView.

3. Open the port from my software.

 

 

 

0 Kudos
Message 7 of 10
(7,618 Views)

The following line says:

port->setBaudRate(BAUD921600);

Is this a typo? Because this isn't the rate you said you needed to work with (Baud rate: 691200).

Ian M.
National Instruments
0 Kudos
Message 8 of 10
(7,605 Views)

The correct baud rate is 691200

port->setBaudRate(BAUD691200);

 

I accidentally copied from other part of the code that work with 921600 baud rate.

 

Sorry.

 

 

0 Kudos
Message 9 of 10
(7,601 Views)

At this point, because this is not actually a LabVIEW issue I'm not sure what can be done for you at this point.

Ian M.
National Instruments
0 Kudos
Message 10 of 10
(7,591 Views)