Status/Service Request Service

NI-VISA

Status/Service Request Service

It is fairly common for a device to need to communicate with a controller at a time when the controller is not planning to talk with the device. For example, if the device detects a failure or has completed a data acquisition sequence, it may need to get the attention of the controller. In both GPIB and VXI, this is accomplished through a Service Request (SRQ). Although the actual technique for delivering this service request to the controller differs between the two interfaces, the end result is that an event (VI_EVENT_SERVICE_REQ) is received by the VISA driver. You can find more details on event notification and handling in Introductory Programming Examples and VISA Events. At this time, just assume that the program has received the event and has a handle to the data through the eventContext parameter.

Under VISA, the VI_EVENT_SERVICE_REQ event contains no additional information other than the type of event. Therefore, by using viGetAttribute() on the eventContext parameter, as shown in the following code, the program can identify the event as a service request.

status = viGetAttribute(eventContext,VI_ATTR_EVENT_TYPE, &eventType);

You can retrieve the status byte of the device by issuing a viReadSTB() operation. This is especially important because on some interfaces, such as GPIB, it is not always possible to know which device has asserted the service request until a viReadSTB() is performed. This means that all sessions to devices on the bus with the service request may receive a service request event. Therefore, you should always check the status byte to ensure that your device was the one that requested service. Even if you have only one device asserting a service request, you should still call viReadSTB() to guarantee delivery of future service request events. For example, the following code checks the type of event, performs a viReadSTB(), and then checks the result.

status = viGetAttribute(eventContext,VI_ATTR_EVENT_TYPE, &eventType);

if (eventType == VI_EVENT_SERVICE_REQ) {

status = viReadSTB(instr, &statusByte);
if ((status >= VI_SUCCESS) && (statusByte & 0x40)) {

/* Perform action based on Service Request */

}

/* Otherwise ignore the Service Request */


} /* End IF SRQ */