01-17-2012 12:44 AM
I added printf("%s\n",Addr) after the GetCtrlVal function. It indicated that the Addr string was exactly what I typed in on the front panel.eg,"USB0::0x0957::0x0407::MY44034220::0::INSTR".
The error indicated "invalid resource reference"(VI_ERROR_INV_RSRC_NAME).
01-17-2012 01:09 AM
So it seems that the VISA help has changed - the constant is the same, but the 'translation' is different....?
My help says
Invalid resource string (parsing error). (VI_ERROR_INV_RSRC_NAME)
In any case: parsing error indicates an error with your string. If this string, entered via your UI, looks fine, i.e. the same as the working string entered directly in your code, all I can guess is that there might be a invisible character, either missing or superfluous. You can check this by using a breakpoint and inspect the Addr value in variable or memory view.
My suspicion would be a line feed or carriage return character
Ha - I just found out that you DO have an invisible character: Try to copy your text from the previous post, i.e. USB0::0x0957::0x0407::MY44034220::0::INSTR, into Notepad: you will see that at the end there is a character between INS and TR....
01-17-2012 01:53 AM
Thank you.There's no error. But as I pointed out in the very beginning, the instrument didn't act at all. eg, I send reset command to it but it didn't act. While I send commmand by MAX or Agilent IO Libraries, the instrument react normal.
01-17-2012 02:03 AM
The Addr string problem has been solved. Now the problem is in the command to be sent.
switch (event) { case EVENT_COMMIT: GetCtrlVal (panelHandle, PANEL_ADDR, Addr); GetCtrlVal (panelHandle, PANEL_COMMAND, Comm); //printf("%s\n",Addr); //printf("%s\n",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); errstat=viOpen (defaultRM, Addr, VI_NULL, VI_NULL, &vi); if(errstat != VI_SUCCESS) printf("viopen() Problem\n"); else{ printf("Open USB Dev just fine\n"); //errstat=viPrintf (vi, Comm); errstat=viPrintf (vi, "*RST\n"); if(errstat != VI_SUCCESS) printf("viprintf() Problem\n"); else printf("VisaWrite USB Dev just fine\n"); } viClose (vi); viClose (defaultRM); break; } return 0;
If I use errstat=viPrintf (vi, "*RST\n"), the instrument acts normal. If I use errstat=viPrintf (vi, Comm) instead, the instrument didn't act ,with no error.
01-17-2012 02:20 AM
The Addr string problem has been solved.
How did you solve it?
01-17-2012 02:25 AM
Concerning your command string: are you sure the command string Comm also includes a final "\n"?
01-17-2012 03:01 AM
About the Addr string format.AS you pointed out,the Addr string should be complete.There's a "?" between INS and TR in the Addr string at first.Secondly, the string cannot include "" .
Thank you very much. I'll do more debug to see the problem about the command.