pointer on struct to Qbytearray
-
wrote on 20 Apr 2023, 16:38 last edited by
Hi All!
Can anybody help in my question?, please
I have got the following data structures:
typedef struct { uint8_t prefix = 0xF0; uint8_t code = 0x00; } restart_t; typedef struct { uint8_t prefix = 0xF0; uint8_t code = 0x01; uint64_t start_addr = 0xFFFFFFFF15000020; } start_t; // typedef struct { uint8_t prefix = 0xF0; uint8_t code = 0x02; uint64_t start_addr = 0xFFFFFFFF15000020; uint32_t data_len = 0x00000000; uint8_t* data; } write_RAM_t;
I need to transfer these data to qextserialport via QbyteArray
And when I transfer restart_t by code below it transfer ok:restart_t restart; QByteArray dataArr2 = QByteArray(static_cast<char*>((void*)&restart), sizeof(restart)); if(port->isOpen()) { port->write(dataArr2); }
That verifies com-port monitor, I see F0 00 data sequense
But when I try to send in the same manner start_t struct I see
the following data sequence :
ff 01 9a 00 00 00 00 00 20 00 00 b5 ff ff ff ff
when I expect
ff 01 ff ff ff ff b5 00 00 20
So, as I understand, I need to point on start_t and write_RAM_t structures by pointer and then fill QbyteArray by these data
But I dont know how to do it
Please, help! -
Hi All!
Can anybody help in my question?, please
I have got the following data structures:
typedef struct { uint8_t prefix = 0xF0; uint8_t code = 0x00; } restart_t; typedef struct { uint8_t prefix = 0xF0; uint8_t code = 0x01; uint64_t start_addr = 0xFFFFFFFF15000020; } start_t; // typedef struct { uint8_t prefix = 0xF0; uint8_t code = 0x02; uint64_t start_addr = 0xFFFFFFFF15000020; uint32_t data_len = 0x00000000; uint8_t* data; } write_RAM_t;
I need to transfer these data to qextserialport via QbyteArray
And when I transfer restart_t by code below it transfer ok:restart_t restart; QByteArray dataArr2 = QByteArray(static_cast<char*>((void*)&restart), sizeof(restart)); if(port->isOpen()) { port->write(dataArr2); }
That verifies com-port monitor, I see F0 00 data sequense
But when I try to send in the same manner start_t struct I see
the following data sequence :
ff 01 9a 00 00 00 00 00 20 00 00 b5 ff ff ff ff
when I expect
ff 01 ff ff ff ff b5 00 00 20
So, as I understand, I need to point on start_t and write_RAM_t structures by pointer and then fill QbyteArray by these data
But I dont know how to do it
Please, help!Has nothing to do with QByteArray or Qt but with aligning of the struct members, see e.g. here: https://carlosvin.github.io/langs/en/posts/cpp-pragma-pack/
Don't know why you copy it to a QByteArray first instead directly calling write()
-
Has nothing to do with QByteArray or Qt but with aligning of the struct members, see e.g. here: https://carlosvin.github.io/langs/en/posts/cpp-pragma-pack/
Don't know why you copy it to a QByteArray first instead directly calling write()
wrote on 20 Apr 2023, 16:50 last edited bythanks for quick replay!
I cant do directly transfer cause port->write(QByteArray); -
thanks for quick replay!
I cant do directly transfer cause port->write(QByteArray);@another_one said in pointer on struct to Qbytearray:
I cant do directly transfer cause port->write(QByteArray);
So hard clicking on my link so you can find an overload of the write() function?
-
@another_one said in pointer on struct to Qbytearray:
I cant do directly transfer cause port->write(QByteArray);
So hard clicking on my link so you can find an overload of the write() function?
wrote on 20 Apr 2023, 17:15 last edited by@Christian-Ehrlicher
Thank you for the link, I checked your link right away but I don't see write function application of qextserialport there
Examples of the link based of streams and unfortunally I dont know how streams I can use with qextserialport -
@Christian-Ehrlicher
Thank you for the link, I checked your link right away but I don't see write function application of qextserialport there
Examples of the link based of streams and unfortunally I dont know how streams I can use with qextserialportLifetime Qt Championwrote on 20 Apr 2023, 17:17 last edited by Christian EhrlicherApart from the fact that I don't see a reason to use QExtSerialPort in favor of QSerialPort, QExtSerialPort is also a QIODevice ...
1/6