@@ -1,6 +1,6 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||
<!DOCTYPE QtCreatorProject> | <!DOCTYPE QtCreatorProject> | ||||
<!-- Written by QtCreator 4.11.1, 2025-08-07T20:13:11. --> | |||||
<!-- Written by QtCreator 4.11.1, 2025-08-08T13:01:33. --> | |||||
<qtcreator> | <qtcreator> | ||||
<data> | <data> | ||||
<variable>EnvironmentId</variable> | <variable>EnvironmentId</variable> | ||||
@@ -35,8 +35,8 @@ PLC::PLC(QWidget *parent) : | |||||
createComponents(); | createComponents(); | ||||
connect(ui->listWidget,&QListWidget::currentTextChanged,this,&PLC::onListwidgetCurrenttextchanged); | connect(ui->listWidget,&QListWidget::currentTextChanged,this,&PLC::onListwidgetCurrenttextchanged); | ||||
connect(ui->btn_insert,&QPushButton::clicked,this,&PLC::btnInsertClicked); | 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, | // connect(modbusManager, &ModbusManager::errorOccurred, | ||||
// this, &PLC::handleModbusError); | // this, &PLC::handleModbusError); | ||||
connect(ui->graphicsView, &MyGraphicsView::itemBoundToRegister, | connect(ui->graphicsView, &MyGraphicsView::itemBoundToRegister, | ||||
@@ -233,3 +233,27 @@ void PLC::btnInsertClicked() | |||||
Connection* c2 = new Connection(newItem, Item::Right, to, toType); | Connection* c2 = new Connection(newItem, Item::Right, to, toType); | ||||
ui->graphicsView->scene()->addItem(c2); | 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(); | |||||
} | |||||
} |
@@ -30,6 +30,12 @@ private slots: | |||||
void onListwidgetCurrenttextchanged(const QString ¤tText); | void onListwidgetCurrenttextchanged(const QString ¤tText); | ||||
void btnInsertClicked(); | void btnInsertClicked(); | ||||
void on_pushButton_clicked(); | |||||
void on_pushButton_2_clicked(); | |||||
void updateConnectionStatus(bool connection); | |||||
private: | private: | ||||
Ui::PLC *ui; | Ui::PLC *ui; | ||||
QGraphicsScene *plc_scene_; | QGraphicsScene *plc_scene_; | ||||
@@ -19,7 +19,7 @@ | |||||
<x>10</x> | <x>10</x> | ||||
<y>30</y> | <y>30</y> | ||||
<width>171</width> | <width>171</width> | ||||
<height>451</height> | |||||
<height>401</height> | |||||
</rect> | </rect> | ||||
</property> | </property> | ||||
</widget> | </widget> | ||||
@@ -29,7 +29,7 @@ | |||||
<x>200</x> | <x>200</x> | ||||
<y>30</y> | <y>30</y> | ||||
<width>761</width> | <width>761</width> | ||||
<height>451</height> | |||||
<height>401</height> | |||||
</rect> | </rect> | ||||
</property> | </property> | ||||
<property name="dragMode"> | <property name="dragMode"> | ||||
@@ -49,6 +49,42 @@ | |||||
<string>插入</string> | <string>插入</string> | ||||
</property> | </property> | ||||
</widget> | </widget> | ||||
<widget class="QTextEdit" name="textEdit"> | |||||
<property name="geometry"> | |||||
<rect> | |||||
<x>10</x> | |||||
<y>440</y> | |||||
<width>951</width> | |||||
<height>87</height> | |||||
</rect> | |||||
</property> | |||||
</widget> | |||||
<widget class="QPushButton" name="pushButton"> | |||||
<property name="geometry"> | |||||
<rect> | |||||
<x>120</x> | |||||
<y>0</y> | |||||
<width>93</width> | |||||
<height>28</height> | |||||
</rect> | |||||
</property> | |||||
<property name="text"> | |||||
<string>连接</string> | |||||
</property> | |||||
</widget> | |||||
<widget class="QPushButton" name="pushButton_2"> | |||||
<property name="geometry"> | |||||
<rect> | |||||
<x>230</x> | |||||
<y>0</y> | |||||
<width>93</width> | |||||
<height>28</height> | |||||
</rect> | |||||
</property> | |||||
<property name="text"> | |||||
<string>断开</string> | |||||
</property> | |||||
</widget> | |||||
</widget> | </widget> | ||||
<customwidgets> | <customwidgets> | ||||
<customwidget> | <customwidget> | ||||