Buffer transfers – Measurement Computing Personal488 rev.3.0 For DOS & Windows 3.Xi User Manual
Page 91
![background image](https://www.manualsdir.com/files/797818/content/doc091.png)
8H. Turbo C
II. SOFTWARE GUIDES - 8. Driver488/DRV
II-76
Personal488 User’s Manual, Rev. 3.0
All the power of C may be used to manipulate, print, store, and analyze the data read from the
IEEE 488 bus. For example, the following statements print the average of ten readings from the 195:
int i;
float sum;
sum=0.0;
for (i=0; i; i++) {
ieeewt(“enter 16\n”);
ieeescnf(“%*4s%e”,&voltage);
sum=sum+voltage;
}
printf(“The average of 10 readings is %g\n”,sum/10.0);
Buffer Transfers
Instead of using an
IEEERD(_)
function to receive the data from a device, we can direct
Driver488/DRV to place the response directly into a data buffer of our choosing. For example, each
reading from the 195 consists of 17 bytes: a four-byte prefix and an eleven-byte reading followed by
the two-byte command terminator. So, we can collect 100 readings in a 1700-byte array. To do this,
we must first allocate the required space in an array:
char hundred[1700];
Now that we have allocated a place for the readings, we can direct Driver488/DRV to put readings
directly into
hundred
with the
ENTER #count BUFFER
command:
ieeeprtf(“ENTER 16 #1700 BUFFER %d:%d\n”,
segment(hundred),offset(hundred));
This command consists of the keyword
ENTER
, followed by the bus device address (
16
), a number sign
(
#
), the number of bytes to transfer (
1700
), and the keyword
BUFFER
, followed by the memory address
of the buffer. The buffer address is specified as
segment:offset
where
segment
and
offset
are
each 16-bit numbers and the colon (
:
) is required to separate them. The
segment
and
offset
values
we need are returned by the
segment
and
offset
functions, respectively.
Once the data has been received, we can print it out:
for (i=0; i<1700; i++) putchar(hundred[i]);
The program could process the previous set of data while collecting a new set into a different buffer.
To allow the program to continue, specify
continue
in the command:
ieeeprtf(“ENTER 16 #1700 BUFFER continue\n”,
segment(hundred),offset(hundred));
Once we have started the transfer, we can check the status:
ieeewt(“status\n”);
ieeerd(response);
printf(“%s\n”,response);
The status that is returned is typically:
CS21 1 L100 000 T0 C0 P1 OK
Notice
P1
which states a transfer is in progress, and
L
which shows we are still a listener. If the bus
device is so fast that the transfer completes before the program can check status, the response is
P0
showing that the transfer is no longer in progress. We can also
WAIT
for the transfer to complete and
check the status again:
ieeewt(“wait\n”);
ieeewt(“status\n”);
ieeerd(response);
printf(“%s\n”,response);
This time the status must be
P0
as the
WAIT
command waits until the transfer has completed. Now that
we know the transfer is complete, we are ready to print out the received data as shown above.