16#include "SampleAppsHelper.h"
22static const std::map<RSINetworkType, std::string> RSINetworkTypeMap = {
23 {RSINetworkType::RSINetworkTypeSTRING,
"RSINetworkTypeSTRING"},
24 {RSINetworkType::RSINetworkTypeDUAL_STRING,
"RSINetworkTypeDUAL_STRING"},
25 {RSINetworkType::RSINetworkTypeRING,
"RSINetworkTypeRING"}
29static const std::map<RSINetworkState, std::string> RSINetworkStateMap = {
30 {RSINetworkState::RSINetworkStateUNINITIALIZED,
"RSINetworkStateUNINITIALIZED"},
31 {RSINetworkState::RSINetworkStateDISCOVERING,
"RSINetworkStateDISCOVERING"},
32 {RSINetworkState::RSINetworkStateDISCOVERED,
"RSINetworkStateDISCOVERED"},
33 {RSINetworkState::RSINetworkStatePREOPERATIONAL,
"RSINetworkStatePREOPERATIONAL"},
34 {RSINetworkState::RSINetworkStateOPERATIONAL,
"RSINetworkStateOPERATIONAL"},
35 {RSINetworkState::RSINetworkStateERROR,
"RSINetworkStateERROR"},
36 {RSINetworkState::RSINetworkStateSHUTDOWN,
"RSINetworkStateSHUTDOWN"},
37 {RSINetworkState::RSINetworkStateSTARTING,
"RSINetworkStateSTARTING"}
43 static constexpr int DEVICE_TYPE_INDEX = 0x1000;
44 static constexpr int DEVICE_TYPE_SUB_INDEX = 0;
45 static constexpr int DEVICE_TYPE_BYTE_SIZE = 4;
49static std::vector<RapidCodeNetworkNode *> GetNodeList(
MotionController *controller)
51 std::vector<RapidCodeNetworkNode *> nodes;
58 throw std::runtime_error(
"Error creating the network node, it is null.");
63 throw std::runtime_error(
"The network node should exist after we get it.");
66 nodes.push_back(node);
72static std::string GetDeviceType(RapidCodeNetworkNode *node)
74 std::string deviceType =
"";
77 uint32_t deviceTypeValue =
78 node->ServiceChannelRead(MdpConstants::DEVICE_TYPE_INDEX, MdpConstants::DEVICE_TYPE_SUB_INDEX, MdpConstants::DEVICE_TYPE_BYTE_SIZE);
80 std::ostringstream deviceTypeStream;
81 deviceTypeStream <<
"0x" << std::uppercase << std::setfill(
'0') << std::setw(8) << std::hex << deviceTypeValue;
83 deviceType = deviceTypeStream.str();
85 catch (std::exception err)
87 deviceType =
"Exception trying to read device type";
93static std::string ReadNodeInfo(RapidCodeNetworkNode *node)
95 std::ostringstream nodeInfo;
98 nodeInfo <<
"Node[" << node->NumberGet() <<
"] - " << node->NameGet() <<
" ______________________________________________\n";
100 nodeInfo <<
" Vendor: " << node->VendorNameGet();
101 nodeInfo <<
" Product: " << node->ProductNameGet() <<
"\n";
103 nodeInfo <<
" VendorID: 0x" << std::hex << std::setw(8) << std::setfill(
'0') << node->VendorIdGet();
104 nodeInfo <<
" ProductCode: 0x" << std::setw(8) << node->ProductCodeGet() <<
"\n";
106 nodeInfo <<
" HardwareRev: 0x" << std::setw(8) << node->RevisionGet();
107 nodeInfo <<
" SerialNumber: " << node->SerialNumberGet() <<
"\n";
109 nodeInfo <<
" StationAlias: 0x" << std::setw(8) << node->StationAliasGet();
110 nodeInfo <<
" AxisCount: " << std::dec << node->AxisCountGet() <<
"\n";
112 nodeInfo <<
" DeviceType: " << GetDeviceType(node);
113 nodeInfo <<
" (For Mdp by reading SDO 0x" << std::hex << std::setw(4) << MdpConstants::DEVICE_TYPE_INDEX <<
")\n";
115 nodeInfo <<
" SegmentCount: " << node->SegmentCountGet() <<
"\n";
117 nodeInfo <<
" DI: " << node->DigitalInCountGet();
118 nodeInfo <<
" DO: " << node->DigitalOutCountGet();
119 nodeInfo <<
" AI: " << node->AnalogInCountGet();
120 nodeInfo <<
" AO: " << node->AnalogOutCountGet() <<
"\n";
122 return nodeInfo.str();
127 const std::string SAMPLE_APP_NAME =
"Utilities: Print Network Topology";
146 std::vector<RapidCodeNetworkNode *> nodes = GetNodeList(controller);
149 std::ostringstream topologyInfo;
152 topologyInfo <<
"EtherCAT: " << std::to_string(nodes.size());
153 topologyInfo <<
" Nodes, " << RSINetworkTypeMap.at(controller->
NetworkTypeGet());
154 topologyInfo <<
" " << RSINetworkStateMap.at(controller->
NetworkStateGet()) <<
"\n";
157 for (RapidCodeNetworkNode *node : nodes)
159 topologyInfo << ReadNodeInfo(node);
163 topologyInfo <<
"\nNetworkInputs count: " << controller->
NetworkInputCountGet() <<
" _________________________________\n";
166 topologyInfo <<
" [" << i <<
"] - " << std::setw(70) << controller->
NetworkInputNameGet(i);
171 topologyInfo <<
"NetworkOutputs count: " << controller->
NetworkOutputCountGet() <<
" _________________________________\n";
179 std::cout << topologyInfo.str() << std::endl;
183 catch (
const std::exception &ex)
185 std::cerr << ex.what() << std::endl;
NetworkNode * NetworkNodeGet(int32_t nodeNumber)
NetworkNodeGet returns a pointer to a RapidCodeNetworkNode object using its node number and initializ...
RSINetworkState NetworkStateGet()
int32_t NetworkNodeCountGet()
static MotionController * Create()
Initialize and start the RMP EtherCAT controller.
void Delete(void)
Delete the MotionController and all its objects.
int32_t NetworkOutputCountGet()
Represents the RMP soft motion controller. This class provides an interface to general controller con...
const char *const NetworkOutputNameGet(int32_t index)
Get the name of a PDO output.
int32_t NetworkOutputBitSizeGet(int32_t index)
Get the size (in bits) of a PDO output.
int32_t NetworkInputCountGet()
Get the number of PDO inputs found on the network.
int32_t NetworkInputBitSizeGet(int32_t index)
Get the size (in bits) of a network input.
RSINetworkType NetworkTypeGet()
Returns network type. (Currently only STRING type is supported.)
const char *const NetworkInputNameGet(int32_t index)
Get the name of a PDO network input.
static void PrintFooter(std::string sampleAppName, int exitCode)
Print a message to indicate the sample app has finished and if it was successful or not.
static void CheckErrors(RapidCodeObject *rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
static void PrintHeader(std::string sampleAppName)
Print a start message to indicate that the sample app has started.
static MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
CreationParameters for MotionController::Create.