stat
- Updated2024-03-18
- 6 minute(s) read
stat
Return GPIB-RS232/485/422 Status
Type
General-use function
Syntax
stat [[c] n]<CR>
or
stat [c] s<CR>
or
stat [c] n s<CR>
Purpose
You can use stat to obtain the GPIB-RS232/485/422 status to see if certain conditions are currently present. stat is used most often to see if the previous operation resulted in an error.
Remarks
You should use stat frequently in the early stages of your program development when the responses of your GPIB devices are likely to be unpredictable.
The GPIB-RS232/485/422 responds with status information in a form depending on the mode or combination of modes you choose. n indicates that the status information is returned as numeric strings. s indicates that the status information is returned in symbolic format—that is, as mnemonic strings. Status bits are separated by a comma. Normally, you use s only when you are debugging your code and want to print the mnemonic for each piece of status information. c specifies that the status is returned after each programming message, eliminating the need to call stat after each programming message.
If you call stat without an argument, continuous status reporting is disabled.
The status information returned by the GPIB-RS232/485/422 contains four pieces of information: the GPIB-RS232/485/422 status, a GPIB error code, a serial error code, and a count. A <CR><LF> follows each piece of the response.
Status represents a combination of GPIB-RS232/485/422 conditions. Inside the GPIB-RS232/485/422, status is stored as a 16-bit integer. Each bit in the integer represents a single condition. A bit value of 1 indicates that the corresponding condition is in effect. A bit value of 0 indicates that the condition is not in effect. Because more than one GPIB-RS232/485/422 condition can exist at one time, more than one bit can be set in status. The highest order bit of status, also called the sign bit, is set when the GPIB-RS232/485/422 detects either a GPIB error or a serial port error. When status is negative, an error condition exists.
The following table lists the values and descriptions of the GPIB status conditions that the stat function might return.
S Mode GPIB Status Conditions stat Returns
Numeric Value (n) | Symbolic Value (s) | Description | Bit |
---|---|---|---|
–32768 | ERR | Error detected | 15 |
16384 | TIMO | Timeout | 14 |
8192 | END | EOI* or EOS detected | 13 |
4096 | SRQI | SRQ* detected while CIC | 12 |
2048 | — | Reserved | 11 |
1024 | — | Reserved | 10 |
512 | — | Reserved | 9 |
256 | CMPL | Operation completed | 8 |
128 | LOK | Lockout state | 7 |
64 | REM | Remote state | 6 |
32 | CIC | Controller-In-Charge | 5 |
16 | ATN | Attention asserted | 4 |
8 | TACS | Talker active | 3 |
4 | LACS | Listener active | 2 |
2 | DTAS | Device trigger active state | 1 |
1 | DCAS | Device clear active state | 0 |
The GPIB error code represents a single GPIB error condition present.
The serial error code represents a single serial port error condition present.
count is the number of bytes transferred over the GPIB by the last rd, wrt, or cmd function.
The following table lists values and descriptions of GPIB error conditions that the stat function might return.
S Mode GPIB Error Conditions stat Returns
Numeric Value (n) | Symbolic Value (s) | Description |
---|---|---|
0 | NGER | No GPIB error condition to report |
1 | ECIC | Command requires GPIB-RS232/485/422 to be CIC |
2 | ENOL | Write detected no Listeners |
3 | EADR | GPIB-RS232/485/422 not addressed correctly |
4 | EARG | Invalid argument or arguments |
5 | ESAC | Command requires GPIB-RS232/485/422 to be System Controller |
6 | EABO | I/O operation aborted |
7-10 | — | Reserved |
11 | ECAP | No capability for operation |
12-13 | — | Reserved |
14 | EBUS | Command bytes could not be sent |
15-16 | — | Reserved |
17 | ECMD | Unrecognized command |
The following table lists the serial port error conditions that the stat function might return.
S Mode Serial Port Error Conditions stat Returns
Numeric Value (n) | Symbolic Value (s) | Description |
---|---|---|
0 | NSER | No serial port error condition to report |
1 | EPAR | Serial port parity error |
2 | EORN | Serial port overrun error |
3 | EOFL | Serial port receive buffer overflow |
4 | EFRM | Serial port framing error |
A detailed description of the conditions under which each bit in status is set or cleared is in Status and Error Message Information.
In general, the GPIB-RS232/485/422 updates the first three status variables at the end of each programming message. It updates the fourth status variable, count, after a cmd, rd, or wrt function. The errors reported correspond to the previous programming message. For example, if you call wrt and then stat s, any errors returned to you correspond to errors in the wrt programming message, not stat. However, if status is returned in continuous mode, the status information corresponds to the current programming message. For example, suppose you called stat c s to set up continuous status reporting. After reading the status information returned from the stat call, you call wrt. The GPIB-RS232/485/422 then returns the status information that corresponds to the wrt message.
To begin continuous status reporting, send the stat c s, stat c n, or stat c n s programming message. Status information is immediately returned indicating the current status conditions. When you call stat with both s and n, the numeric status is always returned first.
Notice that when you send several programming messages to the GPIB-RS232/485/422, it buffers them and processes each one without any delay in between. However, if you enable continuous status reporting and check the status of each programming message before sending the next, the GPIB-RS232/485/422 waits for each subsequent programming message to arrive at the serial port before processing it. This slows down the overall performance of your program. If speed is a primary concern, disable continuous status reporting.
The continuous status setting remains in effect until you call stat again, call onl, or turn off the GPIB-RS232/485/422.
Example 1
Get the GPIB-RS232/485/422 status as numeric values.
char statusValueBuffer[10];
int statusValue;
char gpibErrorBuffer[10];
int gpibError;
char serialErrorBuffer[10];
int serialError;
char countBuffer[10];
int count;
char buffer [] = "stat n\r";
memset(statusValueBuffer,0,10);
memset(gpibErrorBuffer,0,10);
memset(serialErrorBuffer,0,10);
memset(countBuffer,0,10);
viWrite(instr, buffer, strlen(buffer), &retCount);
viRead(instr, statusValueBuffer, 10, &retCount);
statusValue = atoi(statusValueBuffer);
if(statusValue & (1 << 15))
{
printf("Error detected\n");
}
if(statusValue & (1 << 14))
{
printf("Timeout\n");
}
if(statusValue & (1 << 13))
{
printf("EOI* or EOS detected\n");
}
if(statusValue & (1 << 12))
{
printf("SRQ* detected while CIC\n");
}
if(statusValue & (1 << 8))
{
printf("Operation Complete\n");
}
if(statusValue & (1 << 7))
{
printf("Lockout State\n");
}
if(statusValue & (1 << 6))
{
printf("Remote State\n");
}
if(statusValue & (1 << 5))
{
printf("Controller-In-Charge\n");
}
if(statusValue & (1 << 4))
{
printf("Attention Asserted\n");
}
if(statusValue & (1 << 3))
{
printf("Talker Active\n");
}
if(statusValue & (1 << 2))
{
printf("Listener Active\n");
}
if(statusValue & (1 << 1))
{
printf("Device Trigger Active State\n");
}
if(statusValue & 1)
{
printf("Device Clear Active State\n");
}
viRead(instr, gpibErrorBuffer, 10, &retCount);
gpibError = atoi(gpibErrorBuffer);
switch(gpibError)
{
case 0:
printf("No GPIB error condition\n");
break;
case 1:
printf("Command requires S Mode to be CIC\n");
break;
case 2:
printf("No listeners detected\n");
break;
case 3:
printf("S Mode not addressed correctly\n");
break;
case 4:
printf("Invalid argument\n");
break;
case 5:
printf("Command requires S Mode to be System Controller\n");
break;
case 6:
printf("I/O operation aborted\n");
break;
case 11:
printf("S Mode has no capability for that operation\n");
break;
case 14:
printf("Command bytes could not be sent\n");
break;
case 17:
printf("Unrecognized command\n");
break;
}
viRead(instr, serialErrorBuffer, 10, &retCount);
serialError = atoi(serialErrorBuffer);
switch(serialError)
{
case 0:
printf("No serial port error\n");
break;
case 1:
printf("Serial port parity error\n");
break;
case 2:
printf("Serial port overrun error \n");
break;
case 3:
printf("Serial port receive buffer overflow error \n");
break;
case 4:
printf("Serial port framing error\n");
break;
}
viRead(instr, countBuffer, 10, &retCount);
count = atoi(countBuffer);
printf("Count is %d\n",count);
Example 2
Get the GPIB-RS232/485/422 status as symbolic values.
char statusValueBuffer[30];
char gpibErrorBuffer[10];
char serialErrorBuffer[10];
char countBuffer[10];
int count;
char buffer [] = "stat s\r";
memset(statusValueBuffer,0,30);
memset(gpibErrorBuffer,0,10);
memset(serialErrorBuffer,0,10);
memset(countBuffer,0,10);
viWrite(instr, buffer, strlen(buffer), &retCount);
viRead(instr, statusValueBuffer, 30, &retCount);
viRead(instr, gpibErrorBuffer, 30, &retCount);
viRead(instr, serialErrorBuffer, 30, &retCount);
viRead(instr, countBuffer, 30, &retCount);
count = atoi(countBuffer);
Example 3
The following list illustrates what appears on the screen when you are programming the GPIB-RS232/485/422 from a terminal. GPIB-RS232/485/422 responses are in bold text. The statements in parentheses are comments.
stat c s n (Enable continuous status reporting.)
344
0
0
3
CMPL,REM,ATN,TACS ( Status returned. )
NGER
NSER
3
wrt 10
ABCDE ( Write the string ABCDE. )
296 ( to device 10. )
0 ( Status returned. )
0
5
CMPL,CIC,TACS
NGER
NSER
5