LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

device dose not react to C++ code

Solved!
Go to solution

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 device

viPrintf(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;
}

 

 

0 Kudos
Message 1 of 4
(3,691 Views)
Solution
Accepted by topic author photon123

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).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(3,680 Views)

It works! 🙂

 

Thank you!

0 Kudos
Message 3 of 4
(3,667 Views)

Photon,

 

Please mark Roberto's post as "solution".

S. Eren BALCI
IMESTEK
0 Kudos
Message 4 of 4
(3,656 Views)