14 #include "usernetworkanalyzer.h"
15 #include "charinterface.h"
17 REGISTER_TYPE(
XDriverList, HP8711,
"HP/Agilent 8711/8712/8713/8714 Network Analyzer");
18 REGISTER_TYPE(
XDriverList, AgilentE5061,
"Agilent E5061/E5062 Network Analyzer");
19 REGISTER_TYPE(
XDriverList, VNWA3ENetworkAnalyzer,
"DG8SAQ VNWA3E/Custom Network Analyzer");
22 XAgilentNetworkAnalyzer::XAgilentNetworkAnalyzer(
const char *name,
bool runtime,
23 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas) :
26 tr[ *points()].add({
"3",
"5",
"11",
"21",
"51",
"101",
"201",
"401",
"801",
"1601"});
30 calShort()->disable();
34 interface()->setGPIBWaitBeforeRead(10);
35 interface()->setGPIBWaitBeforeWrite(10);
40 interface()->query(
"SENS:FREQ:START?");
41 trans( *startFreq()) = interface()->toDouble() / 1e6;
42 interface()->query(
"SENS:FREQ:STOP?");
43 trans( *stopFreq()) = interface()->toDouble() / 1e6;
44 interface()->query(
"SENS:AVER:STAT?");
45 if(interface()->toUInt() == 0) {
46 trans( *average()) = 1;
49 interface()->query(
"SENS:AVER:COUNT?");
50 trans( *average()) = interface()->toUInt();
52 interface()->query(
"SENS:SWE:POIN?");
53 trans( *points()).str(formatString(
"%u", interface()->toUInt()));
54 interface()->send(
"SENS:SWE:TIME:AUTO OFF");
55 interface()->query(
"SENS:SWE:TIME?");
56 double swet = interface()->toDouble();
57 interface()->sendf(
":SENS:SWE:TIME %f S", std::min(1.0, std::max(0.3, swet)));
58 interface()->send(
"ABOR;INIT:CONT OFF");
64 interface()->sendf(
"SENS:FREQ:START %f MHZ", (
double)shot[ *startFreq()]);
68 interface()->sendf(
"SENS:FREQ:STOP %f MHZ", (
double)shot[ *stopFreq()]);
72 unsigned int avg = shot[ *average()];
74 interface()->sendf(
"SENS:AVER:CLEAR;STAT ON;COUNT %u", avg);
76 interface()->send(
"SENS:AVER:STAT OFF");
80 interface()->sendf(
"SENS:SWE:POIN %s", shot[ *points()].to_str().c_str());
83 XAgilentNetworkAnalyzer::getMarkerPos(
unsigned int num,
double &x,
double &y) {
87 interface()->queryf(
"CALC:MARK%u:STAT?", num + 1u);
88 if(interface()->toInt() != 1)
90 interface()->queryf(
"CALC:MARK%u:X?", num + 1u);
91 x = interface()->toDouble() / 1e6;
92 interface()->queryf(
"CALC:MARK%u:Y?", num + 1u);
93 y = interface()->toDouble();
96 XAgilentNetworkAnalyzer::oneSweep() {
97 interface()->query(
"INIT:IMM;*OPC?");
100 XAgilentNetworkAnalyzer::startContSweep() {
101 interface()->send(
"INIT:CONT ON");
104 XAgilentNetworkAnalyzer::acquireTrace(shared_ptr<RawData> &writer,
unsigned int ch) {
108 interface()->queryf(
"SENS%u:FREQ:START?", ch + 1u);
109 double start = interface()->toDouble() / 1e6;
111 interface()->queryf(
"SENS%u:FREQ:STOP?", ch + 1u);
112 double stop = interface()->toDouble() / 1e6;
114 interface()->queryf(
"SENS%u:SWE:POIN?", ch + 1u);
115 uint32_t len = interface()->toUInt();
117 acquireTraceData(ch, len);
118 writer->insert(writer->end(),
119 interface()->buffer().begin(), interface()->buffer().end());
123 double start = reader.pop<
double>();
124 double stop = reader.pop<
double>();
125 unsigned int samples = reader.pop<uint32_t>();
126 tr[ *
this].m_startFreq =
start;
127 char c = reader.pop<
char>();
130 buf[0] = reader.pop<
char>();
132 sscanf(buf,
"%1u", &len);
133 for(
unsigned int i = 0; i < len; i++) {
134 buf[i] = reader.pop<
char>();
137 sscanf(buf,
"%u", &len);
138 tr[ *
this].m_freqInterval = (stop -
start) / (samples - 1);
139 tr[ *
this].trace_().resize(samples);
141 convertRawBlock(reader, tr, len);
146 interface()->send(
"FORM:DATA REAL,32;BORD SWAP");
147 interface()->sendf(
"TRAC? CH%uFDATA", ch + 1u);
148 interface()->receive(len *
sizeof(
float) + 12);
152 XHP8711::convertRawBlock(RawDataReader &reader,
Transaction &tr,
153 unsigned int len)
throw (XRecordError&) {
154 unsigned int samples = tr[ *
this].trace_().size();
155 if(len /
sizeof(
float) < samples)
156 throw XBufferUnderflowRecordError(__FILE__, __LINE__);
157 if(len /
sizeof(
float) > samples)
158 throw XRecordError(i18n(
"Select scalar plot."), __FILE__, __LINE__);
159 for(
unsigned int i = 0; i < samples; i++) {
160 tr[ *
this].trace_()[i] = pow(10.0, reader.pop<
float>() / 20.0);
165 XAgilentE5061::acquireTraceData(
unsigned int ch,
unsigned int len) {
166 interface()->send(
"FORM:DATA REAL32;BORD SWAP");
167 interface()->sendf(
"CALC%u:FORM SCOMPLEX", ch + 1u);
168 interface()->sendf(
"CALC%u:DATA:FDAT?", ch + 1u);
169 interface()->receive(len *
sizeof(
float) * 2 + 12);
172 XAgilentE5061::convertRawBlock(RawDataReader &reader,
Transaction &tr,
173 unsigned int len)
throw (XRecordError&) {
174 unsigned int samples = tr[ *
this].trace_().size();
175 if(len /
sizeof(
float) < samples * 2)
176 throw XBufferUnderflowRecordError(__FILE__, __LINE__);
177 for(
unsigned int i = 0; i < samples; i++) {
178 tr[ *
this].trace_()[i] = std::complex<double>(
179 reader.pop<
float>(), reader.pop<
float>());
183 XVNWA3ENetworkAnalyzer::XVNWA3ENetworkAnalyzer(
const char *name,
bool runtime,
184 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas) :
186 interface()->setEOS(
"\n");
187 trans( *interface()->device()) =
"TCP/IP";
188 trans( *interface()->port()) =
"127.0.0.1:12333";
190 average()->disable();
193 calOpen()->disable();
194 calShort()->disable();
195 calTerm()->disable();
196 calThru()->disable();
205 interface()->sendf(
"FSTART %f", (
double)shot[ *startFreq()] * 1e6);
209 interface()->sendf(
"FSTOP %f", (
double)shot[ *stopFreq()] * 1e6);
212 XVNWA3ENetworkAnalyzer::getMarkerPos(
unsigned int num,
double &x,
double &y) {
215 interface()->queryf(
"MARK%u?", num);
216 if(interface()->scanf(
"MARK %*u %lf %lf", &x, &y) != 2)
222 XVNWA3ENetworkAnalyzer::oneSweep() {
224 interface()->query(
"ACQNUM?");
225 if(interface()->scanf(
"ACQNUM %u", &num) != 1)
231 XVNWA3ENetworkAnalyzer::startContSweep() {
234 XVNWA3ENetworkAnalyzer::acquireTrace(shared_ptr<RawData> &writer,
unsigned int ch) {
237 interface()->query(
"DATA?");
238 if(interface()->scanf(
"DATA %u", &len) != 1)
240 interface()->receive(len);
241 writer->insert(writer->end(),
242 interface()->buffer().begin(), interface()->buffer().end());
247 uint32_t hsize = reader.pop<uint32_t>();
248 int stype = reader.pop<int32_t>();
249 double start = reader.pop<
double>() * 1e-6;
250 double stop = reader.pop<
double>() * 1e-6;
251 int samples = reader.pop<int32_t>();
252 int rec = reader.pop<int32_t>();
253 double tm = reader.pop<
double>();
254 double temp = reader.pop<
double>();
255 for(
int cnt = 0; cnt < hsize - 48; ++cnt)
258 double df = (stop -
start) / (samples - 1);
259 tr[ *
this].m_startFreq =
start;
260 tr[ *
this].m_freqInterval = df;
261 tr[ *
this].trace_().resize(samples);
269 throw XRecordError(i18n(
"Log/Listed sweep is not supported."), __FILE__, __LINE__);
279 throw XRecordError(i18n(
"Select one of record."), __FILE__, __LINE__);
282 for(
unsigned int i = 0; i < samples; i++) {
283 tr[ *
this].trace_()[i] = std::complex<double>(reader.pop<
double>(), reader.pop<
double>());