ngscopeclient 0.1-dev+51fbda87c
KuaiquPowerSupply.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopehal *
4* *
5* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
36#ifndef KuaiquPowerSupply_h
37#define KuaiquPowerSupply_h
38
44 : public virtual SCPIPowerSupply
45 , public virtual SCPIInstrument
46{
47public:
49 virtual ~KuaiquPowerSupply();
50
51 //Device information
52 virtual uint32_t GetInstrumentTypesForChannel(size_t i) const override;
53
54 //Device capabilities
55 virtual bool SupportsIndividualOutputSwitching() override;
56 virtual bool SupportsVoltageCurrentControl(int chan) override;
57
58 //Read sensors
59 virtual double GetPowerVoltageActual(int chan) override; //actual voltage after current limiting
60 virtual double GetPowerVoltageNominal(int chan) override; //set point
61 virtual double GetPowerCurrentActual(int chan) override; //actual current drawn by the load
62 virtual double GetPowerCurrentNominal(int chan) override; //current limit
63 virtual bool GetPowerChannelActive(int chan) override;
64
65 //Configuration
66 virtual void SetPowerVoltage(int chan, double volts) override;
67 virtual void SetPowerCurrent(int chan, double amps) override;
68 virtual void SetPowerChannelActive(int chan, bool on) override;
69 virtual bool IsPowerConstantCurrent(int chan) override;
70
71protected:
72 enum Command : char {
73 COMMAND_WRITE_VOLTAGE= '1',
74 COMMAND_READ_VOLTAGE = '2',
75 COMMAND_WRITE_CURRENT= '3',
76 COMMAND_READ_CURRENT = '4',
77 COMMAND_KEYPAD_ECHO = '5',
78 COMMAND_FIRMWARE = '6',
79 COMMAND_ON = '7', // No reply to off command
80 COMMAND_OFF = '8', // No reply to on command
81 COMMAND_LOCK = '9',
82 COMMAND_LOCK_ON,
83 COMMAND_LOCK_OFF
84 };
85 // Make sure several request don't collide before we received the corresponding response
86 std::recursive_mutex m_transportMutex;
87 // Rate limiting as per documentation : 3.5 bytes at 9600 bauds = 3.5 * 1.04ms = 3.64ms => 4 ms
88 std::chrono::milliseconds m_rateLimitingInterval = std::chrono::milliseconds(4);
89 std::chrono::system_clock::time_point m_nextCommandReady = std::chrono::system_clock::now();
90
91
92 bool SendWriteValueCommand(Command command, double value);
93 double SendReadValueCommand(Command command);
94 std::string SendSimpleCommand(Command command);
95 std::string SendCommand(Command command, std::string commandString);
96
97 // PSU state
98 bool m_on = false;
99 double m_current = 0;
100 double m_voltage = 0;
101 bool m_constantCurrent = false;
102
103public:
104 static std::string GetDriverNameInternal();
105 POWER_INITPROC(KuaiquPowerSupply);
106};
107
108#endif
A KUAIQU power supply.
Definition: KuaiquPowerSupply.h:46
virtual bool SupportsVoltageCurrentControl(int chan) override
Determines if the power supply supports voltage/current control for the given channel.
Definition: KuaiquPowerSupply.cpp:212
KuaiquPowerSupply(SCPITransport *transport)
Initialize the driver.
Definition: KuaiquPowerSupply.cpp:49
static std::string GetDriverNameInternal()
Return the constant driver name strnig "kuaiqu_psu".
Definition: KuaiquPowerSupply.cpp:194
virtual bool SupportsIndividualOutputSwitching() override
Determines if the power supply supports switching individual output channels.
Definition: KuaiquPowerSupply.cpp:207
virtual uint32_t GetInstrumentTypesForChannel(size_t i) const override
Returns a bitfield describing the set of instrument types that a given channel supports.
Definition: KuaiquPowerSupply.cpp:199
An SCPI-based oscilloscope.
Definition: SCPIInstrument.h:38
An SCPI-based power supply.
Definition: SCPIPowerSupply.h:38
Abstraction of a transport layer for moving SCPI data between endpoints.
Definition: SCPITransport.h:47