01-16-2012 04:07 AM
I used LabVIEW to bulid auto test system before. LV is really easy to learn but it's becoming much more complex when the system requires more function.So I turned to LabWindows. Now I encountered a problem about visa write commmand and visa open command. I guess the problem lies in the data type but I cannot make it clear.The main code is listed below:
ViSession defaultRM,vi;
static char Addr[100],Comm[100];
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (panelHandle, PANEL_ADDR, Addr);
GetCtrlVal (panelHandle, PANEL_COMMAND, Comm);
viOpenDefaultRM (&defaultRM);
viOpen (defaultRM, Addr, VI_NULL, VI_NULL, &vi); //there's a problem
//viOpen (defaultRM, "USB0::0x0957::0x0407::MY44034220::0::INSTR", VI_NULL, VI_NULL, &vi);//Running OK.
viPrintf (vi, Comm);//there's a problem
//viPrintf (vi, "*RST\n");//Running OK
viClose (vi);
viClose (defaultRM);
break;
}
return 0;
Will anyone help to point out the mistake?Thank you.
01-16-2012 04:23 AM
Hi,
maybe it already helps looking at the values of Addr and Comm using a breakpoint after the two GetCtrlVal commands: For example, does Comm include the "\n"?
Also, it would be useful adding some status/error checking, e.g. replace viOpen by status = viOpen and add a line checking if status != VI_SUCCESS; the return value status will help you in tracking down the error.
01-16-2012 05:01 AM
Thank you.I've done some debug.
I assigned "USB0::0x0957::0x0407::MY44034220::0::INSTR" to Addr and "*RST\n" to Comm in the GUI. Then run the program. There's no error or warning but the instrument didn't react at all. If I assigned the same var to Addr and Comm in the .c source code, without GUI for Addr and Comm, the instrument acted as predicted. So I doubt about the data type of Addr and Comm.
01-16-2012 05:11 AM
Hi,
Can you give me the model and the reference of your materiel to see if you have an other parameters to send.
01-16-2012 05:17 AM
Attached is the project file. It's a basic VISA Write program.Please review. Thank you.
01-16-2012 09:10 AM
Hi,
I need the model of your hardware (AGILENT 6020A for exemple). Can you tried to use the VISA TEST PANEL to discuss the materiel.
01-16-2012 09:22 AM
Test this code:
int CVICALLBACK SendCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViStatus errstat; ViSession defaultRM,vi; static char Addr[100],Comm[100]; switch (event) { case EVENT_COMMIT: GetCtrlVal (panelHandle, PANEL_ADDR, Addr); GetCtrlVal (panelHandle, PANEL_COMMAND, Comm); errstat=viOpenDefaultRM (&defaultRM); if(errstat != VI_SUCCESS) printf("viOpenDefaultRM() problem\n"); else { errstat=viOpen(defaultRM, "USB0::0x0957::0x0407::MY44034220::0::INSTR", VI_NULL,VI_NULL, &vi); if(errstat != VI_SUCCESS) printf("viOpen() problem\n"); else printf("Opened USB0::0X957 just fine\n"); } viClose(vi); break; } return 0; }
01-16-2012 08:08 PM
My hardware is Agilent 33220A(functon generator).
01-16-2012 08:20 PM
int CVICALLBACK SendCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { ViStatus errstat; ViSession defaultRM,vi; static char Addr[100],Comm[100]; switch (event) { case EVENT_COMMIT: GetCtrlVal (panelHandle, PANEL_ADDR, Addr); GetCtrlVal (panelHandle, PANEL_COMMAND, Comm); errstat=viOpenDefaultRM (&defaultRM); //if(errstat != VI_SUCCESS) printf("viOpenDefaultRM() problem\n"); //else { errstat=viOpen(defaultRM, "USB0::0x0957::0x0407::MY44034220::0::INSTR", VI_NULL,VI_NULL, &vi); if(errstat != VI_SUCCESS) printf("viOpen() problem\n"); else printf("Opened USB0::0X957 just fine\n"); } viClose(vi); break; } return 0; }
This code is OK.
If I replace the addr "USB0::0x0957::0x0407::MY44034220::0::INSTR" by editing in the GUI, (errstat=viOpen (defaultRM, Addr, VI_NULL, VI_NULL, &vi), there's an error——Invalid resource reference.Where is the problem?
01-17-2012 12:24 AM
1) Your finding demonstrates the usefulness of error checking
2) I could not find the exact error message you gave, the closest I could find in my help file is "Invalid resource string"; it indicates, as expected, an error in your address string; so what does your Addr string look like after the GetCtrlVal function?