/* The "get_data" function has to cope with grabbing the data under a variety * of acquisition conditions. For data from channels 1-4 the general idea is to * ARM (single acquisition), WAIT, then *OPC? (OPeration Complete?). For data * from the maths channels (averaging) you tend to want the scope in norm mode, * issue a CLSW request then wait for the registers to indicate that averaging * has finished. Using a maths channel to take the average of a sequence (using * segmented memory) involves a combination of the two: issuing ARM and CLSW, * and checking that averaging has completed before grabbing the data. * The additional complication is that if you are grabbing data from more than * one channel, if you want the data to be synchronous, you must avoid issuing * either an ARM or a CLSW command. Hence the clear_sweeps and arm_and_wait * flag arguments. * * Summary of required settings (X = "don't care"): * Job | New acq? | Channel | clear_sweeps | arm_and_wait * ------------------------------------------------------------------------------------------- * Realtime acquisition | Yes | 1-4 | X | 1 * " " | No | 1-4 | X | 0 * Segmented acquisition | Yes | 1-4 | X | 1 * " " | No | 1-4 | X | 0 * Averages | Yes | A-D | 1 | 0 * " | No | A-D | 0 | 0 * Segmented averages | Yes | A-D | 1 | 1 * " " | No | A-D | 0 | 0 * */ long lecroy_get_data(VXI11_CLINK * clink, char chan, int clear_sweeps, char *buf, size_t buf_len, int arm_and_wait, unsigned long timeout) { char source[20]; long ret; int is_maths_chan; is_maths_chan = lecroy_is_maths_chan(chan); if ((is_maths_chan == 1) && (clear_sweeps == 1)) lecroy_clear_sweeps(clink); if (arm_and_wait == 1) vxi11_send_printf(clink, "ARM;WAIT"); if ((arm_and_wait == 1) || (is_maths_chan == 0)) { ret = vxi11_obtain_long_value_timeout(clink, "*OPC?", timeout); if (ret != 1) { printf ("lecroy_get_data: error, *OPC? did not return 1\n"); return 0; } } if ((is_maths_chan == 1) && (clear_sweeps == 1)) lecroy_wait_all_averages(clink, timeout); lecroy_scope_channel_str(chan, source); vxi11_send_printf(clink, "%s:WF? DAT1", source); return lecroy_receive_data_block(clink, buf, buf_len, timeout); }
int lecroy_wait_all_averages(VXI11_CLINK * clink, unsigned long timeout) { char cmd[256]; char buf[256]; int chan_on[4]; int mask; int l; int inr = 0; int old_inr = 0; int test = 0; /* Go through all maths channels, see if they're turned on or not */ for (l = 0; l < 4; l++) { sprintf(cmd, "F%d:TRACE?", l + 1); memset(buf, 0, 256); vxi11_send_and_receive(clink, cmd, buf, 256, timeout); if (strstr(buf, "ON") != NULL) { chan_on[l] = 1; } else { chan_on[l] = 0; } } /* Now investigate which maths channels (that are turned on) are averaging */ l = 0; while (l < 4) { if (chan_on[l] == 1) { sprintf(cmd, "F%d:DEF?", l + 1); memset(buf, 0, 256); vxi11_send_and_receive(clink, cmd, buf, 256, timeout); if (strstr(buf, "AVG") == NULL) { chan_on[l] = 0; } } l++; } /* make the appropriate mask */ mask = (chan_on[0] * 256) + (chan_on[1] * 512) + (chan_on[2] * 1024) + (chan_on[3] * 2048); while (test == 0) { inr = (int)vxi11_obtain_long_value_timeout(clink, "INR?", timeout); old_inr = old_inr | inr; if ((old_inr & mask) == mask) test = 1; else test = 0; } return 0; }
/* Lazy wrapper function with default read timeout */ long vxi11_obtain_long_value(CLINK *clink, const char *cmd) { return vxi11_obtain_long_value_timeout(clink, cmd, VXI11_READ_TIMEOUT); }