Serial port communication in Qt -


i new qt , need prepare project send hex commands rs232. qstring line contains 64bit binary data have convert hexadecimal , send through rs232 .

 qstring a=ui->combobox->currenttext();     qstring s1;     s1="./calc "+a;     qprocess p1;     p1.start(s1);     p1.waitforfinished(-1);     qstring line ;      //read            qfile file("teleoutput.txt");     if (!file.open(qiodevice::readonly | qiodevice::text))          return;      qtextstream in (&file);   line = in.readall();     ui->plaintextedit->setplaintext(line); 

so, how convert 64 bit binary data in qstring line hexadecimal value , transfer through rs232?

first of - should use qtserialport

second of - qstring class, works actual string. qbytearray works raw data. when write qstring line = in.readall(); implicitly calls qstring(const qbytearray &ba), uses qstring::fromascii.

last of all, if want process 64bit integers, should this:

quint64 d; qdatastream stream(&file); while (!stream.atend()) {     stream >> d;     process(d); } 

update

quote:

my problem in plaintextedit "1111110101000101010101010101010101010101010101010101010......." 64 bit data populated , need convert data hex , send through rs232

solution:

qstring bindata = plaintextedit.toplaintext(); qbytearray result; while (bindata.size() >= 64) {     quint64 d;     qstring datapiece = bindata.left(64);     bindata.remove(0, 64);     d = datapiece.toulonglong(0, 2);     result += qbytearray::number(d); } _com->write(result); _com->flush(); 

where _com pointer qtserialport, parameters set , opened without errors.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -