01-12-2010 11:55 AM
Based on the example in http://zone.ni.com/devzone/cda/tut/p/id/8911 I am trying
to access the LIN functions of the NI USB-8476 in the following python script:
#!/usr/bin/env python
from ctypes import *
dll = cdll.LoadLibrary("nican.dll")
linName = c_char_p("LIN0")
linPtr = c_void_p()
dll.ncOpenObject.argtypes = [POINTER(c_char_p), POINTER(c_void_p)]
returnValue = dll.ncOpenObject(linName, linPtr)
resulting in the following error message:
Traceback (most recent call last):
File "./demo.py", line 15, in <module>
returnValue = dll.ncOpenObject(byref(linName), linPtr)
ValueError: Procedure called with not enough arguments (8 bytes missing) or wrong calling convention
Thanks for any help.
01-12-2010 04:44 PM
Noticing that I had skipped over the ncConfig function call, thinking this may be a prior
error I tried to set up the ncConfig call according to the ctypes tutorial at
http://python.net/crew/theller/ctypes/tutorial.html. I have been unable
to make the ncConfig function recognize the parameter arrays:
#!/usr/bin/env python
from ctypes import *
dll = cdll.LoadLibrary("nican.dll")
linName = c_char_p("LIN0")
linNumAttr = c_ulong(2)
NC_ATTR_START_ON_OPEN = c_ulong(0x80000006)
NC_ATTR_BAUD_RATE = c_ulong(0x80000007)
class linAttrIdList(Structure):
_fields_ = [("ncAttrStartOnOpenID", c_ulong),("ncAttrBaudRateID", c_ulong)]
linAttrIdList.ncAttrStartOnOpenID = NC_ATTR_START_ON_OPEN
linAttrIdList.ncAttrBaudRateID = NC_ATTR_BAUD_RATE
class linAttrValueList(Structure):
_fields_ = [("ncAttrStartOnOpen", c_ulong),("ncAttrBaudRate", c_ulong)]
linAttrIdList.ncAttrStartOnOpen = 0
linAttrIdList.ncAttrBaudRate = 9600
linPtr = c_void_p(0)
returnValue = dll.ncConfig(linName, linNumAttr, linAttrIdList, linAttrValueList)
this causes python output:
Traceback (most recent call last):
File "./demo.py", line 23, in <module>
returnValue = dll.ncConfig(linName, linNumAttr, linAttrIdList, linAttrValueList)
ctypes.ArgumentError: argument 3: <class 'TypeError'>: Don't know how to convert parameter 3
Again, any help is appreciated, especially any examples of correct python usage of nican.dll.
01-14-2010 11:20 AM
Hi ADLMB,
Unfortunately the second link you posted is broken. Also, Python is not one of the languages that R&D tests with when designing the NI-CAN driver so there may be more issues like this moving forward with Python. I would encourage you to consider using a more widely adopted language. Looking at the NI-CAN readme, you can use LabWindows/CVI, Visual Basic 6.0, Microsoft C/C++ 6.0 or Borland C/C++. There may be someone of the forums with the specialized knowledge you need, good luck.
10-03-2011 08:41 AM
Dear,
About the access of the nican.dll driver from 'Python'
Is there already a solution for it.
We plan to use the NI USB-8473s as hardware interface an drive from a Python program ?
I also suffer with the same issue like described above here
Thank you for an update,
Wouter
10-05-2011 11:07 PM
Hello,
As mentioned above, Python is not one of the languages R&D tests when they design the CAN driver. Again, any language listed in the readme can be used. I've also attached a few other documents you might find useful as well as the documents linked above.
Introduction to Scripting in Perl, Python and Tcl
http://zone.ni.com/devzone/cda/tut/p/id/8910
Advanced Scripting in Perl, Python and Tcl
http://zone.ni.com/devzone/cda/tut/p/id/8911
Call Perl and Python Scripts from LabVIEW
http://zone.ni.com/devzone/cda/tut/p/id/8493
I hope this helps! Good luck programming!
Jordan
05-24-2012 09:45 AM
Hello all,
Have you had any luck with this? I am attempting to use the USB-8473 for monitoring CAN traffic, and would be greatful for any help.
Thank you