send uint8_t using serialPort.writeData
-
Hello,
I am new to this forum. I have a problem when i am using
serialPort.writeData
i NEED to send data as uint8_t as this is what the receiver expects and I cannot change that at this point.When i try
uint8_t cmd[3000]; memcpy(cmd, "x", 4); cmd[4] = CMD_SENDING_FIRMWARE_PAGE & 0xFF; cmd[5] = (CMD_SENDING_FIRMWARE_PAGE << 8) & 0xFF; cmd[6] = (uint8_t)(payLoadSize & 0xFF); cmd[7] = (uint8_t)(payLoadSize >>8); cmd[8] = pageId; memcpy(&cmd[9], data, pageSize);` cmd[8 + payLoadSize] = CalcChecksum(cmd, cmdSize); serialPort.write(cmd, cmdSize + 1);
I get the error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'const char*' [-fpermissive]
Can anyone please help? The data must be sent as uint8_t Thanks
-
Hello,
I am new to this forum. I have a problem when i am using
serialPort.writeData
i NEED to send data as uint8_t as this is what the receiver expects and I cannot change that at this point.When i try
uint8_t cmd[3000]; memcpy(cmd, "x", 4); cmd[4] = CMD_SENDING_FIRMWARE_PAGE & 0xFF; cmd[5] = (CMD_SENDING_FIRMWARE_PAGE << 8) & 0xFF; cmd[6] = (uint8_t)(payLoadSize & 0xFF); cmd[7] = (uint8_t)(payLoadSize >>8); cmd[8] = pageId; memcpy(&cmd[9], data, pageSize);` cmd[8 + payLoadSize] = CalcChecksum(cmd, cmdSize); serialPort.write(cmd, cmdSize + 1);
I get the error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'const char*' [-fpermissive]
Can anyone please help? The data must be sent as uint8_t Thanks
@Aeroplane123 You have to reinterpret_cast<> it to a const char* when passing it to QSerialPort::write()
-
Will this keep the data the same for the receiving end?
-
Will this keep the data the same for the receiving end?
@Aeroplane123 said in send uint8_t using serialPort.writeData:
Will this keep the data the same for the receiving end?
Yes, a cast does not change the data, it just tells the compiler how to treat the data.
-
Hello,
I am new to this forum. I have a problem when i am using
serialPort.writeData
i NEED to send data as uint8_t as this is what the receiver expects and I cannot change that at this point.When i try
uint8_t cmd[3000]; memcpy(cmd, "x", 4); cmd[4] = CMD_SENDING_FIRMWARE_PAGE & 0xFF; cmd[5] = (CMD_SENDING_FIRMWARE_PAGE << 8) & 0xFF; cmd[6] = (uint8_t)(payLoadSize & 0xFF); cmd[7] = (uint8_t)(payLoadSize >>8); cmd[8] = pageId; memcpy(&cmd[9], data, pageSize);` cmd[8 + payLoadSize] = CalcChecksum(cmd, cmdSize); serialPort.write(cmd, cmdSize + 1);
I get the error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'const char*' [-fpermissive]
Can anyone please help? The data must be sent as uint8_t Thanks
@Aeroplane123 said in send uint8_t using serialPort.writeData:
cmd[5] = (CMD_SENDING_FIRMWARE_PAGE << 8) & 0xFF;
As a minor point/aside, this is almost certainly incorrect/not what you intend....
-
Will this keep the data the same for the receiving end?
This post is deleted!