wrapper - Using NI-VISA with Python: error code -1073807343 in viFindRsrc -


i'm working in python , have installed lastest version of ni-visa. i'm using ctypes package in order load visa32.dll installed ni-visa.

i used both ni-visa documentation, the following page base code.

i know of pyvisa wrapper , using find_resources function return instruments connected. however, not wish use wrapper , rather use visa dll file directly.

i've been browsing pyvisa code see how it, , tried learn it, seems still don't it.

here current unfinished code:

import sys ctypes import * visa = windll.loadlibrary("visa32.dll")  resourcemanagerhandle = c_int(0) visa.viopendefaultrm(byref(resourcemanagerhandle))  instr_list = c_ulong(0) nb = c_ulong(0) desc = create_string_buffer(128)  print(visa.vifindrsrc(resourcemanagerhandle,                       "?*instr",                       byref(instr_list),                       byref(nb),                       byref(desc))) # previous line prints: -1073807343  print(instr_list) # previous line prints: c_ulong(0) 

i've been trying find meaning of error code -1073807343 (4000ffef in hex) on internet , though have found forum threads on national instruments forums, still don't quite understand means.

i welcome advice, guidance or link towards relevant information.

the literal "?*instr" creates str object, unicode in python 3. ctypes converts unicode string wchar_t *. on windows, wchar_t 2 bytes, ctypes passes pointer utf-16 encoded buffer "?\x00*\x00i\x00n\x00s\x00t\x00r\x00". bear in mind function expects null-terminated string.

to pass byte string instead, prefix literal b create bytes object, i.e. use b"?*instr".

to prevent mistake passing unnoticed, define function pointer's argtypes. ctypes raise argumenterror if unicode str argument passed parameter that's defined c_char_p.

from ctypes import *  visa = windll("visa32.dll") # or windll.visa32  def vi_status_check(vi_status, func, args):     if vi_status < 0:         raise runtimeerror(hex(vi_status + 2**32))     return args  visa.viopendefaultrm.errcheck = vi_status_check visa.viopendefaultrm.argtypes = [pointer(c_uint32)] visa.vifindrsrc.errcheck = vi_status_check visa.vifindrsrc.argtypes = [c_uint32,          # sesn                             c_char_p,          # expr                             pointer(c_uint32), # findlist                             pointer(c_uint32), # retcnt                             c_char_p]          # desc  rm_session = c_uint32() visa.viopendefaultrm(byref(rm_session))  expr = b"?*instr"     instr_list = c_uint32() nb = c_uint32() desc = create_string_buffer(256)  visa.vifindrsrc(rm_session,                 expr,                 byref(instr_list),                 byref(nb),                 desc) 

the ni-visa programmer reference manual says on page 5-30 instrdesc should @ least 256 bytes.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -