Home › Forums › HTBasic Forum › GPIBNI, VISA, 34401A and *OPC? failing
- This topic has 6 replies, 3 voices, and was last updated 6 months ago by
Tony Goodhew.
-
AuthorPosts
-
April 19, 2025 at 9:52 am #9485
Hi All,
I was trying to run an example program from the manual for a HP 34401A (“Using Status Registers” on page 188) and when it gets to the line:
90 OUTPUT @Dmm; "*OPC?" ! Assure synchronizationThe 34401A generates an error -410 “Query Interrupted” if I use the Visa driver. It works fine if I use the GPIBNI driver.
No change in the code, just loading and unloading the device in the Device Setup dialog.
Any thoughts on what I should be looking at?
Thanks,
TonyG
Full App Source:
10 DIM Results$[4096] 20 INTEGER Val,Hpib,Mask,Task 30 ASSIGN @Dmm TO 714 40 CLEAR 7 ! Clear GPIB and dmm 50 OUTPUT @Dmm;"*RST" ! Reset dmm 60 OUTPUT @Dmm;"*CLS" ! Clear dmm status registers 70 OUTPUT @Dmm;"*ESE 1" ! Enable "operation complete" bit to set 80 ! "standard event" bit in status byte 90 OUTPUT @Dmm;"*SRE 32" ! Enable "standard event" bit in status byte 100 ! to pull the IEEE-488 SRQ line 110 OUTPUT @Dmm;"*OPC?" ! Assure synchronization 120 ENTER @Dmm;Val 130 ! 140 ! Configure the multimeter to make measurements 150 ! 160 OUTPUT @Dmm;"CONF:VOLT:DC 10" ! Set dmm to 10 volt dc range 170 OUTPUT @Dmm;"VOLT:DC:NPLC 10" ! Set the integration time to 10 PLCs 180 OUTPUT @Dmm;"TRIG:COUN 100" ! Dmm will accept 100 triggers 190 OUTPUT @Dmm;"INIT" ! Place dmm in "wait-for-trigger" state 210 OUTPUT @Dmm;"*OPC" ! Set "operation complete" bit in standard event 220 ! registers when measurement is complete 230 ! 240 Hpib=7 250 ON INTR Hpib GOSUB Read_data 260 Mask=2 ! Bit 1 is SRQ 270 ENABLE INTR Hpib;Mask ! Enable SRQ to interrupt the program 280 ! 290 ! Execute other tasks while waiting for data 300 ! 310 Task=1 320 WHILE Task=1 330 DISP "Taking Readings" 340 WAIT .5 350 DISP "" 360 WAIT .5 370 END WHILE 380 PRINT "Results: ";Results$ 390 STOP 400 ! 410 Read_data: ! 420 OUTPUT @Dmm;"FETch?" 430 ENTER @Dmm;Results$ 440 OUTPUT @Dmm;"*CLS" ! Clear dmm status registers 450 Task=0 460 RETURN 470 ENDApril 19, 2025 at 10:59 am #9486I reimplemented this in C# using the NI VISA libraries and the code works as expected:
using Ivi.Visa; using NationalInstruments.Visa; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.ConstrainedExecution; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SRQTest { internal class Program { public static GpibSession gpibSession; public static NationalInstruments.Visa.ResourceManager resManager; public static int gpibIntAddress = 14; // 34401A public static string gpibAddress = string.Format("GPIB0::{0}::INSTR", gpibIntAddress); public static SemaphoreSlim srqWait = new SemaphoreSlim(0, 1); // use a semaphore to wait for the SRQ events static void Main(string[] args) { // Setup the GPIB connection via the ResourceManager resManager = new NationalInstruments.Visa.ResourceManager(); // Create a GPIB session for the specified address gpibSession = (GpibSession)resManager.Open(gpibAddress); gpibSession.TimeoutMilliseconds = 8000; // Set the timeout to be 4s gpibSession.TerminationCharacterEnabled = true; gpibSession.Clear(); // Clear the session gpibSession.ServiceRequest += SRQHandler; SendCommand("*RST"); // Reset the DMM SendCommand("*CLS"); // Clear the DMM status registers SendCommand("*ESE 1"); // Enable "operation complete" bit to set "standard event" bit in status byte SendCommand("*SRE 32"); // Enable "standard event" bit in status byte to pull the IEEE-488 SRQ line var opcResult = QueryString("*OPC?"); // Assure synchronization Console.WriteLine($"OPC Result: {opcResult}"); // Print the result of the OPC query SendCommand("CONF:VOLT:DC 10"); // Set DMM to 10 volt DC range SendCommand("VOLT:DC:NPLC 10"); // Set the integration time to 10 PLCs SendCommand("TRIG:COUN 100"); // DMM will accept 100 triggers SendCommand("INIT"); // Place DMM in "wait-for-trigger" state SendCommand("*OPC"); // Set "operation complete" bit in standard event // Wait for the SRQ event srqWait.Wait(); // Wait for the SRQ event to be signaled // Read the data string response = QueryString("FETCH?"); Console.WriteLine($"1. Response: {response}"); // Clear the DMM status registers SendCommand("*CLS"); } public static void SRQHandler(object sender, Ivi.Visa.VisaEventArgs e) { // Read the Status Byte var gbs = (GpibSession)sender; StatusByteFlags sb = gbs.ReadStatusByte(); Console.WriteLine($"1. SRQHandler - Status Byte: {sb}"); gpibSession.DiscardEvents(EventType.ServiceRequest); SendCommand("*CLS"); srqWait.Release(); } static private void SendCommand(string command) { gpibSession.FormattedIO.WriteLine(command); } static private string ReadResponse() { return gpibSession.FormattedIO.ReadLine(); } static private string QueryString(string command) { SendCommand(command); return (ReadResponse()); } } }Looking at the NI IO Trace Utility, I can see that the HTBasic program differs in that it doesn’t add a 0A to the end of the *OPC? string – Adding END to the OUTPUT statement fixes that and I can continue on but I now run into a problem on line 270 with HT Basic giving an Error 170 “I/O operation not allowed”:
270 ENABLE INTR Hpib;Mask ! Enable SRQ to interrupt the programIf I swap to the GPIBNI driver then the program works successfully.
TonyG
April 22, 2025 at 7:11 am #9487Tony,
I don’t know what GPIB I/O your using, but the cheap Chinese knockoffs (i.e. for N.I. & Keysight) from eBay have issues. HT Basic uses the device registers to control the GPIB. The knockoffs don’t adhere to the strict register implementation of the original device and rely on the device drivers for data and control transfer.
Hope this helps.
April 22, 2025 at 9:40 am #9488I’m using an original NI GPIB-ENET/1000 with the latest NI 488 & VISA drivers.
For clarity, the Basic code works if I use the GPIBNI driver but fails if I use the VISA driver.
That seems to indicate a HT Basic problem and not a problem with the NI Hardware.
April 23, 2025 at 6:34 pm #9489Hi Tony,
Thanks for reporting this. I was able to reproduce and will log a ticket to get it fixed.
Thanks,
Pat
April 23, 2025 at 6:42 pm #9490Thanks Pat – Appreciate it.
TonyG
May 11, 2025 at 6:53 pm #9499Hey Pat,
Just wondering if this got fixed and if there is any way to get the updated code?
Thanks,
TonyG
-
AuthorPosts
- You must be logged in to reply to this topic.