6

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!!

Sandy
  • 233
  • 1
  • 2
  • 18
  • Sandy, do you have a working code in C/C++ for handling this task? If you have, your chances of a helpful answer would increase if you include it in your question. – Arton Dorneles Feb 14 '16 at 14:15
  • @ArtonDorneles I have ni4882.h and ni4882.obj object file from standrad NI installation of the driver. Please do visit the link http://www.ni.com/download/ni-488.2-3.1.2/4360/en/ – Sandy Feb 14 '16 at 14:46
  • Did you try my answer? Drop me a line if I can do anything else for you. – Arton Dorneles Feb 19 '16 at 17:21
  • @ArtonDorneles I tried this option but i got type error exception – Sandy Feb 21 '16 at 14:23
  • Could you post the output of the error here? Maybe I can help you solve that. – Arton Dorneles Feb 21 '16 at 14:26
  • Error is as follows ret = library.viWrite(session, data, len(data), byref(return_count)) ctypes.ArgumentError: argument 2: : Don't know how to convert parameter 2 – Sandy Feb 21 '16 at 14:29
  • Are you reading data this way? `data = list(f.read())` ? If yes, try to switch to `data = f.read()`. – Arton Dorneles Feb 21 '16 at 14:46

1 Answers1

2

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.

Arton Dorneles
  • 1,629
  • 14
  • 18