[英]write and read hexadecimale trame qt 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();
為了調試您的問題,我將從簡化您要嘗試的操作開始。 嘗試編寫一些測試代碼以啟動,以確保一切正常。
也許如果這些步驟之一沒有按您預期的那樣工作,那么您至少可以專注於特定部分為何無法工作的原因。
祝好運。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.