hi, thank you for the reply.. i did try qDebug()<< firstByte << secondByte; i can see the value there. I have firstByte ,secondByte,hexadecimaldata declared as QByteArray in the .h file i am doing some calculations and getting a decimal data which i convert into hexadecimal and append it into the byte array hexadecimaldata.
This is of 2 bytes i need to send the first byte and after a small delay the second byte, thats when the hardware i am communicating with will respond to the data i send.
void SingleChDACQ::CalEqu()
{
float e = lineEdit_3->text().toFloat();
float s = lineEdit_2->text().toFloat();
float f = 5 * s;
float g = 1000 * e;
volt = f/g;
// qDebug()<<volts;
volts = volt * 1000;
hexvaluebuff = volts / 2;
finhexval = hexvaluebuff/0.61035;
uint decimal = finhexval;
hexadecimal.setNum(decimal,16);
firstByte = "0x"+hexadecimal.left(1);
secondByte = "0x"+hexadecimal.mid(1, 2);
sendFrame() ;
// in send frame i am trying to send these 2 bytes. char i = port->write(firstByte);
//char i = port->write(firstByte);
//char i = port->write(secondByte);
}
void SingleChDACQ::CalEqu()
{
float e = lineEdit_3->text().toFloat();
float s = lineEdit_2->text().toFloat();
float f = 5 * s;
float g = 1000 * e;
volt = f/g;
// qDebug()<<volts;
volts = volt * 1000;
hexvaluebuff = volts / 2;
finhexval = hexvaluebuff/0.61035;
uint decimal = finhexval;
hexadecimal.setNum(decimal,16);
firstByte = "0x"+hexadecimal.left(1);
secondByte = "0x"+hexadecimal.mid(1, 2);
sendFrame() ;
// in send frame i am trying to send these 2 bytes. char i = port->write(firstByte);
//char i = port->write(firstByte);
//char i = port->write(secondByte);
}
To copy to clipboard, switch view to plain text mode
Added after 4 minutes:
hi thanks for your reply,
i have appended 0x because even though i am converting the decimal to hex format i am not able to communicate cause the hardware is not detecting the bytes sent. But if i put 0x before the data i have i get the repose from the hardware.
firstByte = "0x"+hexadecimaldata.left(2);
secondByte = "0x"+hexadecimaldata.mid(1, 2);
firstByte = "0x"+hexadecimaldata.left(2);
secondByte = "0x"+hexadecimaldata.mid(1, 2);
To copy to clipboard, switch view to plain text mode
where do you think i am going wrong.?? not able to send the data when i send using qbytearray. but when i do this it works properly. but when i try to send the data with a byte array
char i = port->write(firstByte);
i am not able to get send the data cause i am not getting a response.
static const char mydata[] = {0xAC,0XCA};
char i = port->write(mydata,sizeof(mydata));
static const char mydata[] = {0xAC,0XCA};
QByteArray data = QByteArray::fromRawData(mydata, sizeof(mydata));
char i = port->write(mydata,sizeof(mydata));
To copy to clipboard, switch view to plain text mode
i tried so many diffrent things but was not sucessfull.
thank you.
Bookmarks