read and write in serial port
-
Hi,
Do you have any other application also accessing that serial port ?
-
My program worked today, and I have not any error.
But I do not any change to program.When I run program,
program connects to port successfully, but I receive just one data (space).But when I close this program and open Hercules_3-2-6 Application (rs232 terminal software), that application read data,
and after close Hercules_3-2-6 application and open my application again, this program works and reads data until restarting computer.I repeat this process many times.
But my project does not receive data after restarting system until port opens one time by Hercules_3-2-6 Application.
Meanwhile I have virtual USB COM port and my hardware connected to computer with USB.
-
Are you using the same serial port setup in both your application and Hercules_3-2-6 ?
-
yes, I using the same serial port setup in both my application and Hercules_3-2-6 .
Specification of port: Name: COM3, Baud Rate: 9600, Data bits: 8, Parity: None, Stop bits: 1, Flow control: None
My program:
void MySerialPort::openSerialPort() { serial->setPortName("COM3"); if (serial->open(QIODevice::ReadWrite)) { serial->setParity(QSerialPort::NoParity); serial->setBaudRate(QSerialPort::Baud9600); serial->setDataBits(QSerialPort::Data8); serial->setStopBits(QSerialPort::OneStop); serial->setFlowControl(QSerialPort::NoFlowControl); showStatusMessage("Connectedd"); } else { showStatusMessage(tr("Open error")); } }
Meanwhile I have the same problem in qtserialport terminal example.
When I run qtserialport terminal example, program connects to port successfully, but does not receive any data.
But when I close this program and open Hercules_3-2-6 Application (rs232 terminal software), that application read data, and after close Hercules_3-2-6 application and open terminal example again, this program works and reads data until restarting computer. -
Does the device need DTR ?
-
No,
I wrote a C# .net program. It worked very well likes to Hercules_3-2-6 Application and qt program worked after opening the program.
I added this line for handle error port.void MySerialPort::handleError(QSerialPort::SerialPortError error) { qDebug() << "Error: " << error;//I added this line if (error == QSerialPort::ResourceError) { showStatusMessage(serial->errorString()); closeSerialPort(); } }
Result of run program:
Error: 0
"Connectedd"
Error: 6
"\x00"Just sometimes I have error 6.
How do I fix break condition error? -
@SGaist
Thank you very much my dear.
Your answer was a big help for me.My problem was solved by set "setDataTerminalReady" function to false.
I did not have information about the signal DTR, by pointing you I read about that and find my problem. -