PDA

View Full Version : QextSerialPort strange initialisation problem



Ferric
24th January 2010, 22:06
Hi,

I'm not sure if this is the correct forum, I.e. Im not sure if its specifically related to the QextSerialPort class or not.

At the moment I am using two USB to Serial adapters connected together to create a connection between COM4 and COM7.

I have set up my program to use COM4 and a terminal program to use COM7.

My program only seems to communicate without errors when I first send some data between COM4 and COM7 using just two terminal programs.

If I don't do this first and I try to send data using my program, for example trying to send "hello" the terminal program simply receives the following: 00 80 80 80 00 00 80 00 80 80 80, in hex.

Or if I send "goodbye" I receive "80 00 80 80 80 80 00 00 00 00 80 00 80 80 00" in hex,

But if I set up two terminal programs between COM4 and COM7 and send some characters between them, which are received fine, then I go back to my program and a terminal program on COM7, then everything works fine from then on, until I restart my computer or something.




void Loader::send()
{
QextSerialPort * port = new QextSerialPort("COM4", QextSerialPort::EventDriven);
port->setBaudRate(BAUD9600);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
port->open(QIODevice::ReadWrite );//| QIODevice::Unbuffered); //The Unbuffered option did not help.
port->flush(); // I thought this might help but it didn't.
port->write("goodbye");
port->close();
}


So it seems I need to initialize something, and by creating communication between two terminal programs I am inadvertently doing this initialization... I'm just not sure what exactly this initialization is and how to implement it in my code...

Hope you can understand what I am trying to say, any help would be really welcome

kuzulis
25th January 2010, 07:16
Try an alternative: QSerialDevice
(see examples of it in the directory /examples)

Download click here: http://fireforge.net/snapshots.php?group_id=199

Also on the transfer of symbols see example here:http://www.qtcentre.org/threads/27490-QSerialDevice-never-comes-back-if-device-unavailable

Download example test: http://www.qtcentre.org/attachment.php?attachmentid=4185&d=1264337987

Ferric
25th January 2010, 08:06
Thanks, I might try implementing QSerialDevice tomorrow.

However I would still like to get to the bottom of the current problem, Its pretty odd and there must be a reason.. any thoughts appreciated..

Lesiok
25th January 2010, 10:20
Which version of QExtSerial are You using ?

SteveH
25th January 2010, 16:11
Hi,

Have you tried opening the port before setting the parameters ? - I seem to recall others with the same problem and it was due to the s/w not loading the actual port with the parameters if it was closed, just storing a local copy.

Regards
SteveH

schnitzel
25th January 2010, 17:39
Hi,

Have you tried opening the port before setting the parameters ? - I seem to recall others with the same problem and it was due to the s/w not loading the actual port with the parameters if it was closed, just storing a local copy.

Regards
SteveH

Double that.

I remember having some trouble in the beginning regarding intialization and opening. Currently everything works great by doing the following:



PortSettings pset;
//set pset here as required
...
QextSerialPort *port = new QextSerialPort(CommPort, pset, QextSerialPort::EventDriven);
retVal = port->open(QIODevice::ReadWrite);
etc.


hope this helps

Ferric
25th January 2010, 21:01
Which version of QExtSerial are You using ?
I am using qextserialport-1.2win-alpha.


Have you tried opening the port before setting the parameters ?

I just tried this and it works! Thanks heaps

Lesiok
26th January 2010, 08:03
As You see this is alfa revision 3 years old and is dead.
Use this version (http://code.google.com/p/qextserialport/). It is active developed.

yyiu002
23rd June 2010, 22:26
It works for me now, with following code:



//comPort is com8, baudSel=9600

port = new QextSerialPort(comPort, QextSerialPort::EventDriven);
port->open(QIODevice::ReadWrite);


port->setBaudRate(baudSel);
port->setDataBits(DATA_8);
port->setParity(PAR_NONE);
port->setStopBits(STOP_1);
port->setFlowControl(FLOW_OFF);
port->setTimeout(500);
port->setRts(true);
port->setDtr(true);