[英]write and read hexadecimale trame qt serial port
How can I write and read hex data when I open serial port? 打开串行端口时如何读写十六进制数据?
if (serial->isOpen()) {
qDebug() << "seccus: " ;
static const char buff[] = {0xA1, 0xFF, 0xFF, 0x00,97};
serial->write(buff,sizeof(buff));
}
if (serial->bytesAvailable()) { // If there are bytes available
QByteArray f_data; // data container
f_data.clear();
if (serial->open(QIODevice::ReadWrite)) { // Try to open the port
while(serial->bytesAvailable()) { // Reading loop
f_data.append(serial->readAll());
}
serial->flush();
}
qDebug()<< "the result" << f_data; // Check the result
}
if(!serial->isOpen())
qDebug() << "carte disconnect"<<serial->errorString();
To debug your issue, I would start with simplifying what you're trying to do. 为了调试您的问题,我将从简化您要尝试的操作开始。 Try writing some test code to start, to make sure things work as you expect: 尝试编写一些测试代码以启动,以确保一切正常。
Perhaps if one of these steps doesn't work as you expect, you can at least focus on why that particular part is not working. 也许如果这些步骤之一没有按您预期的那样工作,那么您至少可以专注于特定部分为何无法工作的原因。
Good luck. 祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.