From 0cd753d69ea08e3993ef5147702f40d66a3c4483 Mon Sep 17 00:00:00 2001 From: aschwinn <al.schwinn@gsi.de> Date: Fri, 12 May 2017 14:56:51 +0200 Subject: [PATCH] Bug 1201 - Add possibility to read out PLC run-state - automatically print runstate info in silecs-diagnostic-gui --- .../diagnostictoolmainview.cpp | 8 ++++- .../src/silecs-diagnostic/silecsmodule.cpp | 34 +++++++++++++++++++ .../src/silecs-diagnostic/silecsmodule.h | 2 ++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp b/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp index fb278da..b5adda8 100755 --- a/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp +++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp @@ -251,7 +251,10 @@ void diagnosticToolMainView::on_connectButton_clicked() Utils::displayPLCInformation(plc,ui->InformationMessage); //highlight PLC background in green - ui->treeWidget->currentItem()->setBackgroundColor(0,Qt::green); + currentItem->setBackgroundColor(0,Qt::green); + + //show the run-state of the PLC + mysilecs->updatePLCRunState(currentItem); // Increment number of connected PLC mysilecs->counterConnectedPLC++; @@ -284,6 +287,9 @@ void diagnosticToolMainView::on_disconnectButton_clicked() // Cast the linked object PLC type Silecs::PLC* plc = (Silecs::PLC*)(currentItem->getLinkedObject()); + //update the runstate + mysilecs->updatePLCRunState(currentItem); + // Disconnect plc->disconnect(); diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp b/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp index 5933ed4..41b1e81 100755 --- a/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp +++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp @@ -79,6 +79,39 @@ void silecsModule::enableDebugLog() debugLoggingEnabled_ = true; } +void silecsModule::updatePLCRunState(Item *plcItem) +{ + int index = 1; + try + { + Silecs::PLC* plc = (Silecs::PLC*)(plcItem->getLinkedObject()); + if( !plc->isConnected() ) + { + plcItem->setText(index,""); + plcItem->setBackgroundColor(index,Qt::white); + } + if( plc->isRunning() ) + { + plcItem->setText(index,"running"); + plcItem->setBackgroundColor(index,Qt::green); + } + else + { + plcItem->setText(index,"stopped"); + plcItem->setBackgroundColor(index,Qt::yellow); + } + } + catch(const Silecs::SilecsException& ex2) + { + plcItem->setText(index,"state unknown"); + plcItem->setBackgroundColor(index,Qt::red); + std::string message = "Failed to obtain plc run-state: "; + message += ex2.what(); + Utils::logError(messageConsole_,message); + } + +} + Item *silecsModule::generateTree(string className, string deployFile) { Item *root = NULL; @@ -912,6 +945,7 @@ void silecsModule::updateClusterItem(Item *Cluster,bool updateInputBufferOnly) void silecsModule::updatePLCItem(Item *PLCItem,bool updateInputBufferOnly) { + updatePLCRunState(PLCItem); Silecs::PLC* plc = (Silecs::PLC*)(PLCItem->getLinkedObject()); Utils::logInfo(messageConsole_,std::string("updating controller: '") + plc->getName() + "'"); int numberOfdevice = PLCItem->childCount(); diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.h b/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.h index 9e5a477..fea4e78 100755 --- a/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.h +++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.h @@ -68,6 +68,8 @@ public: */ ~silecsModule(); + void updatePLCRunState(Item *plcItem); + /** *Generate the empty entire tree */ -- GitLab