我正在使用Window 7 x64 問題在於我用Arduino發送PC信息,並且在讀取端口時,我收到Arduino發送的奇怪的神器(0000000)PC讀取(0000 + 000)或類似的東西(00000 + 00) - (0 + 000000)等等。qextserialport奇怪的讀
對於一個例子,我將顯示的屏幕截圖
和
打開端口
bool MainWindow::openPort()
{
QString strPort = LineConnect->currentText();
port = new QextSerialPort(strPort, QextSerialPort::EventDriven);
if (port->open(QIODevice::ReadWrite | QIODevice::Unbuffered) == true) {
port->setBaudRate(BAUD9600);
port->setDataBits(DATA_8);
port->setParity(PAR_NONE);
port->setStopBits(STOP_1);
port->setFlowControl(FLOW_OFF);
port->setTimeout(100);
port->waitForReadyRead(10);
port->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
connect(port,SIGNAL(readyRead()), this, SLOT(onReadyRead()));
INFO_conn->append("port "+ port->portName() + " opened..");
INFO_conn->append("port " + port->portName() + " reading..");
return true;
} else {
INFO_conn->append("port " + port->portName() + " error connection..");
}
return false;
}
讀數據
對於PCvoid setup()
{
Serial.begin(9600);
.....
}
void loop()
{
Serial.print(K38);
Serial.print(K40);
Serial.print(K42);
Serial.print(K44);
Serial.print(K46);
Serial.print(K48);
Serial.print(K50);
or
Serial.print("0000000"); // result same
}
我不能什麼可以有一個問題理解
void MainWindow::onReadyRead()
{
/*first option read data*/
QByteArray msg = port->readAll();
int size = msg.size();
QString data = "Data: " + msg + " size: " + QString::number(size);
INFO_conn->append(data);
/*second option read data*/
// char data[1024];
// QTextStream out(stdout);
// out << "data received: ";
// int bytesRead = port->read(data, 1024);
// data[bytesRead] = '\0';
// out << data << " (" << bytesRead << " bytes)" << endl;
// //QString messRead = "data received: " + data +" "+ bytesRead + " bytes";
// INFO_conn->append(data);
}
發送數據Arduino的,都試過了。 來自QexSerialPort庫的示例讀得最多。 需要幫助。感謝您的幫助。
你應該考慮使用QtSerialPort。我無法提及在新代碼中使用QextSerialPort的任何原因。 – lpapp