15 #include "charinterface.h"
16 #include "thamwayprot.h"
17 #include "ui_thamwayprotform.h"
20 REGISTER_TYPE(
XDriverList, ThamwayT300ImpedanceAnalyzer,
"Thamway T300-1049A Impedance Analyzer");
21 REGISTER_TYPE(
XDriverList, ThamwayCharPROT,
"Thamway PROT NMR.EXE TCP/IP Control");
23 REGISTER_TYPE(
XDriverList, ThamwayUSBPROT,
"Thamway PROT NMR USB Control");
24 XThamwayUSBPROT::XThamwayUSBPROT(
const char *name,
bool runtime,
26 interface()->setEOS(
"\r\n");
29 interface()->query(
"*IDN?");
30 fprintf(stderr,
"PROT:%s\n", interface()->toStr().c_str());
35 XThamwayCharPROT::XThamwayCharPROT(
const char *name,
bool runtime,
36 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas) :
38 trans( *this->interface()->port()) =
"127.0.0.1:5025";
39 trans( *this->interface()->device()) =
"TCP/IP";
40 this->interface()->setEOS(
"\n");
43 template <
class tInterface>
45 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas)
52 m_form->statusBar()->hide();
53 m_form->setWindowTitle(i18n(
"Thamway PROT Control - ") + this->
getLabel() );
55 m_form->m_dblOutput->setRange(0, 1023);
56 m_form->m_dblOutput->setSingleStep(1);
57 m_form->m_dblRXGain->setRange(0, 95);
58 m_form->m_dblRXGain->setSingleStep(2.0);
59 m_form->m_dblRXPhase->setRange(0, 360);
60 m_form->m_dblRXPhase->setSingleStep(1.0);
65 xqcon_create<XQToggleButtonConnector>(this->
rfON(), m_form->m_ckbRFON),
66 xqcon_create<XQDoubleSpinBoxConnector>(this->
oLevel(), m_form->m_dblOutput, m_form->m_slOutput),
67 xqcon_create<XQLineEditConnector>(this->
freq(), m_form->m_edFreq),
68 xqcon_create<XQDoubleSpinBoxConnector>(m_rxGain, m_form->m_dblRXGain, m_form->m_slRXGain),
69 xqcon_create<XQDoubleSpinBoxConnector>(m_rxPhase, m_form->m_dblRXPhase, m_form->m_slRXPhase),
70 xqcon_create<XQLineEditConnector>(m_rxLPFBW, m_form->m_edRXLPFBW)
72 this->
rfON()->setUIEnabled(
false);
73 this->
oLevel()->setUIEnabled(
false);
74 this->
freq()->setUIEnabled(
false);
75 this->
amON()->disable();
76 this->
fmON()->disable();
77 rxGain()->setUIEnabled(
false);
81 template <
class tInterface>
87 template <
class tInterface>
91 this->interface()->query(
"FREQR");
93 for(
int i = 0; ; ++i) {
94 if(this->interface()->scanf(
"FREQR%lf", &f) == 1)
98 this->interface()->receive();
100 this->interface()->query(
"ATT1R");
102 if(this->interface()->scanf(
"ATT1R%lf", &olevel) != 1)
105 this->interface()->query(
"GAINR");
107 if(this->interface()->scanf(
"GAINR%lf", &gain) != 1)
109 this->interface()->query(
"PHASR");
111 if(this->interface()->scanf(
"PHASR%lf", &phase) != 1)
113 this->interface()->query(
"LPF1R");
115 if(this->interface()->scanf(
"LPF1R%lf", &bw) != 1)
119 tr[ *this->freq()] = f;
120 tr[ *this->oLevel()] = olevel;
121 tr[ *this->rxGain()] = gain;
122 tr[ *this->rxPhase()] = phase;
123 tr[ *this->rxLPFBW()] = bw;
128 rxGain()->setUIEnabled(
true);
129 rxPhase()->setUIEnabled(
true);
130 rxLPFBW()->setUIEnabled(
true);
133 m_lsnRFON = tr[ *this->rfON()].onValueChanged().connectWeakly(
134 this->shared_from_this(), &XThamwayPROT::onRFONChanged);
135 m_lsnOLevel = tr[ *this->oLevel()].onValueChanged().connectWeakly(
136 this->shared_from_this(), &XThamwayPROT::onOLevelChanged);
137 m_lsnFreq = tr[ *this->freq()].onValueChanged().connectWeakly(
138 this->shared_from_this(), &XThamwayPROT::onFreqChanged);
139 m_lsnRXGain = tr[ *rxGain()].onValueChanged().connectWeakly(
141 m_lsnRXPhase = tr[ *rxPhase()].onValueChanged().connectWeakly(
142 this->shared_from_this(), &XThamwayPROT::onRXPhaseChanged);
143 m_lsnRXLPFBW = tr[ *rxLPFBW()].onValueChanged().connectWeakly(
144 this->shared_from_this(), &XThamwayPROT::onRXLPFBWChanged);
147 template <
class tInterface>
150 rxGain()->setUIEnabled(
false);
151 rxPhase()->setUIEnabled(
false);
152 rxLPFBW()->setUIEnabled(
false);
158 m_lsnRXPhase.reset();
159 m_lsnRXLPFBW.reset();
164 template <
class tInterface>
168 this->interface()->sendf(
"FREQW%010.6f", mhz);
171 template <
class tInterface>
174 this->interface()->sendf(
"RFSWW%s", shot[ *this->rfON()] ?
"1" :
"0");
176 template <
class tInterface>
179 int olevel = (int)shot[ *this->oLevel()];
180 olevel = std::min(1023, std::max(0, olevel));
181 this->interface()->sendf(
"ATT1W%04.0f", (
double)olevel);
183 template <
class tInterface>
186 double gain = shot[ *rxGain()];
187 gain = std::min(95.0, std::max(0.0, gain));
188 this->interface()->sendf(
"GAINW%02.0f", gain);
190 template <
class tInterface>
193 double phase = shot[ *rxPhase()];
194 phase -= floor(phase / 360.0) * 360.0;
195 this->interface()->sendf(
"PHASW%05.1f", phase);
197 template <
class tInterface>
200 double bw = shot[ *rxLPFBW()];
202 this->interface()->sendf(
"LPF1W%07.0f", bw * 1e3);
210 XThamwayT300ImpedanceAnalyzer::XThamwayT300ImpedanceAnalyzer(
const char *name,
bool runtime,
211 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas) :
213 interface()->setEOS(
"\r\n");
214 interface()->setSerialBaudRate(115200);
215 interface()->setSerialStopBits(1);
216 interface()->setSerialFlushBeforeWrite(
true);
217 trans( *interface()->device()) =
"SERIAL";
219 average()->disable();
221 calThru()->disable();
226 interface()->query(
"GET START?");
228 if(interface()->scanf(
"START %lf", &freq) != 1)
230 trans( *startFreq()) = freq;
231 interface()->query(
"GET STOP?");
232 if(interface()->scanf(
"STOP %lf", &freq) != 1)
234 trans( *stopFreq()) = freq;
235 unsigned int samples;
236 interface()->query(
"GET SAMPLE?");
237 if(interface()->scanf(
"SAMPLE %u", &samples) != 1)
239 trans( *points()) = samples;
242 interface()->send(
"LOG FORMAT");
248 interface()->sendf(
"SET START %f", (
double)shot[ *startFreq()]);
252 interface()->sendf(
"SET STOP %f", (
double)shot[ *stopFreq()]);
256 interface()->sendf(
"SET SAMPLE %u", (
unsigned int)shot[ *points()]);
260 interface()->query(
"CAL OPEN");
261 if(interface()->toStrSimplified() !=
"CAL OPEN DONE")
266 interface()->query(
"CAL SHORT");
267 if(interface()->toStrSimplified() !=
"CAL SHORT DONE")
272 interface()->query(
"CAL LOAD");
273 if(interface()->toStrSimplified() !=
"CAL LOAD DONE")
278 XThamwayT300ImpedanceAnalyzer::getMarkerPos(
unsigned int num,
double &x,
double &y) {
282 const auto trace = shot[ *
this].trace();
283 double v = (num == 0) ? 1e10 : -1.0;
285 for(
unsigned int i = 0; i < shot[ *
this].length(); i++) {
286 double z = std::norm( trace[i]);
300 x *= idx * shot[ *
this].freqInterval() + shot[ *
this].startFreq();
304 XThamwayT300ImpedanceAnalyzer::oneSweep() {
307 XThamwayT300ImpedanceAnalyzer::startContSweep() {
310 XThamwayT300ImpedanceAnalyzer::acquireTrace(shared_ptr<RawData> &writer,
unsigned int ch) {
313 interface()->query(
"MEAS ON");
314 if(interface()->scanf(
"LOG MAG,F=,M=,%u", &len) != 1)
316 writer->push((uint32_t)0);
318 for(
unsigned int i = 0; i < len; ++i) {
319 interface()->receive();
321 if(interface()->scanf(
"%f,%f", &freq, &) != 2)
330 uint32_t stype = reader.pop<uint32_t>();
331 uint32_t samples = reader.pop<uint32_t>();
336 throw XRecordError(i18n(
"Given format is not supported."), __FILE__, __LINE__);
339 tr[ *
this].trace_().resize(samples);
340 float startfreq = 0.0, stopfreq = 0.0;
341 for(
unsigned int i = 0; i < samples; i++) {
342 float freq = reader.pop<
float>();
347 tr[ *
this].trace_()[i] = pow(10.0, reader.pop<
float>() / 20.0);
349 tr[ *
this].m_startFreq = startfreq;
350 tr[ *
this].m_freqInterval = (stopfreq - startfreq) / (samples - 1);