Fluke PM-3370B Sander User Manual


 
USING THE COMBISCOPE INSTRUMENTS 3 - 33
3.4.3.2 Conversion of 16-bit samples to integer
As an example a conversion of a trace of 512 "16-bit" samples is shown. The
format is as follows:
PROGRAM EXAMPLE:
In this example a trace acquisition of 2 byte samples is done. Thereafter, the trace
data is read and converted to integer samples in the array "trace", and the number
of trace bytes samples is printed. The conversion from double byte (byte1 = msb
and byte2 = lsb) to integer is done as follows (refer to figure 3.12):
If byte1 < 128 then integer = byte1
*
256 + byte2.
If byte1
128 then integer = (byte1 - 256)
*
256 + byte2.
Example: byte1 = 255 & byte2 = 32 --> integer = (255 - 256)
*
256 + 32 = - 224.
DIM trace(512)
Arra
y of 512 i
ntegers
DIM response AS STRING
*
1033
Trace response buffer
CALL Send(0, 8, "
*
RST", 1)
Resets the instrument
Sets 16 bit sample data format
CALL Send(0, 8, "INITiate", 1)
Single shot initiation
CALL Send(0, 8, "
*
WAI;TRACe? CH1", 1)
Queries for channel 1 trace
CALL Receive(0, 8, response$, 256)
Reads the channel 1 trace
PRINT "Number of trace bytes ="; IBCNT%
IBCNT% = length of trace buffer
The contents of the response$ string of this example will be as follows:
# 4 1 0 2 6 <16> <msb1> <lsb1> ... <msb512> <lsb512> <sum> <10>
nr.of.digits = VAL(MID$(response$, 2, 1))
nr.of.bytes = VAL(MID$(response$, 3, nr.of.digits)) - 2
PRINT "Number of trace bytes ="; nr.of.bytes
sample.length = ASC(MID$(response$, 3 + nr.of.digits, 1))
nr.of.samples = nr.of.bytes / (sample.length / 8)
PRINT "Number of trace samples ="; nr.of.samples
FOR i = 1 TO nr.of.samples
J = 2
*
i + 2 + nr.of.digits
Pointer to next sample
byte1 = ASC(MID$(response$, J, 1))
Most Significant Byte
byte2 = ASC(MID$(response$, J + 1, 1))
Least Significant Byte
IF byte1 < 128 THEN
trace(i) = byte1
*
256 + byte2
ELSE trace(i) = (byte1 - 256)
*
256 + byte2
END IF
NEXT i
trace bytes
# 4 1 0 2 6 <16> <msb 1> <lsb 1> . . . <msb 512> <lsb 512> <checksum> <NL
>
trace sample 512
trace sample 1
byte with decimal value 16
number of trace bytes (1026)
number of digits of 1026