PDA

View Full Version : Receive a raw data via serial port (qExtSerialPort)



AUDI_ENG
2nd July 2014, 08:44
Hello everyone,

I'm now here, thank you for your forum,

I have a problem in receiving data via serial port (Raspberry pi)..
I use the QextSerialPort,
I'm sure that data sent by the other device is correct, i have in the oscilloscope the uart trames
but when i send this data, i receive a strange data
this is my code :


in this fuction , i call the slot function :

if(msgBoxConfirmerReception->exec() == QMessageBox::Yes){

portReception->setBaudRate(BAUD115200);
portReception->setFlowControl(FLOW_OFF);
portReception->setParity(PAR_NONE);
portReception->setDataBits(DATA_8);
portReception->setStopBits(STOP_1);

if(portReception->open(QIODevice::ReadOnly)==true){

connect(portReception, SIGNAL(readyRead()), this, SLOT(receiveTrames()));
qDebug()<<"listenning for data on";

}

else{
QMessageBox::critical(this,"ERREUR","le port UART n'est pas connecté");
qDebug()<<"device failed to open:"<<portReception->errorString();
portReception->close();
exit(1);

}




}

----------------------------------------------------

void AffichageTrames::receiveTrames()

{

StopAff->setEnabled(true);
QByteArray bytes;
int a = portReception->bytesAvailable();
bytes.resize(a);
qDebug() << "nb data availble = " <<a;
portReception->read(bytes.data(), bytes.size());
qDebug() << QString(bytes.toHex())<<"\n";

}

for exemple if i send a value = 1
I receive : fe (Hexadecimal)

kuzulis
2nd July 2014, 14:19
Why do you use the QextSerialPort, what reason?

It is better to use QtSerialPort (https://qt-project.org/wiki/QtSerialPort)instead. The QtSerialPort already are present (http://qt-project.org/doc/qt-5/qtserialport-index.html)in Qt5 (also this module can be compiled and for Qt4, see wiki).

AUDI_ENG
2nd July 2014, 14:24
thank you for your reply,

i don't have any reason, i don't know other library to send data by serial port
i know qtExtSerialPort and QtSerialPort

I use Qt 4.7 so QtSerialPort can be used in Qt4 ? because when i give a search in google, i see that its only used in Qt5

Lesiok
2nd July 2014, 14:56
1. Are you sure that parameters (speed, parity etc) are OK ?
2. How method AffichageTrames::receiveTrames() is activated ?

kuzulis
2nd July 2014, 15:06
@AUDI_ENG,


I use Qt 4.7 so QtSerialPort can be used in Qt4 ? because when i give a search in google, i see that its only used in Qt5

you can see similar my reply (https://qt-project.org/forums/viewreply/183055/)on another forum.

AUDI_ENG
3rd July 2014, 08:45
@AUDI_ENG,



you can see similar my reply (https://qt-project.org/forums/viewreply/183055/)on another forum.


thank you,
I will try this library today


1. Are you sure that parameters (speed, parity etc) are OK ?
2. How method AffichageTrames::receiveTrames() is activated ?

I active this fonction with the readyRead() signal :

connect(portReception, SIGNAL(readyRead()), this, SLOT(receiveTrames()));

In the other device, i have the same baude : 115200 and i didn't integrate the parity mode in the uart trames

Lesiok
3rd July 2014, 09:14
I active this fonction with the readyRead() signal :

connect(portReception, SIGNAL(readyRead()), this, SLOT(receiveTrames()));

In the other device, i have the same baude : 115200 and i didn't integrate the parity mode in the uart trames
1. All parameters (speed, parity, word length, stop bits) must be the same on both ends.
2. How value 1 is sent ? As one byte, as ASCII character or integer ?

AUDI_ENG
3rd July 2014, 11:06
1. All parameters (speed, parity, word length, stop bits) must be the same on both ends.
2. How value 1 is sent ? As one byte, as ASCII character or integer ?

I have a pic microcontroller, so i use the TX/RX (UART) port.. i send a "bytes" data ..
for example in the output (oscilloscope) i have :
start bit | data byte | stop bit
___0____10000000____1___

this correspond to "1" value

on both devices, i disable the parity mode, i have 115200, i have stop bits, and the word length is a "byte"

Lesiok
3rd July 2014, 11:59
What happen if You change code to this :

void AffichageTrames::receiveTrames()
{
StopAff->setEnabled(true);
QByteArray bytes;
bytes = portReception->readAll();
qDebug() << "nb data read = " << bytes.size() << " bytes = " << QString(bytes.toHex())<<"\n";
}
P.S.
I hope You have latest version of QExtSerialPort library (https://code.google.com/p/qextserialport/downloads/detail?name=qextserialport-1.2rc.zip&can=2&q=)

^NyAw^
3rd July 2014, 12:33
Hi,

I also recommend you to use a serial port sniffer to ensure that the data you are sending is the data you are receiving.

AUDI_ENG
3rd July 2014, 12:47
What happen if You change code to this :

void AffichageTrames::receiveTrames()
{
StopAff->setEnabled(true);
QByteArray bytes;
bytes = portReception->readAll();
qDebug() << "nb data read = " << bytes.size() << " bytes = " << QString(bytes.toHex())<<"\n";
}
P.S.
I hope You have latest version of QExtSerialPort library (https://code.google.com/p/qextserialport/downloads/detail?name=qextserialport-1.2rc.zip&can=2&q=)

Now, I have the qtSerialPort library,

I test this code ..

I receive :
nb data read = 1 bytes = "FE"
but in the oscilloscope i have one byte :
start bit | data byte | stop bit
___0___10000000____1___


Hi,

I also recommend you to use a serial port sniffer to ensure that the data you are sending is the data you are receiving.

thank u, i will try this now

AUDI_ENG
4th July 2014, 12:09
HI
I"m solving the problem..
its consist on value of baud rate in the other device (microcontroller PIC)
im using a cristal with 10 Mhz and the PLL in the pic is enabled so (Frequency of system = 4*Fosc = 40 Mhz) --> so the baud rate is not the same if we considerate that frequency are only 10 Mhz

Thank you so much !

Lesiok
4th July 2014, 13:03
HI
I"m solving the problem..
its consist on value of baud rate in the other device (microcontroller PIC)
im using a cristal with 10 Mhz and the PLL in the pic is enabled so (Frequency of system = 4*Fosc = 40 Mhz) --> so the baud rate is not the same if we considerate that frequency are only 10 Mhz

Thank you so much !

I told you so :D

AUDI_ENG
4th July 2014, 14:08
I told you so :D

yes Thank you :D so much ;)