15 #include "charinterface.h"
16 #include "xwavengraph.h"
21 #define strncasecmp strnicmp
25 XTDS::XTDS(
const char *name,
bool runtime,
26 Transaction &tr_meas,
const shared_ptr<XMeasure> &meas) :
29 for(
auto &&x: {trace1(), trace2(), trace3(), trace4()})
30 tr[ *x].add({
"CH1",
"CH2",
"CH3",
"CH4",
"MATH1",
"MATH2"});
31 for(
auto &&x: {vFullScale1(), vFullScale2(), vFullScale3(), vFullScale4()})
32 tr[ *x].add({
"0.02",
"0.05",
"0.1",
"0.2",
"0.5",
"1",
"2",
"5",
"10",
"20",
"50",
"100"});
33 tr[ *trigSource()].add({
"EXT",
"EXT10",
"CH1",
"CH2",
"CH3",
"CH4",
"LINE"});
36 interface()->setGPIBWaitBeforeWrite(20);
37 interface()->setGPIBWaitBeforeSPoll(10);
39 trans( *recordLength()) = 10000;
44 interface()->send(
"HEADER ON");
45 interface()->query(
"ACQ:STOPAFTER?");
47 if(interface()->scanf(
":ACQ%*s %9s", buf) != 1)
51 interface()->query(
"ACQ:MODE?");
52 if(interface()->scanf(
":ACQ%*s %9s", buf) != 1)
54 if( !strncmp(buf,
"AVE", 3)) {
55 interface()->query(
"ACQ:NUMAVG?");
57 if(interface()->scanf(
":ACQ%*s %d", &x) != 1)
61 if( !strncmp(buf,
"SAM", 3))
63 interface()->send(
"DATA:ENC RPB;WIDTH 2");
70 interface()->send(
"ACQ:MODE SAMPLE");
73 interface()->send(
"ACQ:MODE AVE;NUMAVG " + shot[ *
average()].to_str());
80 interface()->send(
"ACQ:STOPAFTER SEQUENCE;STATE ON");
83 interface()->send(
"ACQ:STOPAFTER RUNSTOP;STATE ON");
88 interface()->send(
"TRIG:A:EDG:SOU " + shot[ *trigSource()].to_str());
92 if(shot[ *trigPos()] >= 0)
93 interface()->sendf(
"HOR:DELAY:STATE OFF;TIME %.2g", (
double)shot[ *trigPos()]);
95 interface()->sendf(
"HOR:DELAY:STATE ON;TIME %.2g", -(shot[ *trigPos()] - 50.0) / 100.0 * (
double) ***timeWidth());
99 interface()->sendf(
"TRIG:A:EDG:LEV %g", (
double)shot[ *trigLevel()]);
103 interface()->sendf(
"TRIG:A:EDG:SLOP %s", (shot[ *trigFalling()] ?
"FALL" :
"RISE"));
107 interface()->sendf(
"HOR:MAIN:SCALE %.1g", (
double)shot[ *timeWidth()] / 10.0);
111 XString ch = ( **trace1())->to_str();
112 if(ch.empty())
return;
113 interface()->sendf(
"%s:SCALE %.1g", ch.c_str(), atof(shot[ *vFullScale1()].to_str().c_str()) / 10.0);
117 XString ch = ( **trace2())->to_str();
118 if(ch.empty())
return;
119 interface()->sendf(
"%s:SCALE %.1g", ch.c_str(), atof(shot[ *vFullScale2()].to_str().c_str()) / 10.0);
123 XString ch = ( **trace3())->to_str();
124 if(ch.empty())
return;
125 interface()->sendf(
"%s:SCALE %.1g", ch.c_str(), atof(shot[ *vFullScale3()].to_str().c_str())/10.0);
129 XString ch = ( **trace4())->to_str();
130 if(ch.empty())
return;
131 interface()->sendf(
"%s:SCALE %.1g", ch.c_str(), atof(shot[ *vFullScale4()].to_str().c_str())/10.0);
135 XString ch = ( **trace1())->to_str();
136 if(ch.empty())
return;
137 interface()->sendf(
"%s:OFFSET %.8g", ch.c_str(), (double)shot[ *vOffset1()]);
141 XString ch = ( **trace2())->to_str();
142 if(ch.empty())
return;
143 interface()->sendf(
"%s:OFFSET %.8g", ch.c_str(), (double)shot[ *vOffset2()]);
147 XString ch = ( **trace3())->to_str();
148 if(ch.empty())
return;
149 interface()->sendf(
"%s:OFFSET %.8g", ch.c_str(), (double)shot[ *vOffset3()]);
153 XString ch = ( **trace4())->to_str();
154 if(ch.empty())
return;
155 interface()->sendf(
"%s:OFFSET %.8g", ch.c_str(), (double)shot[ *vOffset4()]);
159 interface()->send(
"HOR:RECORD " +
160 shot[ *recordLength()].to_str());
164 interface()->send(
"TRIG FORC");
169 interface()->send(
"ACQ:STATE ON");
174 interface()->query(
"ACQ:NUMACQ?;:BUSY?");
177 if(interface()->scanf(
":ACQ%*s %d;:BUSY %d", &n, &busy) != 2)
184 XTDS::getTimeInterval() {
185 interface()->query(
"WFMP?");
186 const char *cp = strstr(&interface()->buffer()[0],
"XIN");
189 int ret = sscanf(cp,
"%*s %lf", &x);
199 for(std::deque<XString>::iterator it = channels.begin(); it != channels.end(); it++) {
200 int rsize = (2 * width + 1024);
201 interface()->sendf(
"DATA:SOURCE %s;START %u;STOP %u;:WAVF?",
202 (
const char *)it->c_str(),
204 interface()->receive(rsize);
205 writer->insert(writer->end(),
206 interface()->buffer().begin(), interface()->buffer().end());
212 double yin[256], yoff[256];
217 int size = reader.size();
218 std::vector<char> bufcpy(reader.data());
219 bufcpy.push_back(
'\0');
220 char *buf = &bufcpy[0];
227 if( *cp ==
':') cp++;
228 if( !strncasecmp(cp,
"XIN", 3))
229 sscanf(cp,
"%*s %lf", &xin);
230 if( !strncasecmp(cp,
"PT_O", 4))
231 sscanf(cp,
"%*s %d", &triggerpos);
232 if( !strncasecmp(cp,
"XZE", 3))
233 sscanf(cp,
"%*s %lf", &xoff);
234 if( !strncasecmp(cp,
"YMU", 3))
235 sscanf(cp,
"%*s %lf", &yin[ch_cnt - 1]);
236 if( !strncasecmp(cp,
"YOF", 3))
237 sscanf(cp,
"%*s %lf", &yoff[ch_cnt - 1]);
238 if( !strncasecmp(cp,
"NR_P", 4)) {
240 sscanf(cp,
"%*s %d", &width);
242 if( !strncasecmp(cp,
"CURV", 4)) {
244 cp = strchr(cp,
'#');
249 if(snprintf(fmt,
sizeof(fmt),
"#%%*1d%%%ud", x) < 0)
257 if( *cp !=
',')
break;
260 char *ncp = strchr(cp,
';');
262 cp = strchr(cp,
':');
271 xoff = -triggerpos * xin;
273 tr[ *
this].setParameters(ch_cnt, xoff, xin, width);
276 for(
int j = 0; j < ch_cnt; j++) {
277 double *wave = tr[ *
this].waveDisp(j);
278 cp = strchr(cp,
'#');
281 if(sscanf(cp,
"#%1d", &x) != 1)
break;
283 if(snprintf(fmt,
sizeof(fmt),
"#%%*1d%%%ud", x) < 0)
286 if(sscanf(cp, fmt, &yyy) != 1)
break;
291 for(; i < std::min(width, yyy/2); i++) {
292 double val = *((
unsigned char *)cp) * 0x100;
293 val += *((
unsigned char *)cp + 1);
294 *(wave++) = yin[j] * (val - yoff[j] - 0.5);
297 for(; i < width; i++) {