PXI

cancel
Showing results for 
Search instead for 
Did you mean: 

Recommended approach for PXI control from Python

Solved!
Go to solution

Hello,

 

thanks for your time.

 

I'm not going far ...

 

#-*- coding: UTF-8-*-*

from ctypes import c_bool, c_int, c_double, c_char_p, byref, windll, cdll
from ctypes.util import find_library

def c_string(s):
return c_char_p(str(s).encode('utf-8'))

lib_name = find_library('nidcpower_32')
dll = cdll.LoadLibrary(lib_name)#C:\Program Files\IVI Foundation\IVI\Bin\nidcpower_32.dll
vi = c_int(0)
dll.niDCPower_InitializeWithChannels(c_string('PXI1Slot7'), c_string('0'), c_bool(True), c_string(''), byref(vi))

answer:

 

C:\WinPython-32bit-3.6.3.0Qt5\PycharmsProject\test\venv\Scripts\python.exe C:/WinPython-32bit-3.6.3.0Qt5/PycharmsProject/test/test.py
Traceback (most recent call last):
  File "C:/WinPython-32bit-3.6.3.0Qt5/PycharmsProject/test/test.py", line 13, in <module>
    dll.niDCPower_InitializeWithChannels(c_string('PXI1Slot7'), c_string('0'), c_bool(True), c_string(''), byref(vi))
ValueError: Procedure called with not enough arguments (20 bytes missing) or wrong calling convention

Process finished with exit code 1

 

 

 I don't find anything in the web about that. The PXI1Slot7 is an PXIe-4142

0 Kudos
Message 11 of 15
(1,801 Views)

cdll and windll are for two different calling conventions (how functions pass arguments and return values), which is what it seems to be complaining about. You should be using windll.

Message 12 of 15
(1,798 Views)

The code below works. thanks a lot.

#-*- coding: UTF-8-*-*

from ctypes import c_bool, c_int, c_double, c_char_p, byref, windll, cdll
from ctypes.util import find_library
import time

def c_string(s):
return c_char_p(str(s).encode('utf-8'))

lib_name = find_library('nidcpower_32')
dll = windll.LoadLibrary(lib_name)#C:\Program Files\IVI Foundation\IVI\Bin\nidcpower_32.dll
vi = c_int(0)
dll.niDCPower_InitializeWithChannels(c_string('PXI1Slot7'), c_string('0'), c_bool(True), c_string(''), byref(vi))
dll.niDCPower_ConfigureOutputFunction(vi, c_string('0'), c_int(1006))
dll.niDCPower_ConfigureVoltageLevel(vi, c_string('0'),c_double(3.1))
dll.niDCPower_Initiate(vi)
dll.niDCPower_ConfigureOutputEnabled(vi, c_string('0'), c_bool(True))

 

0 Kudos
Message 13 of 15
(1,793 Views)

Great, happy to help

0 Kudos
Message 14 of 15
(1,791 Views)

Adding some info in case anyone stumbles upon this thread... Some time after the first post some people started an open project to already wrap these NI drivers in Python. It can be found here:

 

https://github.com/ni/nimi-python

 

I haven't tried it myself but by the looks of it it tries to provide a Python interface for each and every one of the C-style functions in the original drivers. If you want to write something on top your code will look similar, but at least you won't have to deal with ctypes/cffi yourself.

0 Kudos
Message 15 of 15
(1,456 Views)