Skip to content
Snippets Groups Projects
Commit 8da90d7e authored by al.schwinn's avatar al.schwinn
Browse files

Bug 1387 - Provide Command-Line Silecs Client

- added connect method
- improved graphics
- cout runState
parent 8dc0cbc0
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <stdio.h> #include <stdio.h>
#include <getopt.h> #include <getopt.h>
#include <iostream> #include <iostream>
#include <iomanip> // std::right, etc
#include <unistd.h>//usleep #include <unistd.h>//usleep
#include <silecs-communication/interface/utility/XMLParser.h> #include <silecs-communication/interface/utility/XMLParser.h>
...@@ -38,6 +39,7 @@ std::string arg_deviceName = ""; ...@@ -38,6 +39,7 @@ std::string arg_deviceName = "";
std::string arg_blockName = ""; std::string arg_blockName = "";
std::string arg_registerName = ""; std::string arg_registerName = "";
bool arg_silent = false; bool arg_silent = false;
bool arg_checkChecksum = true;
ModeType arg_mode = UNDEFINED; ModeType arg_mode = UNDEFINED;
uint32_t periodicInterval = 0; uint32_t periodicInterval = 0;
...@@ -55,6 +57,7 @@ void printHelp() ...@@ -55,6 +57,7 @@ void printHelp()
std::cout << startbold << "DESCRIPTION" << endbold << std::endl; std::cout << startbold << "DESCRIPTION" << endbold << std::endl;
std::cout << "\t Connect to a PLC and get/set values by using the Silecs-framework." << std::endl; std::cout << "\t Connect to a PLC and get/set values by using the Silecs-framework." << std::endl;
std::cout << startbold << "\t-b " << endbold << "silecs-block to get" << std::endl; std::cout << startbold << "\t-b " << endbold << "silecs-block to get" << std::endl;
std::cout << startbold << "\t-c " << endbold << "ignore silecs-checksum, force connect to PLC" << std::endl;
std::cout << startbold << "\t-d " << endbold << "silecs-device to request" << std::endl; std::cout << startbold << "\t-d " << endbold << "silecs-device to request" << std::endl;
std::cout << startbold << "\t-f " << endbold << "path to silecs-parameter-file of the plc" << std::endl; std::cout << startbold << "\t-f " << endbold << "path to silecs-parameter-file of the plc" << std::endl;
std::cout << startbold << "\t-h " << endbold << "print this help" << std::endl; std::cout << startbold << "\t-h " << endbold << "print this help" << std::endl;
...@@ -140,8 +143,19 @@ std::string getRegisterValueAsString(Silecs::Register* reg ) ...@@ -140,8 +143,19 @@ std::string getRegisterValueAsString(Silecs::Register* reg )
void printTableHead() void printTableHead()
{ {
std::cout << "|\tDevice\t\t|\tBlock\t\t|\tRegister\t|\tValue\t\t|" << std::endl; std::cout << "------------------------------------------------------------------------------------------------------------------------------------------------" << std::endl;
std::cout << "-------------------------------------------------------------------------------------------------------------------------" << std::endl; std::cout << "| "<< std::setw(20) << std::left << "Device" << "| " << std::setw(30) << std::left << "Block" << "| " << std::setw(50) << std::left << "Register" << "| " << std::setw(30) << std::left<< "Value" << "|" << std::endl;
std::cout << "------------------------------------------------------------------------------------------------------------------------------------------------" << std::endl;
}
void printRunState(Silecs::PLC *plc)
{
std::cout << "------------------------------------------------------------------------------------------------------------------------------------------------" << std::endl;
if( plc->isRunning() )
std::cout << "plc run-state is: RUNNING" << std::endl;
else
std::cout << "plc run-state is: STOPPED" << std::endl;
std::cout << "------------------------------------------------------------------------------------------------------------------------------------------------" << std::endl;
} }
void printRegister(Silecs::Device *device, Silecs::Register* reg ) void printRegister(Silecs::Device *device, Silecs::Register* reg )
...@@ -152,7 +166,7 @@ void printRegister(Silecs::Device *device, Silecs::Register* reg ) ...@@ -152,7 +166,7 @@ void printRegister(Silecs::Device *device, Silecs::Register* reg )
} }
else else
{ {
std::cout << "|\t" << device->getLabel() << "\t|\t" << reg->getBlockName() << "\t|\t" << reg->getName() << "\t|\t" << getRegisterValueAsString(reg) << "\t|" << std::endl; std::cout << "| " << std::setw(20) << std::left << device->getLabel() << "| " << std::setw(30) << std::left << reg->getBlockName() << "| " << std::setw(50) << std::left << reg->getName() << "| " << std::setw(30) << std::left << getRegisterValueAsString(reg) << "|" << std::endl;
} }
} }
...@@ -184,7 +198,6 @@ void printDevice(Silecs::Device *device, Silecs::XMLParser &paramParser) ...@@ -184,7 +198,6 @@ void printDevice(Silecs::Device *device, Silecs::XMLParser &paramParser)
printRegister(device, *reg); printRegister(device, *reg);
} }
} }
} }
void setRegister(Silecs::Register* reg,std::string value) void setRegister(Silecs::Register* reg,std::string value)
...@@ -208,6 +221,13 @@ int connectNonInteractive(Silecs::Service *service, Silecs::XMLParser &paramPars ...@@ -208,6 +221,13 @@ int connectNonInteractive(Silecs::Service *service, Silecs::XMLParser &paramPars
{ {
Silecs::Cluster *silecsCluster = getSilecsClusterbyDevice(arg_deviceName, paramParser, service); Silecs::Cluster *silecsCluster = getSilecsClusterbyDevice(arg_deviceName, paramParser, service);
Silecs::PLC *plc = silecsCluster->getPLC(getPLCName(paramParser),arg_parameterFile); Silecs::PLC *plc = silecsCluster->getPLC(getPLCName(paramParser),arg_parameterFile);
plc->connect(Silecs::MASTER_SYNCHRO,true,arg_checkChecksum);
if(!plc->isConnected())
{
std::cout << "Error: Failed to connect to PLC."<< std::endl;
return EXIT_FAILURE;
}
printRunState(plc);
Silecs::Device *device = plc->getDevice(arg_deviceName); Silecs::Device *device = plc->getDevice(arg_deviceName);
Silecs::Register* reg = NULL; Silecs::Register* reg = NULL;
...@@ -260,11 +280,14 @@ int main(int argc, char **argv) ...@@ -260,11 +280,14 @@ int main(int argc, char **argv)
bool interactiveOptionSet = false; bool interactiveOptionSet = false;
bool periodicOptionSet = false; bool periodicOptionSet = false;
while ((opt = getopt(argc, argv, ":l:hp:r:b:d:f:m:is")) != -1) while ((opt = getopt(argc, argv, ":l:hcp:r:b:d:f:m:is")) != -1)
{ {
switch (opt) switch (opt)
{ {
case 'c':
arg_checkChecksum = false;
break;
case 'h': case 'h':
printHelp(); printHelp();
return EXIT_SUCCESS; return EXIT_SUCCESS;
...@@ -396,15 +419,15 @@ int main(int argc, char **argv) ...@@ -396,15 +419,15 @@ int main(int argc, char **argv)
} }
catch(std::string *str) catch(std::string *str)
{ {
std::cout << str; std::cout << str << std::endl;
} }
catch(std::exception& ex) catch(std::exception& ex)
{ {
std::cout << ex.what(); std::cout << ex.what() << std::endl;
} }
catch(...) catch(...)
{ {
std::cout << "Unexpected error caught in Main. Please notify SILECS support"; std::cout << "Unexpected error caught in Main. Please notify SILECS support" << std::endl;
} }
return -1; return -1;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment