Skip to content

Instantly share code, notes, and snippets.

@atimin
Last active February 7, 2020 01:42
Show Gist options
  • Save atimin/90d14dacf112e0131839e666e3493673 to your computer and use it in GitHub Desktop.
Save atimin/90d14dacf112e0131839e666e3493673 to your computer and use it in GitHub Desktop.
Read Logic Status and write Logic Command for PowerFlex 525
//
// Created by Aleksey Timin on 11/16/19.
//
#include <cstdlib>
#include <sstream>
#include <cip/connectionManager/NetworkConnectionParams.h>
#include "SessionInfo.h"
#include "MessageRouter.h"
#include "ConnectionManager.h"
#include "utils/Logger.h"
#include "utils/Buffer.h"
using namespace eipScanner::cip;
using eipScanner::SessionInfo;
using eipScanner::MessageRouter;
using eipScanner::ConnectionManager;
using eipScanner::cip::connectionManager::ConnectionParameters;
using eipScanner::cip::connectionManager::NetworkConnectionParams;
using eipScanner::utils::Buffer;
using eipScanner::utils::Logger;
using eipScanner::utils::LogLevel;
enum LogicStatuses {
};
int main() {
Logger::setLogLevel(LogLevel::DEBUG);
auto si = std::make_shared<SessionInfo>("172.28.1.3", 0xAF12);
auto messageRouter = std::make_shared<MessageRouter>();
// Read register
CipUint logicStatusId = 19;
auto response = messageRouter->sendRequest(si, ServiceCodes::GET_ATTRIBUTE_SINGLE,
EPath(0x07, logicStatusId, 4),
{});
if (response.getGeneralStatusCode() == GeneralStatusCodes::SUCCESS) {
Buffer buffer(response.getData());
CipUint reg;
buffer >> reg;
Logger(LogLevel::INFO) << "Read register #" << logicStatusId << " = 0x" << std::hex << reg;
} else {
Logger(LogLevel::ERROR) << "We got error=0x" << std::hex << response.getGeneralStatusCode();
}
// Clear faults
// See OpenEr EDS 160 line
Buffer command;
CipUint clearCommand = 0x8;
CipUint maskCommand = 0x8;
command << clearCommand << maskCommand;
CipUint logicCommandId = 13;
Logger(LogLevel::INFO) << "Write command #" << logicCommandId << " = 0x" << std::hex << clearCommand << " with mask "
<< maskCommand;
response = messageRouter->sendRequest(si, ServiceCodes::SET_ATTRIBUTE_SINGLE,
EPath(0x07, logicCommandId, 4),
command.data());
if (response.getGeneralStatusCode() == GeneralStatusCodes::SUCCESS) {
Logger(LogLevel::INFO) << "Writing is successful";
} else {
Logger(LogLevel::ERROR) << "We got error=0x" << std::hex << response.getGeneralStatusCode();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment