PDA

View Full Version : QSerialPort and sending bytes (with value > 127?)



blackmoon
23rd October 2015, 06:30
I have to communicate with cash-register.
If i send data without polish diacritic chars - it works, but i have to use CP852 encoding (chars (int) value > 127 ie 0xb1 then it does not work.
(i become from cash-register's service an example what to send and i send exacly this same)


QString hex = "0234301c4c49541d4741546f77617220a5a91e42411e43311e 44332c30301e45332c30301e47737a74756b613742413303";
QByteArray test = QByteArray::fromHex(hex.toLatin1());

serial = new QSerialPort(this);
serial->setPortName("ttyACM0");
serial->setBaudRate(QSerialPort::Baud9600);
serial->setDataBits(QSerialPort::Data8);
serial->setParity(QSerialPort::NoParity);
serial->setStopBits(QSerialPort::OneStop);
serial->setFlowControl(QSerialPort::NoFlowControl);

if(serial->open(QIODevice::ReadWrite))

{

qDebug()<<"Port is open!";
if(serial->isWritable())
{
qDebug()<<"Yes, i can write to port!";
}
serial->waitForBytesWritten(-1);
serial->write(test.data());
serial->flush(); // Port Error 12 (timed out???)
serial->close()
}

Lesiok
23rd October 2015, 06:46
What does it mean "does not work" ?

blackmoon
23rd October 2015, 07:39
What does it mean "does not work" ?

if i send data without (hex 0xA5, 0xA9) i become proper cash-register answer...in other case - i become nothing

how to send unsigned char (values 0-255)?

Lesiok
23rd October 2015, 08:15
Are you sure thar the sequence is correct (in accordance with the printer protocol) ? QSerial is only a pipe - does not analyze transmitted data.

blackmoon
23rd October 2015, 09:17
i am sure i send correctly and exactly that what give me cash-register service (i have succesed send my own data (with proper response) but only if they don't have chars with (int) > 127)
i thing something is wrong with sending this data (Debian 8.0/64bits)
1. chars, witch make problem
2. check sum - correcty calculated11469

Lesiok
23rd October 2015, 09:26
Maybe some problem similar to this (http://www.qtcentre.org/threads/64007-serial-readAll()-strange-problem-reading-form-FTD232) ? Can You make test on another platform ?

blackmoon
23rd October 2015, 09:47
yes, but only on 32 bit platform