NI GPIB-Serial Converter Help

rd

  • Updated2024-03-18
  • 3 minute(s) read

rd

Read Data*

Type

I/O function

Syntax

rd #count [addr]<CR>

Purpose

You can use rd to read data from the GPIB.

Remarks

The argument count is a numeric string preceded by a number sign (#). count specifies the number of GPIB data bytes to read and can range from 1 to 4294967295.

The argument addr specifies the GPIB address of the device to be addressed as a Talker. Addr consists of a primary address and an optional secondary address.

The GPIB-RS232/485/422 reads data from the GPIB until one of the following events occurs:

  • The GPIB-RS232/485/422 successfully transfers all data.
  • The GPIB END message is received with a data byte.
  • The EOS byte is received.
  • The I/O time limit is exceeded. The EABO error is recorded.
  • The GPIB-RS232/485/422 receives a Device Clear. The EABO error is recorded.
  • The addr argument is specified and the requested GPIB addressing bytes cannot be sent. The EBUS error is recorded.

Because you might not know the number of bytes actually read from the GPIB, the GPIB-RS232/485/422 returns the received GPIB data to you in the following manner. First, the GPIB-RS232/485/422 returns all bytes it read from the GPIB. Next, if the number of bytes read is less than count, the GPIB-RS232/485/422 sends null bytes (decimal 0) until the total number of bytes returned to you matches the number specified in count. Finally, it returns a numeric string representing the number of bytes it actually read from the GPIB.

For example, if you send the GPIB-RS232/485/422 the programming message "rd #10"<CR>, it reads data from the GPIB until it receives 10 bytes of data, the END message, or an eos byte. If the GPIB-RS232/485/422 received END with the fourth data byte, it would return the 4 data bytes. Then it would send 6 null bytes followed by an ASCII 4 and <CR><LF>.

You should always read back count bytes of data from the serial port, then look at the numeric string to determine how many bytes were read from the GPIB.

If you call rd with the addr argument, the GPIB-RS232/485/422 must be CIC to perform the addressing. If this is the first function you call that requires GPIB Controller capability, and you have not disabled System Controller capability with rsc, the GPIB-RS232/485/422 sends Interface Clear (IFC*) to make itself CIC. It also asserts Remote Enable.

If you call rd with the addr argument, and you previously passed control to some other GPIB device, control must be passed back to you or you must send IFC* to make yourself CIC before making this call. Otherwise, the ECIC error is recorded.

When performing the addressing for a specified addr, the GPIB-RS232/485/422 sends out its own listen address as well as the talk address of the specified device. It then places itself in Standby Controller state with ATN* unasserted, and remains there after the read operation is complete.

If the addr argument is not specified, the GPIB-RS232/485/422 assumes it has already been addressed to listen by the Controller. If the GPIB-RS232/485/422 is the Controller, and did not address itself to listen before calling rd, the EADR error is recorded and no data bytes are transferred.

If you call rd without an argument, the GPIB-RS232/485/422 records EARG.

See Also

eos, eot, and tmo.

Example

Read up to 10 bytes from the GPIB device at address 3.

char  cmdBuffer [] = "rd #10 3\r";
char  rdBuffer[11];
char  countBuffer[5];
int count = 0;
memset(rdBuffer,0,11);
memset(countBuffer,0,5);
//Disable Termination Character to allow all NULL
//characters to be read from the serial port
viSetAttribute (instr, VI_ATTR_TERMCHAR_EN, VI_FALSE);
viSetAttribute (instr, VI_ATTR_ASRL_END_IN, VI_ASRL_END_NONE);
viWrite(instr, cmdBuffer, strlen(cmdBuffer), &retCount);
viRead(instr, rdBuffer, 10, &retCount);
//Re-enable Termination Character
viSetAttribute (instr, VI_ATTR_TERMCHAR_EN, VI_TRUE);
viSetAttribute (instr, VI_ATTR_ASRL_END_IN, VI_ASRL_END_TERMCHAR);
viRead(instr, countBuffer, 4, &retCount);
count = atoi(countBuffer);
printf("S Mode read %d bytes from device at PAD 3.\n", count);

Log in to get a better experience