Hey again,
I've been pulling my hair out for these past few days, but it seems I just can't find the problem.
readBytes is still an empty string after this bit:
bool EcoDIOManager::isOn(quint16 dio_n)
{
bool isOn = false;
const char ON = 0x00;
const int switchIndex = 6;
if(readBytes.size() > switchIndex && readBytes[switchIndex] == ON)
{
isOn = true;
}
else
{
isOn = false;
}
return isOn;
}
bool EcoDIOManager::isOn(quint16 dio_n)
{
bool isOn = false;
const char ON = 0x00;
const int switchIndex = 6;
QByteArray readBytes = this->read_bytes(dio_n);
if(readBytes.size() > switchIndex && readBytes[switchIndex] == ON)
{
isOn = true;
}
else
{
isOn = false;
}
return isOn;
}
To copy to clipboard, switch view to plain text mode
I suspected that the problem lies with the call of the read_bytes(dio_n) function.
QByteArray EcoDIOManager
::read_bytes(quint16 dio_n
) {
/* *******************************
* 1st byte: Command number, 1
* 2nd byte: Version, 2
* 3rd byte: Response only, any
* 4th byte: Data length, 1
* 5th byte: DIO channel
********************************/
bytes.push_back(1);
bytes.push_back(2);
bytes.push_back(NULLPTR);
bytes.push_back(1);
bytes.push_back(dio_n);
client.write(bytes);
this->ui->txtbxOutput->append(client.read(7).toHex());
return client.read(7);
}
QByteArray EcoDIOManager::read_bytes(quint16 dio_n)
{
/* *******************************
* 1st byte: Command number, 1
* 2nd byte: Version, 2
* 3rd byte: Response only, any
* 4th byte: Data length, 1
* 5th byte: DIO channel
********************************/
QByteArray bytes;
bytes.push_back(1);
bytes.push_back(2);
bytes.push_back(NULLPTR);
bytes.push_back(1);
bytes.push_back(dio_n);
client.write(bytes);
this->ui->txtbxOutput->append(client.read(7).toHex());
return client.read(7);
}
To copy to clipboard, switch view to plain text mode
I've also tried return client.read(7).toHex();.
The function on itself parses the values (the string of bytes) properly in the textbox (I can see the values I need without any issues), yet it cannot be used in EcoDIOManager::isOn().
Any suggestions as to why this might occur at all? It's driving me crazy. I've nearly not had as many problems figuring out how to write as opposed to apply a process to reading.
Bookmarks