04-02-2010 05:39 PM
Hello.
I have meassuring system keithley 237, connected to COM4 port.
And I have insturment commands from keithley manual.
When I use LabView Instrument I/O assistent and put there in "Query and Parse" steps these comands, device reacts as it should.
But when I try to write and execute my own C++ code, device does not react at all.
just no reaction at all!
May be somebody can help me and tell me what is missing.
Here is my C++ code:
#include <iostream>
#include "visa.h"
using namespace std;
int main (int argc, char *argv[])
{
ViStatus status;
ViSession defaultRM, instr;
/* Open Default RM */
status = viOpenDefaultRM(&defaultRM);
if (status != VI_SUCCESS) {
/* Error Initializing VISA...exiting */
return -1;
}
/* Access other resources */
status = viOpen(defaultRM, "ASRL4::INSTR", VI_NULL, VI_NULL, &instr);
// here I send commands to deviceviPrintf(defaultRM, "F1,0X"); // "F1,0X" and all another symbols in "" are just commands from keithley manual.
viPrintf(defaultRM, "B1E-6,0,X");
viPrintf(defaultRM, "L11,0X");
viPrintf(defaultRM, "P3X");
viPrintf(defaultRM, "O0X");
viPrintf(defaultRM, "N1X");
viPrintf(defaultRM, "H0X");
viClose(instr);
viClose(defaultRM);
return 0;
}
Solved! Go to Solution.
04-03-2010 03:26 AM
Hi,
there is an evident problem in your code: viPrintf () accepts as the first parameter a session handle, which in your case is 'instr' variable returned by viOpen (). Using the default resource manager leads to incorrect results (BTW, you should add to your code some error checking: I'd expect viPrintf () to return VI_ERROR_INV_OBJECT or similar error).
As an additional hint, I noted that you are not using any termination for your messages: you should check in device documentation if you must add some termination character (most instruments want a '\r' or '\r\n' sequence at the end of messages to accept them).
04-03-2010 05:29 PM
It works! 🙂
Thank you!
04-04-2010 12:16 AM
Photon,
Please mark Roberto's post as "solution".