diff --git a/src/libPS/IPowerSupply.cpp b/src/libPS/IPowerSupply.cpp index 8e933466805038dbc11cfd4d9a256112e97eb360..6099cf13a68e2909eff284d6f3b6af4467921ada 100644 --- a/src/libPS/IPowerSupply.cpp +++ b/src/libPS/IPowerSupply.cpp @@ -59,6 +59,21 @@ std::vector<std::string> IPowerSupply::getListOfModels() return m_models; } +void IPowerSupply::turnOnAll() +{ + logger(logWARNING) << "turnOnAll() not implemented for this PS."; +} + +void IPowerSupply::turnOffAll() +{ + logger(logWARNING) << "turnOffAll() not implemented for this PS."; +} + +bool IPowerSupply::isOn(unsigned channel) +{ + logger(logWARNING) << "isOn() not implemented for this PS."; +} + void IPowerSupply::setCurrentProtect(double cur, unsigned channel) { logger(logWARNING) << "setCurrentProtect() not implemented for this PS."; diff --git a/src/libPS/IPowerSupply.h b/src/libPS/IPowerSupply.h index dd9f21fbf082032304382824289a2cfe3fdfcfbc..41e68c02f48316b34c98901396e04a56a41b41d1 100644 --- a/src/libPS/IPowerSupply.h +++ b/src/libPS/IPowerSupply.h @@ -111,11 +111,23 @@ public: */ virtual void turnOn(unsigned channel = 0) = 0; + /** Turn on all channels of the power supply. + */ + virtual void turnOnAll(); + /** \brief Turn off power supply * @param channel channel, if any */ virtual void turnOff(unsigned channel = 0) = 0; + /** Turn off all channels of the power supply. + */ + virtual void turnOffAll(); + + /** Check whether an output channel is enabled. + */ + virtual bool isOn(unsigned channel = 0); + /** @} */ /** \name Current Control and Measurement diff --git a/src/libPS/Keithley24XX.cpp b/src/libPS/Keithley24XX.cpp index 71fea455152276ba8f8f9b3e4a5121bae7e88300..45dc61e4d5c25a670262f29c47ac1e36724049eb 100644 --- a/src/libPS/Keithley24XX.cpp +++ b/src/libPS/Keithley24XX.cpp @@ -48,8 +48,8 @@ void Keithley24XX::turnOff(unsigned channel) bool Keithley24XX::isOn(unsigned channel) { if (channel != 1) throw std::runtime_error("Set the channel to 1 for single channel power-supply"); - - return m_com->sendreceive(":OUTPUT?")=="1"; + // search for substring in case value is returned with a terminator + return m_com->sendreceive(":OUTPUT?").find("1") == 0; } std::string Keithley24XX::identify() diff --git a/src/libPS/PowerSupplyChannel.cpp b/src/libPS/PowerSupplyChannel.cpp index 61b69607454ed76d3bc676e46224119e85574279..3c1c94f10703f8487d310feb4fe57d30c487aeef 100644 --- a/src/libPS/PowerSupplyChannel.cpp +++ b/src/libPS/PowerSupplyChannel.cpp @@ -53,6 +53,9 @@ void PowerSupplyChannel::turnOn() void PowerSupplyChannel::turnOff() { m_ps->turnOff(m_channel); } +bool PowerSupplyChannel::isOn() +{ m_ps->isOn(m_channel); } + void PowerSupplyChannel::setCurrentLevel(double cur) { m_ps->setCurrentLevel(cur, m_channel); } diff --git a/src/libPS/PowerSupplyChannel.h b/src/libPS/PowerSupplyChannel.h index d1c3a071900fa9e18db88f43332c340b0339f0d5..76299b10128525adafbb29a52fc8ddbb7017f15a 100644 --- a/src/libPS/PowerSupplyChannel.h +++ b/src/libPS/PowerSupplyChannel.h @@ -67,6 +67,12 @@ public: * Warning: Not all power supplies support per-channel on/off control. */ void turnOff(); + + /** Check whether an output channel is enabled. + * + * Warning: Not all power supplies support per-channel on/off check. + */ + bool isOn(); /** @} */ diff --git a/src/libPS/TTIPs.cpp b/src/libPS/TTIPs.cpp index 300a267d737a473eaeb46cb991ebe8ab06aa9643..c5620550faf0eb20515cb5e49022effe3ed6a8e9 100644 --- a/src/libPS/TTIPs.cpp +++ b/src/libPS/TTIPs.cpp @@ -42,6 +42,11 @@ void TTIPs::turnOn(unsigned channel) m_com->send("OP"+std::to_string(channel)+" 1"); } +void TTIPs::turnOnAll() +{ + m_com->send("OPALL 1"); +} + void TTIPs::turnOff(unsigned channel) { if(channel<1 || channel > m_nchan) @@ -50,6 +55,19 @@ void TTIPs::turnOff(unsigned channel) m_com->send("OP"+std::to_string(channel)+" 0"); } +void TTIPs::turnOffAll() +{ + m_com->send("OPALL 0"); +} + +bool TTIPs::isOn(unsigned channel) +{ + if(channel<1 || channel > m_nchan) + throw std::runtime_error("Invalid channel: "+std::to_string(channel)); + // search for substring because value is returned with a <RESPONSE MESSAGE TERMINATOR> + return m_com->sendreceive("OP" + std::to_string(channel) + "?").find("1") == 0; +} + void TTIPs::setCurrentLevel(double cur, unsigned channel) { if(channel<1 || channel > m_nchan) diff --git a/src/libPS/TTIPs.h b/src/libPS/TTIPs.h index 2750e8a4418de7196ce68017e2d8cec41a2fa6ce..dde66fe9d541ab5bee3e077afb712be06f343324 100644 --- a/src/libPS/TTIPs.h +++ b/src/libPS/TTIPs.h @@ -36,7 +36,10 @@ public: virtual void reset(); virtual void turnOn(unsigned channel); + virtual void turnOnAll(); virtual void turnOff(unsigned channel); + virtual void turnOffAll(); + virtual bool isOn(unsigned channel); /** @} */ diff --git a/src/libPS/python.cpp b/src/libPS/python.cpp index a48089d05a6c908027a3c6bb41d7bb750d294264..05781384f0228844c0bfeac2c944344b7f9d7cf5 100755 --- a/src/libPS/python.cpp +++ b/src/libPS/python.cpp @@ -81,6 +81,13 @@ public: channel ); } + void turnOnAll() override { + PYBIND11_OVERLOAD_PURE( + void, + IPowerSupply, + turnOnAll, + ); + } void turnOff(unsigned channel = 0) override { PYBIND11_OVERLOAD_PURE( void, @@ -89,6 +96,21 @@ public: channel ); } + void turnOffAll() override { + PYBIND11_OVERLOAD_PURE( + void, + IPowerSupply, + turnOffAll, + ); + } + bool isOn(unsigned channel = 0) override { + PYBIND11_OVERLOAD_PURE( + bool, + IPowerSupply, + isOn, + channel + ); + } void setCurrentLevel(double cur, unsigned channel = 0) override { PYBIND11_OVERLOAD_PURE( void, @@ -320,8 +342,12 @@ void register_ps(py::module& m){ .def("identify", &IPowerSupply::identify) .def("turnOn", &IPowerSupply::turnOn, py::arg("channel") = 0) + .def("turnOnAll", &IPowerSupply::turnOnAll) .def("turnOff", &IPowerSupply::turnOff, py::arg("channel") = 0) + .def("turnOffAll", &IPowerSupply::turnOffAll) + .def("isOn", &IPowerSupply::isOn, + py::arg("channel") = 0) .def("setCurrentLevel", &IPowerSupply::setCurrentLevel, py::arg("current"), py::arg("channel") = 0) .def("getCurrentLevel", &IPowerSupply::getCurrentLevel, @@ -392,28 +418,31 @@ void register_ps(py::module& m){ .def(py::init<const std::string &>()); py::class_<Keithley24XX, PyPS<Keithley24XX>, IPowerSupply, std::shared_ptr<Keithley24XX>>(m, "Keithley24XX") - .def(py::init<const std::string &>()); - + .def(py::init<const std::string &>()) + .def("isOn", &Keithley24XX::isOn); py::class_<RS_HMPXXXX, SCPIPs, std::shared_ptr<RS_HMPXXXX>>(m, "RS_HMPXXXX") .def(py::init<const std::string &>()); - py::class_<RigolDP832, SCPIPs, std::shared_ptr<RigolDP832>>(m, "RigolDP832") .def(py::init<const std::string &>()); - py::class_<SorensenPs, PyPS<SorensenPs>, IPowerSupply, std::shared_ptr<SorensenPs>>(m, "SorensenPs") .def(py::init<const std::string &>()); + py::class_<TTIPs, PyPS<TTIPs>, IPowerSupply, std::shared_ptr<TTIPs>>(m, "TTIPs") + .def(py::init<const std::string &>()) + .def("turnOnAll", &TTIPs::turnOnAll) + .def("turnOffAll", &TTIPs::turnOffAll) + .def("isOn", &TTIPs::isOn); - py::class_<TTIXXXTPPs, PyPS<TTIXXXTPPs>, IPowerSupply, std::shared_ptr<TTIXXXTPPs>>(m, "TTIXXXTPPs") + py::class_<TTIXXXTPPs, PyPS<TTIXXXTPPs>, TTIPs, std::shared_ptr<TTIXXXTPPs>>(m, "TTIXXXTPPs") .def(py::init<const std::string &>()); - py::class_<TTIXXXDPPs, PyPS<TTIXXXDPPs>, IPowerSupply, std::shared_ptr<TTIXXXDPPs>>(m, "TTIXXXDPPs") + py::class_<TTIXXXDPPs, PyPS<TTIXXXDPPs>, TTIPs, std::shared_ptr<TTIXXXDPPs>>(m, "TTIXXXDPPs") .def(py::init<const std::string &>()); - py::class_<TTIXXXSPPs, PyPS<TTIXXXSPPs>, IPowerSupply, std::shared_ptr<TTIXXXSPPs>>(m, "TTIXXXSPPs") + py::class_<TTIXXXSPPs, PyPS<TTIXXXSPPs>, TTIPs, std::shared_ptr<TTIXXXSPPs>>(m, "TTIXXXSPPs") .def(py::init<const std::string &>()); py::class_<PowerSupplyChannel, std::shared_ptr<PowerSupplyChannel>>(m, "PowerSupplyChannel") @@ -425,6 +454,7 @@ void register_ps(py::module& m){ .def("program", &PowerSupplyChannel::program) .def("turnOn", &PowerSupplyChannel::turnOn) .def("turnOff", &PowerSupplyChannel::turnOff) + .def("isOn", &PowerSupplyChannel::isOn) .def("setCurrentLevel", &PowerSupplyChannel::setCurrentLevel) .def("getCurrentLevel", &PowerSupplyChannel::getCurrentLevel) .def("setCurrentProtect", &PowerSupplyChannel::setCurrentProtect)