Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

C++ Help with GPIB and 488.1 device

To Any and All,
 
Can you tell me what I am doing wrong here?
 

#include

<iostream>

#include

<windows.h>

#include

"ni488.h"

int main()

{

int gpib;

gpib = ibfindA(

"GPIB0");

ibsic(gpib);

ibcmd(gpib,

"_?@3",4L);

ibwrt(gpib,

"C2",2L);

ibcmd(gpib,

"_",1L);

ibcmd(gpib,

"_?@3",4L);

ibwrt(gpib,

"A0",2L);

ibcmd(gpib,

"_",1L);

return 0;

}

The device does not respond to myt commands. I think it is probably with my board initialization, but I am at a loss. I know the commands work with ibic.exe, in the order presented and the hardware and unit are working. So it must be my coding.

If I use ibfind I get this error;

error C2664: 'ibfindW' : cannot convert parameter 1 from 'const char [6]' to 'LPCWSTR'

1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

 

0 Kudos
Message 1 of 11
(6,778 Views)
Hi,

what is the returned status

status1=ibsic(gpib);

status2=ibcmd(gpib,"_?@3",4L);

status3=ibwrt(gpib,"C2",2L);

...

?

Hint: You can check the returned status variables (if not 0) with the GPIB error coding list. If the stuff works fine, status should be 0.

Best regards peter


0 Kudos
Message 2 of 11
(6,770 Views)
Hi,
 
You should use ibfind() but if you are going to use ibfinda() then you need to pass a value of type LPCSTR, therefore you need to cast "GPIB0".
 
also you should also capture the return values so you can handle the error conditions
 
Regards
Ray Farmer
Regards
Ray Farmer
0 Kudos
Message 3 of 11
(6,765 Views)

muellerp,

 

I just got in this morning, but give me a little bit and I can get you the return values. I will either attach the NI Spy or re-write my code to capture the values.



Message Edited by shard923 on 01-16-2008 07:48 AM
0 Kudos
Message 4 of 11
(6,753 Views)

Ray Farmer,

What the heck is that LPCSTR and how do I cast to it. Do I just do a <static_cast>LPCSTR ? Is that some sort of Microsoft data type? Thank you for your help.

 

 

0 Kudos
Message 5 of 11
(6,751 Views)

Hi,

You can declare a variable ie

LPCSTR device = "GPIB0";

gpib= ibfind(device);

 

or

gpib = ibfind ((LPCSTR)"GPIB0");

regards

Ray Farmer

Regards
Ray Farmer
0 Kudos
Message 6 of 11
(6,748 Views)

Ray,

When I use

gpib = ibfind(LPCWSTR(

"GPIB0"));

the project will compile but then NI Spy tells me that iberr is EVDR, or "Error connecting to driver or device" and then all the following commands then fail.

 


 

0 Kudos
Message 7 of 11
(6,742 Views)

muellerp,

I looked at the script with NI Spy and it told me all commands went through okay except my ibwrt. A coworker here had changed the PAD of the GPIB0 to 25 instead of 0, so the ibwrt wasn't working. Thank you for your help. I also found that despite what the manual and programming instructions say for the units I am working with, the "B" model and the "C" model are different in how they react to IEEE commands.

0 Kudos
Message 8 of 11
(6,741 Views)
To shard923:

I'm quite interested in the work you are doing on ADT-222B. Would you please contact me directly - that_mail@yahoo.com

Thank you,


0 Kudos
Message 9 of 11
(6,609 Views)

Ray,

I ended up fixing this by using a multi-byte character set in the properties drop-down of the project menu. After that, ta-da, no complaints from the compiler.

 

Message 10 of 11
(6,509 Views)