09-25-2011 08:26 PM
I'm automating some tests using a Tektronix AFG3022B Function Generator.
To keep things simple, the problem I'm having is if someone decides to close my application inadvertently (i.e. Ctrl-C) during the middle of a read/write to the instrument. I can't communicate to the instrument the next time the application starts without a hard reset of the instrument.
It's not a consistent error too, sometimes it'll connect to the instrument with viOpen(), but then no write messages get through (always giving me a "Timeout expired before operation completed." error message). Other times it won't connect to the instrument at all with viOpen().
I've tried doing a viClear() straight after connecting to the instrument, but it doesn't help.
Any ideas?
09-26-2011 05:05 PM
Thhhza:
I have a few questions for clarification and troubleshooting.
1. First, are you using LabVIEW, SignalExpress (Tektronix Edition maybe?), or another program? Also, what
version of VISA are you using? You can find this in Measurement & Automation Explorer under My
System>Software. The numbers listed after "NI-VISA" are your version.
2. Do you have a clear or close vi after you try to read/write?
3. When you do terminate during a read or write, are you able to run a Measurement & Automation Explorer Test
Panel?
Feel free to send in a screen shot of your code. Have a good evening.
Tori W.
09-26-2011 06:11 PM
Hi Tori,
1. Console application written in Microsoft Visual C++ using NI-VISA 5.1.1
2. The only time I call viClose() is at the end when the application exits normally. A viClose() is called on the ViSession for the instrument, and then the ViSession for the default resource manager. If the user does not exit the application normally (i.e. Ctrl-C while running), these viClose() obviously don't get called.
3. If this is "Open VISA Test Panel", then yes. If I click Input/Output and send the query command "*IDN?\n" however, it gives me this error the first time:
Read OperationError
VISA: (Hex 0xBFFF0037) Device reported an input protocol error during transfer.
and on subsequent tries:
Read OperationError
VISA: (Hex 0xBFFF0015) Timeout expired before operation completed.
Also, the Function Generator is connected via USB to the PC.
Thanks,
Andrew.
09-26-2011 06:27 PM - edited 09-26-2011 06:28 PM
Some code snippets for basically what I'm doing, with the error checking (for easier reading).
Initialisation:
m_vstStatus = viOpenDefaultRM(&m_vssnDefaultRM);
m_vstStatus = viFindRsrc(m_vssnDefaultRM, "USB?*INSTR{VI_ATTR_MANF_ID==0x0699 && VI_ATTR_MODEL_CODE==0x0347}", &vflFindList, &vuint32NumInstruments, vacInstrumentResourceString);
m_vstStatus = viOpen(m_vssnDefaultRM, vacInstrumentResourceString, VI_NULL, VI_NULL, &m_vssnInstrument);
m_vstStatus = viPrintf(m_vssnInstrument, "*RST\n");
m_vstStatus = viPrintf(m_vssnInstrument, "SYST:KLOC:STAT ON\n");
Set Working Directory on USB Stick:
m_vstStatus = viPrintf(m_vssnInstrument, "MMEM:CDIR \"%s\"\n", sTestFileDirectory.c_str());
m_vstStatus = viQueryf(m_vssnInstrument, "MMEM:CDIR?\n", "%256[^\n]", vacWorkingDirectory);
Load Setup File from USB Stick into internal setup memory and recall it:
m_vstStatus = viPrintf(m_vssnInstrument, "MMEM:LOAD:STAT 1,\"%s\"\n", p_pTestFile->GetTestFileName().c_str());
m_vstStatus = viPrintf(m_vssnInstrument, "*RCL 1\n");
Set Outputs On/Off:
m_vstStatus = viPrintf(m_vssnInstrument, "OUTP1:STAT %s\n", p_sState.c_str());
m_vstStatus = viPrintf(m_vssnInstrument, "OUTP2:STAT %s\n", p_sState.c_str());
UnInitialisation:
m_vstStatus = viPrintf(m_vssnInstrument, "SYST:KLOC:STAT OFF\n");
m_vstStatus = viPrintf(m_vssnInstrument, "*RST\n");
viClose(m_vssnInstrument);
viClose(m_vssnDefaultRM);
09-27-2011 12:12 AM
Have a look at the Winapi function SetConsoleCtrlHandler(). With that function you can install a handler function , which is executed when the user hits CTRL-C and does the missing ViClose calls.
09-28-2011 06:07 PM
Thanks markus, that worked!