Skip to content
Snippets Groups Projects
Commit 27faa25b authored by Karol Krizka's avatar Karol Krizka Committed by Elisabetta Pianori
Browse files

SCPIPs: Check only first character of return string to ignore termination with CharDevCom.

parent aa5afec6
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <thread> #include <thread>
#include "Logger.h" #include "Logger.h"
#include "StringUtils.h"
//Register power supply //Register power supply
#include "PowerSupplyRegistry.h" #include "PowerSupplyRegistry.h"
...@@ -110,6 +111,7 @@ void SCPIPs::send(const std::string& cmd) ...@@ -110,6 +111,7 @@ void SCPIPs::send(const std::string& cmd)
{ {
m_com->send(cmd); m_com->send(cmd);
std::string opcreply=m_com->sendreceive("*OPC?"); std::string opcreply=m_com->sendreceive("*OPC?");
utils::rtrim(opcreply);
if(opcreply!="1") if(opcreply!="1")
throw std::runtime_error("SCPI command not completed"); throw std::runtime_error("SCPI command not completed");
} }
......
#ifndef STRINGUTILS_H
#define STRINGUTILS_H
#include <string>
#include <algorithm>
namespace utils
{
//
// Credit for trim functions: https://stackoverflow.com/a/217605
//! \brief Remove whitespaces from start of string
/**
* See std::isspace for definition of whitespace
*
* \param s String object from which to remove white space from
*/
static inline void ltrim(std::string &s)
{
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch)
{ return !std::isspace(ch); }
));
}
//! \brief Remove whitespaces from end of string
/**
* See std::isspace for definition of whitespace
*
* \param s String object from which to remove white space from
*/
static inline void rtrim(std::string &s)
{
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch)
{ return !std::isspace(ch); }
).base(), s.end());
}
//! \brief Remove whitespaces from both sides of a string
/**
* See std::isspace for definition of whitespace
*
* \param s String object from which to remove white space from
*/
static inline void trim(std::string &s)
{
ltrim(s);
rtrim(s);
}
};
#endif // STRINGUTILS_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment