程序重启/刷新后页面状态与设备实际状态错配,导致按页面流程下发指令反馈错误。 新增 syncDeviceConfigOnce:连接建立进入远控后同步查询设备 OUTP/FUNC/FUNC:MODE 及各限值/设定值,以设备真实回读为准覆盖内存状态;设备输出仍为开时置 loadOn=true 并由 applyEnable 重新下发完整使能序列(接管恢复控制)。 - IT6000C 新增 7 个配置回读查询封装(CURR?/VOLT?/VOLT:LIM?/CURR:LIM?*2/POW:LIM?*2) - ELoad 实现 syncDeviceConfigOnce 并接入 doControlCycle(连接后自动,覆盖重连/复位/本控→远控) - 抽出 normFunc 辅助函数复用于 pollError;快照新增 cfgSynced/cfgSyncTime - 页面卡2 增加设备配置同步状态显示
135 lines
4.5 KiB
C++
135 lines
4.5 KiB
C++
#include "IT6000C.h"
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
|
|
namespace eload {
|
|
|
|
//============================================================================
|
|
// 基础
|
|
//============================================================================
|
|
|
|
bool IT6000C::identify(std::string& idn) {
|
|
return m_scpi.query("*IDN?", idn, 300);
|
|
}
|
|
|
|
bool IT6000C::remote() {
|
|
// 连接建立后必须先进入远控,否则设置命令被面板本地态拒绝。
|
|
// 用 cmdConfirmed 等待真实写入结果,明确反馈成功/失败。
|
|
return m_scpi.cmdConfirmed("SYST:REM", 300);
|
|
}
|
|
|
|
bool IT6000C::local() {
|
|
return m_scpi.cmdConfirmed("SYST:LOC", 300);
|
|
}
|
|
|
|
bool IT6000C::reset() {
|
|
return m_scpi.cmd("*RST");
|
|
}
|
|
|
|
bool IT6000C::clearStatus() {
|
|
return m_scpi.cmd("*CLS");
|
|
}
|
|
|
|
bool IT6000C::opComplete() {
|
|
std::string r;
|
|
return m_scpi.query("*OPC?", r, 300);
|
|
}
|
|
|
|
bool IT6000C::nextError(std::string& err) {
|
|
return m_scpi.query("SYST:ERR?", err, 200);
|
|
}
|
|
|
|
//============================================================================
|
|
// 输出
|
|
//============================================================================
|
|
|
|
bool IT6000C::output(bool on) {
|
|
return m_scpi.cmd(on ? "OUTP 1" : "OUTP 0");
|
|
}
|
|
|
|
bool IT6000C::queryOutput(bool& on) {
|
|
std::string r;
|
|
if (!m_scpi.query("OUTP?", r, 200)) return false;
|
|
on = (r.find("1") != std::string::npos);
|
|
return true;
|
|
}
|
|
|
|
bool IT6000C::clearProtection() {
|
|
return m_scpi.cmd("OUTP:PROT:CLE");
|
|
}
|
|
|
|
//============================================================================
|
|
// 工作模式
|
|
//============================================================================
|
|
|
|
bool IT6000C::setFunctionCC() {
|
|
return m_scpi.cmd("FUNC CURR");
|
|
}
|
|
|
|
bool IT6000C::setFunctionCV() {
|
|
return m_scpi.cmd("FUNC VOLT");
|
|
}
|
|
|
|
bool IT6000C::queryFunction(std::string& func) {
|
|
return m_scpi.query("FUNC?", func, 200);
|
|
}
|
|
|
|
bool IT6000C::setFunctionModeFixed() {
|
|
return m_scpi.cmd("FUNC:MODE FIX");
|
|
}
|
|
|
|
bool IT6000C::queryFunctionMode(std::string& mode) {
|
|
return m_scpi.query("FUNC:MODE?", mode, 200);
|
|
}
|
|
|
|
//============================================================================
|
|
// 设定值
|
|
//============================================================================
|
|
|
|
bool IT6000C::setDouble(const char* scpi, double v) {
|
|
char buf[64];
|
|
std::snprintf(buf, sizeof(buf), "%s %.6f", scpi, v);
|
|
return m_scpi.cmd(buf);
|
|
}
|
|
|
|
bool IT6000C::setCurrent(double amp) { return setDouble("CURR", amp); }
|
|
bool IT6000C::setVoltage(double volt) { return setDouble("VOLT", volt); }
|
|
bool IT6000C::setVoltageLimit(double volt){ return setDouble("VOLT:LIM", volt); }
|
|
bool IT6000C::setCurrentLimitPos(double amp) { return setDouble("CURR:LIM", amp); }
|
|
bool IT6000C::setCurrentLimitNeg(double amp) { return setDouble("CURR:LIM:NEG", amp); }
|
|
bool IT6000C::setPowerLimitPos(double watt) { return setDouble("POW:LIM", watt); }
|
|
bool IT6000C::setPowerLimitNeg(double watt) { return setDouble("POW:LIM:NEG", watt); }
|
|
|
|
bool IT6000C::queryCurrent(double& amp) { return queryDouble("CURR?", amp); }
|
|
bool IT6000C::queryVoltage(double& volt) { return queryDouble("VOLT?", volt); }
|
|
bool IT6000C::queryVoltageLimit(double& volt) { return queryDouble("VOLT:LIM?", volt); }
|
|
bool IT6000C::queryCurrentLimitPos(double& amp) { return queryDouble("CURR:LIM?", amp); }
|
|
bool IT6000C::queryCurrentLimitNeg(double& amp) { return queryDouble("CURR:LIM:NEG?", amp); }
|
|
bool IT6000C::queryPowerLimitPos(double& watt) { return queryDouble("POW:LIM?", watt); }
|
|
bool IT6000C::queryPowerLimitNeg(double& watt) { return queryDouble("POW:LIM:NEG?", watt); }
|
|
|
|
//============================================================================
|
|
// 测量
|
|
//============================================================================
|
|
|
|
bool IT6000C::queryDouble(const char* scpi, double& v) {
|
|
std::string r;
|
|
if (!m_scpi.query(scpi, r, 150)) return false;
|
|
if (r.empty()) return false;
|
|
char* end = nullptr;
|
|
double d = std::strtod(r.c_str(), &end);
|
|
if (end == r.c_str()) return false;
|
|
v = d;
|
|
return true;
|
|
}
|
|
|
|
bool IT6000C::measureVoltage(double& v) { return queryDouble("MEAS:VOLT?", v); }
|
|
bool IT6000C::measureCurrent(double& i) { return queryDouble("MEAS:CURR?", i); }
|
|
bool IT6000C::measurePower(double& p) { return queryDouble("MEAS:POW?", p); }
|
|
|
|
bool IT6000C::fetchVoltage(double& v) { return queryDouble("FETCh:VOLT?", v); }
|
|
bool IT6000C::fetchCurrent(double& i) { return queryDouble("FETCh:CURR?", i); }
|
|
bool IT6000C::fetchPower(double& p) { return queryDouble("FETCh:POW?", p); }
|
|
|
|
} // namespace eload
|