Angel Posted January 31, 2005 Posted January 31, 2005 Hi, I am trying to create some functions that will people control intruments (osciloscopes, signal generators, spectrum analyzers, etc) through VISA and GPIB. To do so I am trying to call the visa32.dll from AutoIt by means of DllCall. However I am having trouble with this as I don't seem to be calling the functions properly as I do not get the proper responses from the DLL. I've reviewed my code several times but I can't see what I am doing wrong, other than the fact that some of the paremeters are supposed to be unsigned integers but I am telling DllCall that they are integers. So I will post here the original C calls to the functions (which I've used and work in C) and my "AutoIt equivalents". I hope that someone can spot my mistake and help me finish this which I think would be of great use for the "lab rats" like me which are using AutoIt :-). The code is a bit long but I've tried to comment a lot. I've put the functions that I want to call followed by the "translation" using C types (like int, char, etc). Then I put an example that works in C. Here I go: The C- code: #cs ; The C code from wich this was copied: // First some typedefs and #defines required to understand the function prototypes typedef unsigned long ViUInt32; typedef ViUInt32 ViObject; typedef ViObject ViSession; typedef ViUInt32 ViAccessMode; typedef signed long ViInt32; typedef ViInt32 ViStatus; #define VI_NULL (0) // Then the function prototypes themselves // viStatus viOpenDefaultRM (*viSession) => signed int viOpenDefaultRM(*unsigned long) // viStatus viOpen (viSession, char*, viAccessMode, ViUInt32, *viSession); => signed int viOpen(unsigned long, char*, unsigned long, unsigned long, *unsigned long) // viStatus viQueryf (viSession, char*, char*, ...); => like fprintf(fid, command, format_string, params...) // viStatus viClose(viSession) // And the example code int int_instr; char s_out[255]; errStatus = viOpenDefaultRM (&DEFAULT_RM); errStatus = viOpen (DEFAULT_RM, "GPIB0::20::0", VI_NULL, VI_NULL, &int_instr); errStatus = viQueryf (int_ret, "*IDN?\n", "%s", s_out); viClose(int_ret); #ce This small example gets the "GPIB ID" of the instrument in address 1. Here is the same code in AutoIt: expandcollapse popupGlobal Const $VI_NULL = 0 ; VISA variables Dim $DEFAULT_RM = 0 Dim $int_instr = 0 Dim $s_out = "" Dim $v_results ;- Open VISA RESOURCE MANAGER ; errStatus = viOpenDefaultRM (&DEFAULT_RM); ; signed int viOpenDefaultRM(*unsigned long) $v_results = DllCall("visa32.dll", "int","viOpenDefaultRM", "int_ptr",$DEFAULT_RM) DebugMsg("@error = " & @error) DebugMsg("errStatus = " & $v_results[0]) $DEFAULT_RM = $v_results[1] DebugMsg("$DEFAULT_RM = " & $DEFAULT_RM) ;- Open the INSTRUMENT CONNECTION ; errStatus = viOpen (DEFAULT_RM, "GPIB0::20::0", VI_NULL, VI_NULL, &int_instr); ; signed int viOpen(unsigned long, char*, unsigned long, unsigned long, *unsigned long) $v_results = DllCall("visa32.dll", "long","viOpen", "long", $DEFAULT_RM, "str","GPIB::1::0", "long",$VI_NULL, "long",$VI_NULL,"long_ptr",$int_instr) DebugMsg("@error = " & @error) DebugMsg("errStatus = " & $v_results[0]) $int_instr = $v_results[1] DebugMsg("$int_instr = " & $int_instr) ;- Send QUERY to instrument and get ANSWER ; errStatus = viQueryf (int_instr, "*IDN?\n", "%s", s_out); ; signed int viQueryf (unsigned long, char*, char*, char*); ;errStatus = viQueryf (h_instr, s_command, "%s", string); $v_results = DllCall("visa32.dll", "int","viQueryf", "int",$int_instr, "str","*IDN?", "str","%s", "str", $s_out) DebugMsg("@error = " & @error) DebugMsg("errStatus = " & $v_results[0]) $s_out = $v_results[1] DebugMsg("$s_out = " & $s_out) ;- Close INSTRUMENT Connection ; viClose(int_instr); $v_results = DllCall("visa32.dll", "int","viClose", "int",$int_instr) DebugMsg($v_results) $errStatus = $v_results[0] Func DebugMsg($s_msg) MsgBox(0,"Debug",$s_msg) EndFunc When I run it I do not see any @error problems but when I get to the query I get an error. Even before that I see that the call to viOpen sets $int_instr to the same value as the call to viOpenDefaultRM sets $DEFAULT_RM, which cannot be, as they are suposed to be handles to different things. So does someone see what I am doing wrong. I really think that having VISA and GPIB control in AutoIT would be great! Thanks in advance, Angel
Angel Posted January 31, 2005 Author Posted January 31, 2005 I've found the source of the problem. As usual I had not properly read the documentation. I really should listen to Valik when he gives me some advice!The problem was that DllCall returns a copy of ALL the parameters of the function! I thought that it only returned a copy of the modified parameters!I think that this should be put in bold in the documentation :-)Cheers,Angel
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now