LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Write Problem (char)

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.

 

0 Kudos
Message 1 of 17
(3,435 Views)

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.

0 Kudos
Message 2 of 17
(3,431 Views)

 

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.

0 Kudos
Message 3 of 17
(3,427 Views)

Hi,

Can you give me the model and the reference of your materiel to see if you have an other parameters to send.

0 Kudos
Message 4 of 17
(3,421 Views)

Attached is the project file. It's a basic VISA Write program.Please review. Thank you.

0 Kudos
Message 5 of 17
(3,419 Views)

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.

0 Kudos
Message 6 of 17
(3,401 Views)

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

 

0 Kudos
Message 7 of 17
(3,397 Views)

My hardware is Agilent 33220A(functon generator).

0 Kudos
Message 8 of 17
(3,388 Views)
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?

0 Kudos
Message 9 of 17
(3,385 Views)

1) Your finding demonstrates the usefulness of error checking Smiley Wink

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?

0 Kudos
Message 10 of 17
(3,368 Views)