从网络接受数据,发送到串口,然后把串口返回的数据发送到网络。
基本布局如下图:串口名写在lineedit中,Send按钮不用。
具体代码如下:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_status = false;
this->setFixedSize(652,337);
this->setWindowTitle(tr("Three"));
m_port = 8878;
m_pServerIP = new QHostAddress();
m_pserialPort = new QSerialPort();
m_pTcpServer = new QTcpServer(this);
if(!m_pTcpServer->listen(QHostAddress::Any,m_port))
{