Skip to content
Snippets Groups Projects
Commit ce6fd4ab authored by Elisabetta Pianori's avatar Elisabetta Pianori
Browse files

Merge branch 'kk_scipps-opc' into 'devel'

Add OPC to all SCIPPs commands.

See merge request !167
parents 604ac924 9f3d0bb2
No related branches found
No related tags found
2 merge requests!172Merge into master all DataSink developments,!167Add OPC to all SCIPPs commands.
Pipeline #2045756 passed
...@@ -21,7 +21,7 @@ bool SCPIPs::ping() ...@@ -21,7 +21,7 @@ bool SCPIPs::ping()
void SCPIPs::reset() void SCPIPs::reset()
{ {
m_com->send("*RST"); send("*RST");
if(!ping()) if(!ping())
throw std::runtime_error("No communication after reset."); throw std::runtime_error("No communication after reset.");
...@@ -35,14 +35,12 @@ std::string SCPIPs::identify() ...@@ -35,14 +35,12 @@ std::string SCPIPs::identify()
void SCPIPs::turnOn(unsigned channel) void SCPIPs::turnOn(unsigned channel)
{ {
setChannel(channel); send("OUTPUT ON", channel);
m_com->send("OUTPUT ON");
} }
void SCPIPs::turnOff(unsigned channel) void SCPIPs::turnOff(unsigned channel)
{ {
setChannel(channel); send("OUTPUT OFF", channel);
m_com->send("OUTPUT OFF");
} }
void SCPIPs::setChannel(unsigned channel) void SCPIPs::setChannel(unsigned channel)
...@@ -55,25 +53,22 @@ void SCPIPs::setChannel(unsigned channel) ...@@ -55,25 +53,22 @@ void SCPIPs::setChannel(unsigned channel)
if(m_maxChannels==1) return; // No need to change channel if(m_maxChannels==1) return; // No need to change channel
m_com->send("INST:NSEL " + std::to_string(channel)); send("INST:NSEL " + std::to_string(channel));
} }
void SCPIPs::setCurrentLevel(double cur, unsigned channel) void SCPIPs::setCurrentLevel(double cur, unsigned channel)
{ {
setChannel(channel); send("CURRENT " + std::to_string(cur), channel);
m_com->send("CURRENT " + std::to_string(cur));
} }
double SCPIPs::getCurrentLevel(unsigned channel) double SCPIPs::getCurrentLevel(unsigned channel)
{ {
setChannel(channel); return std::stod(sendreceive("CURRENT?", channel));
return std::stod(m_com->sendreceive("CURRENT?"));
} }
void SCPIPs::setCurrentProtect(double maxcur, unsigned channel) void SCPIPs::setCurrentProtect(double maxcur, unsigned channel)
{ {
setChannel(channel); send("CURRENT " + std::to_string(maxcur), channel);
m_com->send("CURRENT " + std::to_string(maxcur));
} }
double SCPIPs::getCurrentProtect(unsigned channel) double SCPIPs::getCurrentProtect(unsigned channel)
...@@ -83,26 +78,22 @@ double SCPIPs::getCurrentProtect(unsigned channel) ...@@ -83,26 +78,22 @@ double SCPIPs::getCurrentProtect(unsigned channel)
double SCPIPs::measureCurrent(unsigned channel) double SCPIPs::measureCurrent(unsigned channel)
{ {
setChannel(channel); return std::stod(sendreceive("MEAS:CURR?", channel));
return std::stod(m_com->sendreceive("MEAS:CURR?"));
} }
void SCPIPs::setVoltageLevel(double volt, unsigned channel) void SCPIPs::setVoltageLevel(double volt, unsigned channel)
{ {
setChannel(channel); send("VOLTAGE " + std::to_string(volt), channel);
m_com->send("VOLTAGE " + std::to_string(volt));
} }
double SCPIPs::getVoltageLevel(unsigned channel) double SCPIPs::getVoltageLevel(unsigned channel)
{ {
setChannel(channel); return std::stod(sendreceive("VOLTAGE?", channel));
return std::stod(m_com->sendreceive("VOLTAGE?"));
} }
void SCPIPs::setVoltageProtect(double maxvolt, unsigned channel) void SCPIPs::setVoltageProtect(double maxvolt, unsigned channel)
{ {
setChannel(channel); send("VOLTAGE " + std::to_string(maxvolt), channel);
m_com->send("VOLTAGE " + std::to_string(maxvolt));
} }
double SCPIPs::getVoltageProtect(unsigned channel) double SCPIPs::getVoltageProtect(unsigned channel)
...@@ -112,8 +103,46 @@ double SCPIPs::getVoltageProtect(unsigned channel) ...@@ -112,8 +103,46 @@ double SCPIPs::getVoltageProtect(unsigned channel)
double SCPIPs::measureVoltage(unsigned channel) double SCPIPs::measureVoltage(unsigned channel)
{ {
setChannel(channel); return std::stod(sendreceive("MEAS:VOLT?", channel));
return std::stod(m_com->sendreceive("MEAS:VOLT?")); }
void SCPIPs::send(const std::string& cmd)
{
m_com->send(cmd);
std::string opcreply=m_com->sendreceive("*OPC?");
if(opcreply!="1")
throw std::runtime_error("SCPI command not completed");
}
void SCPIPs::send(const std::string& cmd, unsigned channel)
{
if(m_maxChannels>0)
{ // In-range channel check
if(channel>m_maxChannels)
throw std::runtime_error("Invalid channel: "+std::to_string(channel));
} }
if(m_maxChannels!=1)
m_com->send("INST:NSEL "+std::to_string(channel));
send(cmd);
}
std::string SCPIPs::sendreceive(const std::string& cmd)
{
return m_com->sendreceive(cmd);
}
std::string SCPIPs::sendreceive(const std::string& cmd, unsigned channel)
{
if(m_maxChannels>0)
{ // In-range channel check
if(channel>m_maxChannels)
throw std::runtime_error("Invalid channel: "+std::to_string(channel));
}
if(m_maxChannels!=1)
m_com->send("INST:NSEL "+std::to_string(channel));
return sendreceive(cmd);
}
...@@ -91,6 +91,55 @@ public: ...@@ -91,6 +91,55 @@ public:
/** @} */ /** @} */
protected:
//\brief Send power supply command and wait for operation complete.
/**
* Sends `cmd` to the power supply followed up `*OPC?`. Then blocks until
* a response is received. This prevents the program from terminating
* before the program is processed.
*
* An error is thrown if no response to `*OPC?` is seen.
*
* \param cmd Power supply command to transmit.
*/
void send(const std::string& cmd);
//! \brief Add channel set to power supply send
/**
* Sends `":INST:NSEL "+channel` before the actual command. This is
* done without injecting `*OPC?`.
*
* The rest is achieved using `SCIPPs::send(constd std::string& cmd)`.
*
* \param cmd Power supply command to transmit.
* \param channel Target channel
*/
void send(const std::string& cmd, unsigned channel);
//\brief Send power supply command and return response.
/**
* Wrapper around `ICom::sendreceive`.
*
* \param cmd Power supply command to transmit.
*
* \return Parameter response.
*/
std::string sendreceive(const std::string& cmd);
//! \brief Add channel set to power supply sendreceive
/**
* Sends `":INST:NSEL "+channel` before the actual command. This is
* done without injecting `*OPC?`.
*
* The rest is achieved using `SCIPPs::sendreceive(constd std::string& cmd)`.
*
* \param cmd Power supply command to transmit.
* \param channel Target channel
*
* \return Response for `cmd`
*/
std::string sendreceive(const std::string& cmd, unsigned channel);
private: private:
/** PS limitations @{ */ /** PS limitations @{ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment