Hello everyone, I'm having some problems sending my commands to the device through a serial port. So first, I create a Qlineedit that only takes integer, from 0 to 21, and then I create a pushButton with this code
void MainWindow::on_pushButton_2_clicked() //testing button
{
QString input
= ui
->lineEdit
->text
();
bool ok;
char data = input.toInt(&ok, 16);
char checksum;
char power[] = {0x01, 0x06, 0x08, data, checksum, 0x04};
char result = 0x00;
for (int i=0; i<4; i++) {
result += power[i];
};
checksum = result;
power[4]=checksum;
serial->write(power,sizeof(power));
}
void MainWindow::on_pushButton_2_clicked() //testing button
{
QString input = ui->lineEdit->text();
bool ok;
char data = input.toInt(&ok, 16);
char checksum;
char power[] = {0x01, 0x06, 0x08, data, checksum, 0x04};
char result = 0x00;
for (int i=0; i<4; i++) {
result += power[i];
};
checksum = result;
power[4]=checksum;
serial->write(power,sizeof(power));
}
To copy to clipboard, switch view to plain text mode
so for example, if I put in "1" to the lineedit, it will generate a char array of 01, 06, 08, 01, 10, 04 and send it to the serial port. If I input "2", it's going to be 01, 06, 08, 02, 11, 04, and etc. The way I check if the data is sent correctly is that the device will send back an acknowledge line. I've tried this and successfully done it up to 15, then I don't know why but from 16 to 21, the data can't be sent correctly because the device doesn't send back anything. If it doesn't work at all then I know what to fix, but in this case, it works but only for 0-15, so I'm really confused. I will appreciate any help, thank you.
Bookmarks