Instrument Control (GPIB, Serial, VISA, IVI)

Showing results for 
Search instead for 
Did you mean: 

Difference between viWrite and viPrintf?

Go to solution

I know there is the option of formatting with viPrintf, but does it communicate with instruments the same way that viWrite does? Also is there any advantages to using one or the other? Any input appreciated I'm new to using the VISA library.

0 Kudos
Message 1 of 3
Accepted by topic author gflores21

viWrite sends a string as it is, viPrintf  constructs a string in a similar way a printf does it in C.  viPrintf is roughly equivalent to a sequence sprintf (to make the string) and viWrite (to send it).   Any error is more difficult to debug with viPrintf as you don't see the final string being sent therefore I would recommend using only vi Write.

It is said in the Visa reference manual:

"The viPrintf() operation sends data to a device as specified by the format string. Before
sending the data, the operation formats the arguments in the parameter list as specified in the writeFmt string. The viWrite() operation performs the actual low-level I/O to the device.
As a result, you should not use the viWrite() and viPrintf() operations in the same

I'm not sure to understand the reason for such limitation, looks like viPrintf uses some intermediate internal array to buffer the data before it is sent.



Message 2 of 3

Thank you very much! It makes a lot more sense now the way you put it. I was trying to find some direct comparison somewhere, but just couldn't so I thought I would ask here.

0 Kudos
Message 3 of 3