Excel through learning

Excel through learning
Your source of knowledge

Monday, August 4, 2008

Service Request - Instrument Event Handling

Today, I was asked the same question again. I guess I explained this to different group of people many times. And each time, I createed a similar to explain because I did not save the origianl file. So, I decided to blog it and save the sample code as well.

What is service request (SRQ) in Status Subsystem and what are the applications? Service request is a features allow user to monitor certain activity in the instrument. When the condition is met, the instrument's SRQ bit will be set and it will fire an event to our software's event handler. The function then will be called.

There are many applications for SRQ:


  • Let say an instrument have an operation which taking very long time to complete. Instead of keep querrying the instrument's status byte, we can make use of SRQ. This prevent the querrying as it will make the instrument event more busy.
  • We are writing software to control an instrument. We would like to be 'informed' when there is any error occur. Instead of querrying the SYSTem:ERRor? to the instrument, we can setup the SRQ to notify us when the instrument generates error message.

In this example, we use Agilent's E3631A DC Power Supply as example. The scenario is we would like to setup so that the system fire an event when error message is generated from the instrument. Figure 1 shows the E3631A's Status subsystem.


Figure 1: E3631A's Status Subsystem

Let say we would like to fire the event when "Command Error" happen. So, we need to enable ESE bit 5. The SCPI command is "*ESE 32". The Standard Event is contribute to ESB bits in Status Bytes. That means, we need to enable the bit 5 in Status Bytes also. The SCPI command is "*SRE 32".

The sample VEE code is shown in figure 2. At the beginning we setup the instrument to fire the event by enabling the 2 status bits mentioned. To setup the event handler in VEE, we need to use "Instrument Event" container. It is located at the menu: I/O->Advanced I/O -> "Instrument Event", then select the instrument address. The "Event" is set to "RQS" (request), "Action" is set to "Any Set". The "mask" allows the container to mask the bits that we are interested. Since I'm interested to monitor the ESB bit (bit 5) of Status Byte, I set to #H20 (2^5 = 32). The Direct IO container after the "OK" button allow us to send a dummy SCPI command to the instrument, so that the "Command Error" will occur.


Figure 2: Event handling software setup in VEE

When we run the VEE program, note that the program will be waiting for user to press the "OK" button. Once the dummy command is sent to instrument, the ESB bit of the Status Bytes will be set. That will then set the RQS bit. When that happen, the software event handler will be calle. In this case, the "Instrument Event" container will active and output the *STB value. Notice that the value is 96 (32+64) because it is a sum of ESB (bit 5 = 32) and RQS(bit 6 = 64) of the Status Bytes.

Download the sample code in VEE here

Download the sample code in C# here

Thanks Jack for teaching me about this.

0 comments: