diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp b/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp index fb278da22a31e373d07c647afcee539a0ad7d2d1..b5adda80fc9611acd8d4095e5fb4b1d69806dc39 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 5933ed465214458eea6227f0aa491e9667104675..41b1e810f83d5ba65bf199f4d900454b4896acef 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 9e5a47760364327115a3f4df34cad50c56439d16..fea4e78e1a042636c8fb7d20b4b1f6705a2cfc58 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 */