AnsweredAssumed Answered

Help: C++ app using VISA

Question asked by torete43 on Nov 2, 2008
Latest reply on Nov 5, 2008 by torete43
Hi! I need your help. First of all, congratulations for such a great forum and for the attention you provide to the final user.

I'm developing a C++ app using VISA in order to control some instruments over GPIB remotely. As a starting point, the app will capture the screen and transfer to the PC. If I succeed, I will add more capabilities to the app. I know there are some commercial solutions to do that, but It's a requirement from my company to have a propietary app. I have some questions cause it's my first time dealing with de VISA API. I would be grateful for some advice. Here we go:

1) VISA is supposed to be a standarized implementation, is there any difference between NI-VISA and Agilent VISA? I want to control some instruments from different vendors with just one VISA implementation, is this possible? Which one would you recommend?

2) Currently, I have both VISA's installed but I think Agilent's is working as primary. I'm using a PSA E4440A and following both NI-VISA and Agilent VISA documentation. If I try to reproduce some simple examples that comes with NI-VISA Docs over Agilent's library I get some errors from the compiler (MS VC++ 2005 Express Ed.). For example:

     viWrite(instr, "*IDN?\n", 6, &retCount)

In this case I get the error: Parameter 2 cannot be converted from 'const char [7]' to 'ViBuf'. I guess that SCPI commands have to be declared as ViBuf and cannot be passed directly as an array of char (string), Am I right?. So my question is, Why all the examples in NI-VISA docs refered to viWrite or viRead are written this way? Is it possible to do this with NI-VISA library but not with Agilent's? Anyway, I'm using the formatted IO viPrintf and viScanf to sending SCPI commands, as shown in Agilent Docs. Even though, I would like to know where can I find info about data types defined in VISA.

3) This question is related to event handling. The first version of the app is really simple: open sessions, query for the ID, fullscreen, capture screen and transfer gif. Here I show you some code (avoiding error checking wich is done trough status variable):

status = viQueryf(instr,"*IDN?\n","%100t",pb);
status = viPrintf(instr, ":display:fscreen on \n");
status = viPrintf(instr, ":mmem:store:screen 'C:/VISA.GIF' \n");
status = viQueryf(instr, ":mmem:data? 'C:/VISA.GIF' \n", "#%60000t", pr);

Although the program is simple, I have noticed some overlapping. Sometimes the gif is saved before the display was turned into full screen, sometimes the display doesn't appear as full screen or just the app hangs up. I suppose that the next operation starts when the previous one returns the status value and that value is returned when de SCPI command is written into the VISA's write buffer but not when the SCPI command is executed and finished by the instrument. Am i right? (Please let me know if there's anything wrong with my answers). I guess I should use event handling but... Does the events warn me if an instrument has completed succesfully a SCPI command and it's free for receiving another, or they just report that a viPrintf operation has written correctly the command into the buffer?

4) This is the most important point. I have problems with transfering the gif and opening in a windows viewer. This is the operation:   

status = viQueryf(instr, ":mmem:data? 'C:/VISA.GIF' \n", "#%60000t", pr);

where pr is a pointer to a string. I'm a little bit confused cause in some examples the format code appears to be %y,  %b, etc. Actually I have no clue on how to transfer the gif to the pc without loosing the gif format. I just know that the header is in the way #XZZZZ where X represents the size of ZZZZ and ZZZZ the size of the gif itself. Does anyone have a c++ code to do this task? Could you write it here?

5) Finally, I know that the VISA's write buffer is flushed on every access if the SCPI command is followed by the END terminator (\n). This is not the case of the read buffer. So, what would you recommend to get the read buffer flushed: using viFlush() or modifying the VI_ATTR_RD_BUF_OPER_MODE? Which is better?



THX in advance for your help. I hope you don't get angry for the amount of things I have written! If you prefer, I can separate every point in different threads. THX again and regards from Spain! ( sorry for my english   )  

Outcomes