22 debug(
"MSOxxxx built.",
"MSOxxxx::MSOxxxx");
44 struct hostent *server;
45 struct sockaddr_in servAddr;
49 sockfd = socket(AF_INET, SOCK_STREAM, 0);
52 error(
"ERROR opening socket",
"MSOxxxx::open");
57 server = gethostbyname(
ipAddress.c_str());
60 error(
"No such host.",
"MSOxxxx::open");
65 bzero((
char *) &servAddr,
sizeof(servAddr));
66 servAddr.sin_family = AF_INET;
67 bcopy((
char *)server->h_addr, (
char *)&servAddr.sin_addr.s_addr, server->h_length);
70 if (connect(
sockfd,(
struct sockaddr *) &servAddr,
sizeof(servAddr)) < 0)
72 error(
"Connection could not be established.",
"MSOxxxx::open");
76 info(
"Connection established.",
"MSOxxxx::open");
86 info(msg,
"MSOxxxx::send");
88 int n = write(
sockfd,msg.c_str(),msg.length());
91 error(
"Socket write error.",
"MSOxxxx::send");
100 int nRead, nItems, buffPos=0;
109 if(
rxBuffer[buffPos-1] ==
'\n') endData =
true;
117 error(
"Socket read error.",
"MSOxxxx::recv");
124 nItems =
split(rxMsg,msgItems,spacer);
127 info(rxMsg,
"MSOxxxx::recv");
139 bool ok =
send(
":CHANNEL" +
itos(ch) +
":SCALE " +
ftos(value) +
"\n");
146 bool ok =
send(
":CHANNEL" +
itos(ch) +
":OFFSET " +
ftos(value) +
"\n");
155 ok =
send(
":CHANNEL" +
itos(ch) +
":DISPLAY ON \n");
157 ok =
send(
":CHANNEL" +
itos(ch) +
":DISPLAY OFF \n");
164 bool ok =
send(
":CHANNEL" +
itos(ch) +
":LABEL \"" + name +
"\" \n");
175 bool ok =
send(
":TIMEBASE:SCALE " +
ftos(secsPerDiv) +
" \n");
182 bool ok =
send(
":TIMEBASE:POSITION " +
ftos(seconds) +
" \n");
192 ok =
send(
":WAVeform:XINCrement?\n");
194 if(ok && nRxItems > 0)
196 *xInc = atof(
rxItems[0].c_str());
197 send(
":WAVeform:XORigin?\n");
200 if(ok && nRxItems > 0)
202 *xOrg = atof(
rxItems[0].c_str());
216 bool ok =
send(
":TRIGger:SWEep AUTO\n");
225 if(slope) ok =
send(
":TRIGger:EDGE:SLOpe POSitive\n");
226 else ok =
send(
":TRIGger:EDGE:SLOpe NEGative\n");
227 ok |=
send(
":TRIGger:EDGE:SOURce CHANnel" +
itos(ch) +
" \n");
228 ok |=
send(
":TRIGger:LEVel CHANnel" +
itos(ch) +
"," +
ftos(level) +
" \n");
242 ok =
send(
":MEASure:CLEar\n");
243 ok |=
send(
":SYSTem:HEADer OFF\n");
244 ok |=
send(
":MEASure:STATistics ON\n");
245 ok |=
send(
":MEASure:PERiod CHAnnel"+
itos(ch)+
"\n");
255 ok =
send(
":MEASure:CLEar\n");
256 ok |=
send(
":MEASure:DELTatime:DEFine RISing,1,MIDDle,RISing,"+
itos(edge)+
",MIDDle\n");
257 ok |=
send(
":MEASure:STATistics ON\n");
258 ok |=
send(
":MEASure:DELTatime CHANNel"+
itos(chA)+
",CHANNel"+
itos(chB)+
"\n");
268 ok =
send(
":MEASure:CLEar\n");
269 ok |=
send(
":SYSTem:HEADer OFF\n");
270 ok |=
send(
":MEASure:STATistics ON\n");
271 ok |=
send(
":MEASURE:VAVERAGE DISPLAY,CHANNEL"+
itos(ch)+
"\n");
279 PyObject* waveform = PyList_New(0);
280 double xOrigin, xIncrement;
281 int nRxItems, iItems;
285 ok |=
send(
":RUN \n");
286 ok |=
send(
":DIGitize CHANnel"+
itos(ch)+
"\n");
287 ok |=
send(
":CHANnel"+
itos(ch)+
":DISPlay ON\n");
288 ok |=
send(
":WAVeform:FORMat ASCii\n");
289 ok |=
send(
":WAVeform:BYTeorder LSBFirst\n");
290 ok |=
send(
":WAVeform:SOURce CHANnel"+
itos(ch)+
"\n");
291 ok |=
send(
":WAVeform:STReaming 1\n");
292 ok |=
send(
":WAVeform:DATA?\n");
295 ok |=
send(
":RUN \n");
299 for(iItems=0 ; iItems<nRxItems-1 ; iItems++)
303 PyList_Append(waveform, PyFloat_FromDouble(((
double)iItems * xIncrement) + xOrigin));
304 PyList_Append(waveform, PyFloat_FromDouble(atof(
rxItems[iItems].c_str())));
314 int nRxItems=7, nMeas=0;
315 PyObject* statistics = PyList_New(0);
318 while(ok && nRxItems == 7 && nMeas < nMinMeas)
321 ok |=
send(
":MEASure:Results?\n");
323 nMeas = (int) atof(
rxItems[6].c_str());
325 if(!ok || nRxItems != 7)
327 error(
"Malformed packet. Try it again!",
"MSOxxxx::getJitter");
331 PyList_Append(statistics, PyFloat_FromDouble(atof(
rxItems[2].c_str())));
332 PyList_Append(statistics, PyFloat_FromDouble(atof(
rxItems[3].c_str())));
333 PyList_Append(statistics, PyFloat_FromDouble(atof(
rxItems[4].c_str())));
334 PyList_Append(statistics, PyFloat_FromDouble(atof(
rxItems[5].c_str())));
359 ok =
send(
":DISPLAY:LABEL ON \n");
361 ok =
send(
":DISPLAY:LABEL OFF \n");
374 PyObject* idList = PyList_New(0);
376 ok =
send(
"*IDN? \n");
378 if(ok && nRxItems == 4)
380 info(
"Oscilloscope : " +
rxItems[0],
"MSOxxxx::id");
382 info(
"Serial Number: " +
rxItems[2],
"MSOxxxx::id");
384 for(
int i=0; i<4; i++)
385 PyList_Append(idList, PyString_FromString(
rxItems[i].c_str()));
392 bool ok =
send(
":RUN \n");
399 bool ok =
send(
":STOP \n");
407 unsigned int delimPos = str.find(delimiter);
410 while(delimPos != string::npos)
412 splitStr[nStrings++] = str.substr(0,delimPos);
413 str = str.substr(delimPos+1,string::npos);
414 delimPos = str.find(delimiter);
416 splitStr[nStrings++] = str;
422 std::ostringstream buffer;
423 buffer << std::setprecision(7) << std::scientific <<
f;
void info(std::string mymsg)
PyObject * getStatistics(int nMinMeas)
StatusCode triggerConfig(bool slope, int ch, double level)
int split(string str, string *splitStr, string delimiter)
StatusCode channelDisplay(int ch, bool display)
StatusCode channelScale(int ch, double value)
void setType(std::string type)
void error(std::string mymsg)
void setId(unsigned char id)
void debug(std::string mymsg)
StatusCode labelDisplay(bool display)
StatusCode setupAvgVoltage(int ch)
void configTCPIP(string ip, int port)
void msg(std::string mymsg)
StatusCode setupJitter(int ch)
StatusCode channelOffset(int ch, double value)
PyObject * waveformCapture(int ch)
bool getTimeBase(double *xInc, double *xOrg)
int recv(string *rxItems, string spacer)
#define DEFAULT_IP_ADDRESS
StatusCode setupDeltaTime(int chA, int chB, int edge)
StatusCode timeBaseOffset(double seconds)
StatusCode timeBaseScale(double secsPerDiv)
StatusCode channelDisplayName(int ch, string name)