I'm in the process of automating lab instruments. I have a requirement like function will send file/binary data via VISA GPIB from Host PC to instrument.
In Ni4882.h there is the following functions to transfer file/binary data in Visual studio 2010, and it is working. I have well versed in the sending command as GPIB string.
But I never came across sending the file through GPIB command.
These are functions I tried in c++. I used ni4882.obj file (have the definition of these functions) and created an application, So I was able to transfer a file PC to instruments. But I am not able to find equivalent functions in python
unsigned long NI488CC ibwrtfA (int ud, const char * filename);
unsigned long NI488CC ibwrtfW (int ud, const wchar_t * filename);
Could anyone please let me know the equivalent function in pyvisa or visa python package? --or-- any equivalent module to an alternative for this.
I browse through all the functions of pyvisa and visa, but I failed to find the equivalent functions.
Thanks in advance!!
You can try the method write_raw. Try out this code:
import visa
rm = visa.ResourceManager()
rm.list_resources() # ('ASRL1::INSTR', 'ASRL2::INSTR', 'GPIB0::12::INSTR')
ud = rm.open_resource('GPIB0::12::INSTR') #You need to specify your device here.
#Read the file into data
f = open('file.dat', 'rb')
data = list(f.read())
#Write file into device
ud.write_raw(data)
As alternative to write_raw
you can try write_binary_values or write_ascii_values. Both provide more settings if you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With