clade / PyDAQmx

Interface to National Instrument NIDAQmx driver
Other
133 stars 55 forks source link

ArgumentError thrown at DAQmxFunctions->mafunction #7

Open mbiskach opened 10 years ago

mbiskach commented 10 years ago

I'm attempting to run PyDAQmx on Python 3.3 (32-bit), on a Windows 7 machine with LabVIEW 8.6 (32-bit) and NI-DAQ (9.2.1) installed.

During PyDAQmx installation, I had to use python 2to3.py -w . to upgrade all *.py files on latest version of source code downloaded from Github (version 1.2.5.2). I wonder if anyone else has got PyDAQmx installed and running for Python 3.3 using this approach? I had issues getting all of the modules in the PyDAQmx package installed using the published Python 3 install instructions.

The NIDAQmx.h version is Copyright 2003-2010.

After attempting to run any of the examples I get the same error message:

Traceback (most recent call last):
File "example.py", line 9, in <module>
analog_input.CreateAIVoltageChan("cDAQ1Mod1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,None)
File "<string>", line 3, in CreateAIVoltageChan
File "<string>", line 2, in function
File "C:\Python33\lib\site-packages\pydaqmx-1.2.5.2-py3.3.egg\PyDAQmx\DAQmxFunctions.py", line 23, in mafunction
ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type

example.py

from PyDAQmx import *
import numpy

analog_input = Task()
read = int32()
data = numpy.zeros((1000,), dtype=numpy.float64)

# DAQmx Configure Code
analog_input.CreateAIVoltageChan("cDAQ1Mod1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,None)
analog_input.CfgSampClkTiming("",10000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1000)

# DAQmx Start Code
analog_input.StartTask()

# DAQmx Read Code
analog_input.ReadAnalogF64(1000,10.0,DAQmx_Val_GroupByChannel,data,1000,byref(read),None)

print("Acquired %d points"%read.value)

It's tough for me to tell if this error is due to improper PyDAQmx package setup for Python 3...

Will attempt to install and run package on Python 2.7 to see if error still exists for me.

clade commented 10 years ago

Dear Michael,

In order to run example with Python 3.3, you need to use bytecode string instead of string. The conversion is not made automatically. In the example, replace "cDAQ1Mod1/ai0" by b"cDAQ1Mod1/ai0" and so on.

You wrote me that you had problem in getting all of the modules of PyDAQmx installed. Are you talking about the examples (which are not part of the module - and shoulb probably be in another folder) or about the main module (.py files in the PyDAQmx folder) ?

Regards, Pierre

I'm attempting to run PyDAQmx on Python 3.3 (32-bit), on a Windows 7 machine with LabVIEW 8.6 (32-bit) and NI-DAQ (9.2.1) installed.

During PyDAQmx installation, I had to use python 2to3.py -w . to upgrade all *.py files on latest version of source code downloaded from Github (version 1.2.5.2). I wonder if anyone else has got PyDAQmx installed and running for Python 3.3 using this approach? I had issues getting all of the modules in the PyDAQmx package installed using the published Python 3 install instructions.

The NIDAQmx.h version is Copyright 2003-2010.

After attempting to run any of the examples I get the same error message:

Traceback (most recent call last):
File "example.py", line 9, in <module>
analog_input.CreateAIVoltageChan("cDAQ1Mod1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,None)
File "<string>", line 3, in CreateAIVoltageChan
File "<string>", line 2, in function
File
"C:\Python33\lib\site-packages\pydaqmx-1.2.5.2-py3.3.egg\PyDAQmx\DAQmxFunctions.py",
line 23, in mafunction
ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type

example.py

from PyDAQmx import *
import numpy

analog_input = Task()
read = int32()
data = numpy.zeros((1000,), dtype=numpy.float64)

# DAQmx Configure Code
analog_input.CreateAIVoltageChan("cDAQ1Mod1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,None)
analog_input.CfgSampClkTiming("",10000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1000)

# DAQmx Start Code
analog_input.StartTask()

# DAQmx Read Code
analog_input.ReadAnalogF64(1000,10.0,DAQmx_Val_GroupByChannel,data,1000,byref(read),None)

print("Acquired %d points"%read.value)

It's tough for me to tell if this error is due to improper PyDAQmx package setup for Python 3...

Will attempt to install and run package on Python 2.7 to see if error still exists for me.


Reply to this email directly or view it on GitHub: https://github.com/clade/PyDAQmx/issues/7

mbiskach commented 10 years ago

Thanks, Pierre. I knew the solution was right in front of me! I think a reminder note could be added to the documentation about using bytecode strings in Python 3.

As for installing the PyDAQmx package in Python 3, let me provide some additional information:

  1. The package name parameter is missing from the setup parameters in setup.py so package is built as UNKNOWN instead of PyDAQmx. I just add the following around line 80 in setup.py:
name="PyDAQmx",
  1. Following the Python 3 installation procedure in installation.rst:
python 2to3.py -w setup.py
python setup.py build
python setup.py install

I then try to use the PyDAQmx

import PyDAQmx

results in:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".\PyDAQmx\__init__.py", line 3, in <module>
    from DAQmxTypes import *
ImportError: No module named 'DAQmxTypes'

However, if I run:

python 2to3.py -w .
python setup.py build
python setup.py install

it fixes all the import statements in the PyDAQmx package including line 3 from init.py:

from .DAQmxTypes import *

I'm not sure why relative imports are not fixed with the

use_2to3=True

flag set in setup.py. But explicitly running 2to3 on all the modules fixes the relative import statements and the PyDAQmx package is installed properly.

ejaywang commented 10 years ago

Thanks Pierre, solved my problem too!

fallen commented 9 years ago

I had the same issue about byte strings, maybe indeed it can be written somewhere in documentation :)