Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

tektronix TDS6604 math curve

I am trying to read a math curve from Tektronix TDS6604 oscilloscope. It doesn't look like it's reading the actual data. Can you take a look at my program?
0 Kudos
Message 1 of 5
(3,616 Views)
When you say it doesn't look like it's reading the actual data, what kind of data do you get? Have you tried stepping through your code in a debugger to see where the failure is occuring? I read through your code, and overall it looked reasonable. I noticed that when you actually start pulling in the data and scaling it, you're doing a cast from each character to a double. Is the data actually coming back as a single byte per point? Also, you might consider using the %b scan specifier to read the binary data - this specifier recognizes the definite length block data format, and handles parsing the header information and determining how many bytes are in the buffer automatically. You can find more info about how to use it in the NI-VISA online reference. If yo
u can provide a little more info about the kind of curve data you expect to be getting and what you're actually getting, that would help in figuring out what's going wrong. Also, if you could give me an idea of the values you're seeing for the yOffset, yMult, and the actualy byte values, that would help too.

I noticed in this section:
// Read waveform into allocated storage
ptr = (double*) malloc(*elements*sizeof(double));
double e;

for (i = 0; i < *elements; i++) {
status = viScanf(*vi, "%c", &c);
if (status < VI_SUCCESS) goto error;
ptr[i] = (((double) c) - yoffset) * ymult;
}
0 Kudos
Message 2 of 5
(3,616 Views)
Hi
Thanks a lot for replying my question. First of all, here's the answers to your questions
1. The data that I get is displayed on a graph (on the computer). The graph doesn't look like what I see on the oscilloscope at all. The data displayed on the graph at the computer looks like a noise, but the data displayed at oscilloscope doesn't look like noise (I don't know how to describe that shape, it actally is an magnitude part of FFT of a square wave). The first element of the data on the oscilloscope is about -16.50, but at the computer side, the first element of data (ptr[0]) is -63. So I assume the data is wrong.
2. yoffset = 0
3. ymult = 1
4. some of the actual byte values are (at the for loop that you suggested me changing from %c to %b. If you lo
ok in the code I just attached, it's commented "scan char" and "double converted char")
- first element, c = -63 (='A') and ptr[0] is -63
- second element, c = -128 (='Ç')and ptr[1] is -128
5. There is not failure or error message when running or compiling the program, but I just can tell that the data read is wrong.

I tried replacing %c by %b as you suggested. It doesn't work. At the for loop that you typed above, I got status < VI_SUCCESS so it goes to error and no data is read.

Thank you
0 Kudos
Message 3 of 5
(3,616 Views)
sorry I forget to attached the code file. There's nothing different from the previous code that I attach except the comment about how much the yoffset, ymult,..is added.
0 Kudos
Message 4 of 5
(3,616 Views)
Irene,
typically if you expect a well-formed signal and you get what looks like noise, it's because the bytes representing the waveform are not being decoded correctly. I'm guessing your waveform on the computer is jumping around between -128 to 127. Values of ymult = 1 and yoffset = 0 means the data coming back is already scaled. So what I think we're missing is the data width and byte order information. Each byte can't represent one data point with those scaling values - you'd only get integer values out. This is where the %b modifier comes in really handy. If, for instance, you know that you have 1000 elements coming out in big-endian order and they're 8-byte floats, you can do something like this:
int elements = 1000;
double* wavef
orm = (double*)malloc(sizeof(double)*elements);
viQueryf(*vi, "CURVE?\n", "%#!obZb", &elements, waveform);
But first we need to determine the byte width and byte order. You should be able to find that information by querying the instrument, or by checking your instrument documentation.
0 Kudos
Message 5 of 5
(3,616 Views)