The second parameter you are passing to that function is not unsigned char, it is a QByteArray. Further, the byte array you are using is a string representation of the bytes in the array in hex: a very different thing to the actual bytes that you almost certainly want to be sending. The first byte in the QByteArray is an unsigned char:
if(rs485WriteData(_READ_ENGINEADDRESS, data.at(0)))
if(rs485WriteData(_READ_ENGINEADDRESS, data.at(0)))
To copy to clipboard, switch view to plain text mode
It seems you are generally confused about the difference between the value in a byte and the string representation of it. If you want to compare the value of the first byte in the QByteArray then do so directly, don't convert to a string and then compare. So, line 8 becomes:
if (data.at(0) < 0x06) // notice no quotes and no toHex(), or
if (data.at(0) < 6) // same thing in decimal
if (data.at(0) < 0x06) // notice no quotes and no toHex(), or
if (data.at(0) < 6) // same thing in decimal
To copy to clipboard, switch view to plain text mode
and line 10:
if( data.toHex() < _ENGINEROOM_SUBS )
if( data.toHex() < _ENGINEROOM_SUBS )
To copy to clipboard, switch view to plain text mode
I am assuming that _READ_ENGINEADDRESS and _ENGINEROOM_SUBS are defined integer literals in hex like
#define _READ_ENGINEADDRESS 0x06
#define _READ_ENGINEADDRESS 0x06
To copy to clipboard, switch view to plain text mode
which lead to think you needed to convert your byte array to a hex string.
Bookmarks