diff --git a/editor.pro.user b/editor.pro.user index 6933c03..916a4d0 100644 --- a/editor.pro.user +++ b/editor.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/plc.cpp b/plc.cpp index 1818534..3c978dc 100644 --- a/plc.cpp +++ b/plc.cpp @@ -35,8 +35,8 @@ PLC::PLC(QWidget *parent) : createComponents(); connect(ui->listWidget,&QListWidget::currentTextChanged,this,&PLC::onListwidgetCurrenttextchanged); connect(ui->btn_insert,&QPushButton::clicked,this,&PLC::btnInsertClicked); -// connect(modbusManager, &ModbusManager::connectionStatusChanged, -// this, &PLC::updateConnectionStatus); + connect(modbusManager, &ModbusManager::connectionStatusChanged, + this, &PLC::updateConnectionStatus); // connect(modbusManager, &ModbusManager::errorOccurred, // this, &PLC::handleModbusError); connect(ui->graphicsView, &MyGraphicsView::itemBoundToRegister, @@ -233,3 +233,27 @@ void PLC::btnInsertClicked() Connection* c2 = new Connection(newItem, Item::Right, to, toType); ui->graphicsView->scene()->addItem(c2); } + +void PLC::on_pushButton_clicked() +{ + modbusManager->connectToDevice("COM1",QSerialPort::BaudRate(9600),QSerialPort::DataBits(8),QSerialPort::EvenParity,QSerialPort::StopBits(1)); +} + +void PLC::on_pushButton_2_clicked() +{ + modbusManager->disconnectDevice(); +} + +void PLC::updateConnectionStatus(bool connection) +{ + if (connection) + { + ui->textEdit->append("连接"); + modbusManager->startSimulation(2000); + } + else + { + ui->textEdit->append("断开"); + modbusManager->stopSimulation(); + } +} diff --git a/plc.h b/plc.h index 906f8c0..99c7f7e 100644 --- a/plc.h +++ b/plc.h @@ -30,6 +30,12 @@ private slots: void onListwidgetCurrenttextchanged(const QString ¤tText); void btnInsertClicked(); + void on_pushButton_clicked(); + + void on_pushButton_2_clicked(); + + void updateConnectionStatus(bool connection); + private: Ui::PLC *ui; QGraphicsScene *plc_scene_; diff --git a/plc.ui b/plc.ui index 33a7d94..c595c9f 100644 --- a/plc.ui +++ b/plc.ui @@ -19,7 +19,7 @@ 10 30 171 - 451 + 401 @@ -29,7 +29,7 @@ 200 30 761 - 451 + 401 @@ -49,6 +49,42 @@ 插入 + + + + 10 + 440 + 951 + 87 + + + + + + + 120 + 0 + 93 + 28 + + + + 连接 + + + + + + 230 + 0 + 93 + 28 + + + + 断开 + +