C# VISA wait on RQS

I'm trying to write a simple C# (.NET 4.0) program to control a Keithley 2400 SMU over VISA GPIB and I'm having trouble with getting the program to wait for the Service Request that the Keithley sends at the end of the sweep.
The sweep is a simple linear voltage sweep, controlled internally by the Keithley unit. I've got the unit set up to send a ServiceRequest signal at the end of the sweep or when compliance is reached.
I'm able to send the commands to the SMU and read the data buffer, but only if I manually enter a timeout between the sweep start command and the read data command.
One issue I'm having is that I'm quite new to C# - I'm using this project (porting parts of my LV code) to learn it. 
Here is what I have so far for my C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using NationalInstruments.VisaNS;
private void OnServiceRequest(object sender, MessageBasedSessionEventArgs e)
Console.WriteLine("Service Request Received!");
// open the address
Console.WriteLine("Sending Commands to Instrument");
instrAddr = "GPIB0::25::INSTR";
mySession = ResourceManager.GetLocalManager().Open(instrAddr);
// Cast to message-based session
mbSession = (MessageBasedSession)mySession;
// Here's where things get iffy for me... Enabling the event and whatnot
mbSession.ServiceRequest += new MessageBasedSessionEventHandler(OnServiceRequest);
MessageBasedSessionEventType srq = MessageBasedSessionEventType.ServiceRequest;
mbSession.EnableEvent(srq, EventMechanism.Handler);
// Start the sweep (SMU was set up earlier)
Console.WriteLine("Starting Sweep");
mbSession.Write(":OUTP ON;:INIT");
int timeout = 10000; // milliseconds
// Thread.Sleep(10000); // using this line works fine, but it means the test always takes 10s even if compliance is hit early
// This raises error saying that the event is not enabled.
mbSession.WaitOnEvent(srq, timeout);
// Turn off the SMU.
Console.WriteLine("I hope the sweep is done, cause I'm tired of waiting");
mbSession.Write(":OUTP OFF;:TRAC:FEED:CONT NEV");
// Get the data
string data = mbSession.Query(":TRAC:DATA?");
// Close session
mbSession.Dispose();
All the above is supposed to mimic this LabVIEW code:
So, any ideas on where I'm going wrong?
Thanks,
Solved!
Go to Solution.

It turns out that I need to enable the event as a Queue rather than a handler:
mbSession.EnableEvent(srq, EventMechanism.Handler);
Should actually be:
mbSession.EnableEvent(srq, EventMechanism.Queue);
Source: The documentation under "Remarks". It was a pain to find the docs on it... NI needs to make it easier :-(.
With this change, I also don't need to create the MessageBasedSessionEventHandler.
The final, working code (with fluff like namespaces and classes removed) looks like:
rm = ResourceManager.GetLocalManager().Open("GPIB0::25::INSTR");
MessageBasedSession mbSession = (MessageBasedSession)rm;
MessageBasedSessionEventType srq = MessageBasedSessionEventType.ServiceRequest;
mbSession.EnableEvent(srq, EventMechanism.Queue); // Note QUEUE, not HANDLER
int timeout = 10000;
// Start the sweep
mbSession.Write(":OUTP ON;:INIT");
// This waits for the Service Request
mbSession.WaitOnEvent(srq, timeout);
// After the Service Request, turn off the SMUs and get the data
mbSession.Write(":OUTP OFF;:TRAC:FEED:CONT NEV");
string data = mbSession.Query(":TRAC:DATA?");
mbSession.Dispose();
I hope this helps future programmers.

Similar Messages

  • VISA wait on event Error -107380731​3

    Hello, I am trying to zero and calibrate a pair of HP power meters.
    After sending the command to zero one of the meters, I use the VISA Wait for RQS.vi which throws this error:
    Error -1073807313 occurred at VISA Wait on Event in Wait for RQS.VI->HP 437B_visa.vi->PowerMeterSetup.vi
    Possible reason(s):
    VISA: (Hex 0xBFFF002F) You must be enabled for events of the specified type in order to receive them.
    I opened up the "Wait for RQS.vi" to examine the "Wait on Event.vi". The "Wait on Event.vi" has the hexidecimal constant 3FFF200B (Service Request) attached to the event type input, and there is a VISA event class controller set to "Generic Event" attached to the event resource class input.
    So, why the error?
    Thanks,
    Victor

    On NI's web site there is a tutorial, app note, and examples on using VISA for handling service requests. Below are links to each.
    Tutorial: http://www.ni.com/swf/presentation/us/visa/
    Application Note: http://zone.ni.com/devzone/conceptd.nsf/webmain/1A​760883EEF23D7E86256DBA006C9C00?opendocument
    Examples: http://sine.ni.com/apps/we/niepd_web_display.DISPL​AY_EPD4?p_guid=C99424CC48EC1273E034080020E74861&p_​...

  • HP 34401A - wait on event in Wait on RQS

    Hello,
    i'm in a desperate situation. I want to measure resistance with LabView 7.1 over GPIB. The equipment i use is the HP 34401A multimeter. For many times it was no problem. The single read example worked without failures and returned the measured values.
    Then a short time later, nothing worked as before. I always receive this error: "VISA Wait on Event in Wait for RQS.VI->HP34401A Read Meas.vi->HP34401A Single Read Example.vi"
    I know this question is not asked for the first time. But the answers given in the other threads don't help.
    The timeout time i changed from 10000 to 60000 ms. The failure is in the wait for RQS.vi .
    Please help me, that would be very kind!
    Thanks a lot
    Greg

    I have one of those multimeters as well, and use it from time to time in a program to verify the voltage from a power supply...
    I always use the method in the vi attached, since I've always found it easier (again, easier for me anyways), since you can control everything. You may want to vary the wait in between the read and the write, since my meter is an Agilent (newer than if it says HP...they had to branch it off for some reason), and it might be different, but I doubt it.
    All the commands are in the manual... Hope this helps,
    Geoff
    Attachments:
    GPIB Write-Read.vi ‏22 KB

  • VISA Wait on Event User Event

    I have a Producer/Consumer program that uses an Event Structure to handle the UI button presses.  I want to be able to use the VISA wait on Event to read characters from the RS232 port.  So in my Event Structure I created a case for dynamic user events.
    I also create a while loop that has the VISA Enable Event and VISA Wait on Event in it. I enabled the "Serial Character" event only.  When I get this event I use the Create User Event.VI and Register for Events to get a Event Refnum
    How do I get the Event Refnum from this loop into my Producer loop?
    Solved!
    Go to Solution.

    Paul_Knight_Lockheed_Martin wrote:
    Here is the code
    No, that is not the code. That is one subVI and a picture. Where are you waiting for the VISA events? Where are you generating your user event? Based on the picture you are calling the Initialize_Controller_Communication and remaing in that code until the Stop buuton is pressed. You will not start your event structure in the producer loop until this VI completes. So, if you are not hitting the stop button to complete your initializtion it is no wonder you are never seeing your event structure run.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • VISA wait on Event crashes RT target

    After adding code that included a VISA wait on event (serial character), my cFP-2220 with LVRT 2012SP1 stopped answering when LabVIEW tries to halt the running code to do a build or deploy...(The code works otherwise works fine).
    The code on the controller seems to stop (all activity can be seen halting), but the VISA-part seems to still be hanging, or have crashed the controller (web and ftp interface goes down as well).  If I just reduce the given timeout from 100 ms to 50 ms, the problem disappears. 
    My own interpretation of this is that the rules that is supposed to enable the host PC to halt code on the RT-target is simply not abided by the VISA wait function, and if that function happens to be waiting while the command is issued, and this wait does not happen to time out relatively shortly after the command has arrived, it will cause a crash.
    Is this a bug, is there a workaround other than not using events (I changed the code from polling to events to be able to detect 5/10 ms silence time on serial ports without using all processing time on it...), or is it expected and not considered an issue?
    MTO

    James-K wrote:
    Artst,
    Can you post a screenshot of your code to further clarify?  
    It sounds like you are trying to stop the VIs by clearing the reference while it is still in use which will lead to a crash.  There is not a way to "unblock" a VI once it is running.  Can you specify a timeout instead?
    Well, I think this is not giving enough credit to the actual problem. One common VISA programming paradigme in the standard C API is to actually let a VISA Read (and of course a VISA Wait on Event) to terminate with an error by issuing the viTerminate() function, which I believe should be possible to get optionally be called by VISA Close too. Unfortunately there is no direct access to any VISA Terminate function in the LabVIEW palettes, but I have in the past created a small VI which calls the underlaying VISA API directly to abort any stuck operations on a session. Possibly this VI could solve the problem, making the VISA Wait On Event return before the VISA Close pulls its session under its feet.
    PS: Why can't I upload the VI directly to the board? Is it because it is in LabVIEW 7.1 format??
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions
    Attachments:
    VISA Close with Abort.zip ‏10 KB

  • VISA Wait On Event Crashes LabVIEW

    While "VISA Wait On Event" is pending on an event, and in another thread the "VISA resource name" input to "VISA Wait On Event" is closed using "VISA Close" vi LabVIEW crashes.
    I had a need to programmatically cause "VISA Wait On Event" to unblock so the LabVIEW program it is running in can be closed, or the "VISA resource name" originally input to "VISA Wait On Event" can be changed. I expected that executing "VISA Close" in another thread would cause "VISA Wait On Event" to unblock with an error. Instead LabVIEW crashes.

    James-K wrote:
    Artst,
    Can you post a screenshot of your code to further clarify?  
    It sounds like you are trying to stop the VIs by clearing the reference while it is still in use which will lead to a crash.  There is not a way to "unblock" a VI once it is running.  Can you specify a timeout instead?
    Well, I think this is not giving enough credit to the actual problem. One common VISA programming paradigme in the standard C API is to actually let a VISA Read (and of course a VISA Wait on Event) to terminate with an error by issuing the viTerminate() function, which I believe should be possible to get optionally be called by VISA Close too. Unfortunately there is no direct access to any VISA Terminate function in the LabVIEW palettes, but I have in the past created a small VI which calls the underlaying VISA API directly to abort any stuck operations on a session. Possibly this VI could solve the problem, making the VISA Wait On Event return before the VISA Close pulls its session under its feet.
    PS: Why can't I upload the VI directly to the board? Is it because it is in LabVIEW 7.1 format??
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions
    Attachments:
    VISA Close with Abort.zip ‏10 KB

  • RQS and visa on wait

    Hello!
    I have Agilent 35670A signal analyzer over GPIB. For the past three months or so, it has been working fine. However, since last week, I seem to have a problem with it, especially with visa on Wait.vi.
    What happens is that Labview waits and wait without processing to a next vi even if the instrument has finished its job. The particular vi that is problematic is called "run.vi", in which, by highlighting the execusion, I have found that the vi named as "wait on RQS" is not responding at all.
    I was previously using Labview 7.1, but when the problem started, I upgraded it to the version 8, but without any success of getting rid of the problem.
    Looks to me that the instrument lost the communication with the labview, and the labview is still trying to communicate with it. Only this specific function causes trouble and the rest of the function, such as obtaining the data itself (without having the labview to run the instrument) works OK.
    Any suggestions?

    Hello,
    thank you for your reply.
    I am LabView beginner and try to measure the frequency response of actuator with LabView 7.1 and Agilent 35670A signal analyzer.
    When I test one sample, it works OK, but when I measure next sample(new one) again, I get the following error message.
    Error 1073807339 occurred at VISA wait on Event in Wait for RQS.vi
    It happens almost same with havenoidea's. LabView wait and wait ("Wait on RQS.vi is not response at all") even if the signal analyzer finished the measurement, then I get the error message. ( but I get the result from the signal anayzer). In this case the sweep frequency of the signal analyzer (from 2Hz up to 50KHz) changes very slowly.
    I use Window XP and NI-488.2 ver.1.70 in my PC.
    I attached the related VI for your reference. 
    Thank you
    Attachments:
    Frequency Response.zip ‏319 KB

  • Visa Set Timeout Or Wait Function

    Hi guys, I want that my VISA waits for a certain number of seconds doing always the same operation.
    The first  idea I had is shown in Immagine, after that I saw the Visa set Timeout but I haven't understood how it works.
    What I want is that the instrument I'm controlling stays in the :TRACe1:MODE MAXHold (without resetting the comand, so no cicle) until I want.
    Which is the correct solution?
    Attachments:
    Immagine.PNG ‏66 KB
    Immagine2.PNG ‏80 KB

    Hi Kate first of all thank you for your reply so the second one should be used between the write&read visa function, is it correct? For example when I want acquire the data from the instrument I should give some time between the instruction sent with the Write Visa and the feedback received from the Read Visa, have I understood well?
    Another thing about the first immage using this configuration  are you sure that the last value that I read from the instrument will be the result of all the things seen from 0 to 20seconds?
    You will find the reason of this question watching the immage attached. As you can see the doubt I have is that the output of the image2 is the same of the input of the image1.
    To be more accurate the instruction :TRACe1:MODE MAXHold has this function: Maintains the minimum for each point of the trace, and updates each trace point if a new minimum is generated in successive sweeps.
    So what I want to see is the final result of the successive sweeps, for example the final result of all the sweeps after 20 seconds.
    I hope that this clarify you what I'm asking for.
    Attachments:
    Immagine.PNG ‏77 KB
    Immagine2.PNG ‏77 KB

  • Problem with visa RQS (always times out)

    I am trying to program a pair of Wavetek 39 waveform generators, which us GPIB.  I want to not fill up their input buffer by seending commands too fast, so I want to know when it is done with one before sending the next one.  The way I should do this it seems, is to use the service request event.  Unforunately, I can't get that working. 
    I've slightly modified the SRQ event example (just modified the instrument instruction string to match my instrument) and attaced that.  Unfortunately, when I run that, no service request is generated, or at least the "wait for RQS" vi doesn't pick up on them, so it always times out, even thought the instruction ("WAVE SINE", which just selects a sine wave for output) is definately finfished. 
    Any ideas why this isn't working, or othe methods I might use to make sure I don't send instructions too fast (besides just adding arbtrary waits. .  that would be dumb)?
    Attachments:
    SRQ Event Handling.vi ‏42 KB

    yes I've seen that tutorial.  It is, as far as I can tell, very similar to the example code in SRQ Event Handling.vi.  Unfortunately I still get timeouts when I try using " *OPC? " instead of " *OPC " so either I'm doing something wrong (and not understanding how it's supposed to work), or my GPIB device is simply not generating the service request as it should.
    - Bjørn
    Message Edited by holomorph on 01-26-2007 05:54 PM
    Message Edited by holomorph on 01-26-2007 05:55 PM

  • Why use Visa Events?

    In short, why would one want to use Visa Events?  I have been experimenting with them in order to try to find new ways to handle or avoid Visa Read timeouts and I am struggling to see how they are useful, because they throw timeout errors too.  To provide some background, I am hacking on a test application that reads and displays data from a serial port.  The data can be intermittent, because I often toggle my my serial devices on and off.  I don't want to be bothered with timeout errors stopping my application, so I have used varisous ways to handle them.  The current way I am experimenting with uses Visa Events, hence the reason for this question. 
    If the Visa Read times out and the Visa Wait on Event  times out, then what is the advantage of the latter?  Is the Wait on Event less resource intensive than Visa Read?  By the last question, I mean does the Visa Read poll or block behind the scenes while the Wait on Event does not? 
    Thanks in adavnce.

    Hi Tysoni,
    There are many advantages to using VISA events, one of which being that they can prevent LabVIEW from continuously polling your serial ports.
    The links below provide some additional information on VISA events and receiving time outs while using VISA events.
    http://digital.ni.com/public.nsf/allkb/179E61F87CF8B340862571EA0037CFA3
    http://digital.ni.com/public.nsf/allkb/E393205297CFF1B386256DFA00738F4A
    Regards

  • Can't get RQS to work

    I'm new to gpib programming and the various forum threads on this topic haven't helped me. If I understand correctly, If I have serial autopolling set then I can wait on RQS otherwise I can wait on SRQI. I've written a short test that prints ibsta, iberr, and ibcnt after each gpib command. Regardless of how I set IbaAUTOPOLL, ibsta after ibwait reports TIMO. I'd appreciate any hints on what I don't understand. This was done on very old Solar is 8 OS/Sun hardware using NI SBUS card and drivers; this code correctly reads a resistor from an Agilent dmm.
    When enabled I see:
    ibsta = 0x4100  < TIMO CMPL >
    iberr = 0 EDVR <DOS Error>
    ibcnt = 5
    When disabled I see:
    ibsta = 0x4128  < TIMO CMPL CIC TACS >
    iberr = 768 <UNKNOWN>
    ibcnt = 15319040
    I've included the source of my test case(renamed dotc cause .c wouldnt attach) and both runs as attachements. I'd really appreciate any clue on what's wrong. (so stuck)
    TIA
    gary
    Attachments:
    sAUTO_enabled.log ‏3 KB
    sAUTO_disabled.log ‏3 KB
    solI3e_dotc ‏5 KB

    RQS is one of those GPIB features that can bite hard.  So let me dig out a bit of a history lesson.
    RQS as designed was a means to notify the controller in charge that an instrument was in need of attention but, more than that HP provided for a "Prioritization" of when to service service requests.  Service requsts a served in ascending address order.  If device at address 2 has an unserviced service request you cannot see a newer RQS on anything other than address 1 (assuming the CIC is address 0).   Many a year ago I learned the hard way when our lab's ovens raised RQS by default upon reaching the stable setpoint.  Our ovens were usually at address 4  blocking service reqests on our TEK scopes with a default address in the teens.  Not fun when your perfectly functioning code "Suddenly quits" from one iteration to the next.
    You can usually avoid raising RQS.  It can be rather tricky as soon as more than 1 instrument is on the bus.
    Jeff

  • Problème enregistrement et erreur 1073807339

    Bonjour,
    Je cherche à suivre l'évolution de la résistance (j’impose un courant, je récupère une tension puis U=RI) et de la température de mon échantillon au cours du temps, grâce à deux équipements Keithley connectés par GPIB.
    Pour le suivi de la résistance, l’utilisateur détermine le pas de temps d’enregistrement en entrée. Pour le suivi de la température, l’utilisateur définit un pas de temps d’enregistrement et un seuil de détection de variation (typiquement 1 %).
    Sur la face avant se trouvent quelques indicateurs pour déterminer les causes de l’arrêt du programme (ne sont pas des problèmes LabView) ou les potentielles erreurs LabView.
    Je rencontre deux problèmes avec mon programme :
    1/ parfois, l’enregistrement de la résistance s’arrête (mais le programme continue d'enregistrer la température). Il semblerait que ce problème arrive lorsque je consulte ou copie le fichier texte dans lequel sont enregistrées les données  (pas à chaque fois).
    2/ si j’utilise j’utilise excel ou que j’effectue diverses autres actions sur l’ordinateur alors que le programme LabView est lancé, le message d’erreur suivant s’affiche : « Error 1073807339 occured at VISA wait an event for RQS.VI », et le programme ne tourne alors plus correctement (problème avec le Keithley me permettant de suivre l’évolution de la température).
    Si vous pouviez m’aider à comprendre d’où viennent ces problèmes (surtout le premier), ça me serait bien utile. Vous trouverez en PJ le programme LabView et différents sous-VI. Je n’ai mis que peu d’explications dans le programme, donc si besoin je peux apporter des compléments d’informations.
    Merci de votre aide,
    Simon
    Pièces jointes :
    Conditions enregistrement.vi ‏11 KB
    calcul pas de temps-M2.vi ‏10 KB
    Pgm principal.vi ‏82 KB

    réponse rapide avant d'ouvrir ton code :
    Excel n'est pas partageur, si tu ouvres un fichier avec Excel, il  ne laisse pas d'autres appli accèder à ce fichier, en tout cas c'était vrai avant, peut être queles versions récente sont plus souples, mais pas sûr.
    après avoir vu le code :
    je pense que de lire le fichier de résultat pour voir la dernière valeur n'est pas une super idée, tu pourrais conserver cette valeur dans un shift register pour éviter les accès au fichier.
    ensuite, ouvrir ton fichier avec une autre appli pendant que ton soft continu d'y ajouter des valeurs est un peu risqué, en fait ça va dépendre de l'appli que tu utilises, selon comment elle fonctionne tu auras différents comportement, si tu prends Notepad++ tu n'auras pas de soucis, si tu prends Excel, là c'est plus problématique...
    il y a plusieurs option, avant d'écrire ton fichier, t'assurer qu'il est "libre" en récupérant l'erreur à la sortie d'un "open file", c'est moyen parce que tu dois ensuite stocker les valeurs den mémopire jusqu'à ce que le fichier soit libre..
    autre option, utiliser des TDMS (fichiers qui permettent les accès conccurents), il existe aussi un Addin pour qu'Excel puisse ouvrir ces fichiers.
    Il y a surement d'autre option auxquelles je n'ai pas pensé.
    Bonne chance
    When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"

  • HP 34401A-When I run the Read Meas.vi, it has error if I do not turn off the data storage

    When I run the Read Meas.vi, it has error if I do not turn off the data storage. The same thing happen when I run the App. Example. vi. Anyone knows how to solve this problem? Thanks alot.
    KL

    LoganS wrote:
    Hi KL,
    The Read Meas.vi is one of the subvi's in the App. Example.vi, so this problem is most likely the same problem in each case. From the help for Read Meas.vi:
    Data Storage instructs the device to store the data to be sent to either the internal or external buffer. If TRUE (default), the VI stores data in the on mode. If FALSE, the VI does not retain data in the off mode. Use the off mode only with the average min/max operation when you do not need to retrieve data. You cannot configure the meter for external buffering in the off mode.
    So the question is, are you trying to retrieve any data? If so, then as indicated in the above paragraph, you cannot retrieve data and have the data storage turned off. Good luck!
    Logan S.
    Yes, I need to retrieve data. So due to that problem, I cannot really get any data. I am not sure is that problem is due to the USB GPIB or not. But once I click on the click arrow, everying goes fine from initialise, measurment... once it comes to Read measurment, it has error (say somthing like: VISA Wait on Event for RQS.vi->HP34401A Read Meas.vi->Untitled 1) I have no idea like what it shows up.
    KL

  • Communication GPIB avec un keithley 2000

    Bonjour à tous,
    j'essai d'utiliser mon multimètre keithley 2000 en communication GPIB sur mon labview 8.6. J'ai télécharger un vi (pièce jointe) qui est un exemple. J'arrive à initialiser sans pb... mon pb se situe au niveau de la fonction lecture. Le sous vi atteint le time out de 25s et me renvoie l'erreur suivante :
    L'erreur -1073807339 s'est produite à : VISA Wait On Event dans Wait for RQS.VI:1->_ke2000 Wait for SRQ.vi->ke2000 Data Read Single.vi->Keithley channel test.vi
    Raisons possibles :
    VISA:  (Hex 0xBFFF0015) Le délai d'attente (timeout) a expiré avant que l'opération ne soit achevée.
    Je ne comprends pas du tout ce qui se passe, quelqu'un aurait-il une idée !!! Merci à tous
    Attachments:
    Keithley channel test.vi ‏48 KB

    duplicate post

  • Input Triggers from GPIB with LabView

    Hi all,
    I am new to LabView (few days...)
    I use LabView 5.1 with a GPIB interface, and a KEITHLEY 238 current source
    measure unit. The detector is moved on a X-Y table with two stepper motors,
    controlled by a Windows 95 software.
    I would like LabView to record a measurement from the current source
    measure unit each time the current source measure unit sends a trigger
    through the GPIB interface.
    I tried to use VISA sessions and "Wait for RQS.vi" to make LabView wait for
    an input trigger from the GPIB, but it doesn't work..problems with VISA
    class... What VISA class should I choose?
    Do you think this is the best suited method for my application?
    Thank You!
    Norbert MAILLOT

    NI 488.2 won't work because the NI stands for NATIONAL INSTRUMENTS and not QUANCOM. You have to use the configuration software and driver from your vendor. If the instrument driver uses VISA and if your vendor provides a VISA driver for their card, then you should be okay. If the driver has the LabVIEW GPIB functions or if the vendor doesn't have a VISA driver, then you will have to replace all of the NI GPIB functions with whatever functions your vendor provides. If they don't provide a set of VIs, you may have to use a Call Library Node to access your vendor's dll.

Maybe you are looking for