Hey all!

I've been messing around like mad with my code, and it seems I can't get it right.

Basically, I have a QByteArray that contains the values that I have read from my device. The results are usually like this:

01 02 00 03 0x 0y 0z, where X is the DIO number, Y the Input or Output, and Z whether the DIO is turned on or off.

I have to check these values (Y and Z), to see whether it's on Input (read) or Output (write), and whether it's turned on (0) or off (1), so that when I start the application, the checkboxes are either checked or unchecked dependent on the values that have been read.

Here are the relevant code pieces:

Using setChecked() for the checkboxes once clicked on the connect button, which contains the functions to then check whether the DIOs are on or off.
Qt Code:
  1. void EcoDIOManager::connection_established()
  2. {
  3. QString strSuccess = "Successfully connected to ",
  4. device_address = this->ui->txtbxIP->text();
  5.  
  6. this->enableObjects();
  7. this->ui->txtbxSuccess->setText(strSuccess%device_address);
  8. this->ui->chkDIO0->setChecked(this->read_bytes(0));
  9. this->ui->chkDIO1->setChecked(this->read_bytes(1));
  10. this->ui->chkDIO2->setChecked(this->read_bytes(2));
  11. this->ui->chkDIO3->setChecked(this->read_bytes(3));
  12. }
To copy to clipboard, switch view to plain text mode 

This is the function for checking the status (writing to the device which then responds with not 5 bytes, but 7 (6th is Input/Output, and 7th is On/Off).

Qt Code:
  1. bool EcoDIOManager::read_bytes(quint16 dio_n)
  2. {
  3. /*
  4.   * 1st byte: Command number, 1
  5.   * 2nd byte: Version, 2
  6.   * 3rd byte: Response only, any
  7.   * 4th byte: Data length, 1
  8.   * 5th byte: DIO channel
  9.   */
  10. QByteArray bytes;
  11.  
  12. bytes.push_back(1);
  13. bytes.push_back(2);
  14. bytes.push_back(NULLPTR);
  15. bytes.push_back(1);
  16. bytes.push_back(dio_n);
  17.  
  18. client.write(bytes);
  19.  
  20. client.read(7);
  21.  
  22. return bytes[6] == '00';
  23. }
To copy to clipboard, switch view to plain text mode 

I want to return true or false dependent on the status with the return, but I've tried everything I had in mind, but couldn't fix it.

E.g.:

Qt Code:
  1. return (bytes[8] == '0' & bytes[9] == '0');
  2.  
  3. return (bytes.mid(8,2) == '00');
To copy to clipboard, switch view to plain text mode 

Etc.

Any help would be greatly appreciated. =)