03-06-2009 07:12 PM
Hi,
I'm using Matlab 2008a to control an NI USB-6509 board. 2008a doesn't come with 6509 support out of the box so, as suggested here:
http://www.mathworks.com/support/solutions/data/1-68VOCU.html?solutio...
I added the following to my $MATLABROOT\toolbox\daq\daq\private\mwnidaqmx.ini
[USB-6509]
hasAnalogInput = false
hasAnalogOutput = false
hasDigitalIO = true
digitalPortSize = 8,8,8,8,8,8,8,8,8,8,8,8
digitalPortCap = 3,3,3,3,3,3,3,3,3,3,3,3
I can connect to the device and if I use the lower-level functions I can add all the ports lines (12 ports each with 8 lines).
However, things don't work as planned. Right now the main problem is that:
If I write to port2/line7 (labeled 1 on the NI port diagram) then this
seems to also send the signal to port5/line7 (labeled 2). So it's as
though lines 1 and 2 are crossed. This seems to work all the way down
so 3 and 4 are also crossed. I don't have a hardware problem since the
NI test utility works fine. Also, it looks like line numbers over 11 don't work at all. This makes no sense to me.
As an alternative, I would be happy to try coding this in Python. I have some code which appears to connect to the board but gives me an access violation when I try to read and write to it. I can post this code if anyone is a Python whizz. Alternatively, if anybody has working example code for Python dio please do send it my way.
Thanks!
Rob
Solved! Go to Solution.
03-09-2009 01:26 PM
03-09-2009 02:06 PM
Hi,
Thankyou, I wasn't aware of the NI DAQmx tools. I have just tried them and I can write correctly P5L7 via Matlab. I will look into using them and re-writing my code. I think there's a bug in the Mathworks data aqcuisition toolbox:
Since my first post I have tried using 2008b which should have support out of the box for the USB-6509. However, Only the 8 lines on Port 2 seem to work. When I write to Port 5 the outputs are sent to Port 2. So, P5L7 writes to P2L7. The code is super-simple and should "just work" but I only get pulses from the hardware line physically labelled as "1" on the breakout card. Line 2 (P5L7) doesn't do anything:
dio=digitalio('nidaq','dev1'); addline(dio,0:95,'out')
L=24;putvalue(dio.line(L),1);pause(0.3);putvalue(dio.line(L),0);
L=48;putvalue(dio.line(L),1);pause(0.3);putvalue(dio.line(L),0);
I have had this problem with the following NI DAQmx driver versions: 8.7.1, 8.7.2, 8.8, 8.9
Something weird is going on because sometimes Line 2 works and Line 1 does not. Once it even did things correctly. Usually, however, things
are as described above. I can only conclude there's a bug in Matlab.
Rob
03-10-2009 11:28 AM
Hi Rob,
I'm glad DAQmx tools can help. While I'm not familiar with the syntax required in MATLAB, I do know that when making DAQmx calls in C or any other language, we specify the port and line, not the direct pin on the pinout. When I say line, I am referring to one of the 8 inputs/outputs of a port. For example 5.7 corresponds to port 5, line 7 and is mapped out to pin 2 of the 6509. This may be something to take note of. Again, I'm not familiar with the Data Acquisition Toolbox so it may create a layer on top of our driver that maps the pins out to be called in a different fashion. I would recommend looking through the Mathworks documentation or see if they have any example programs.
03-10-2009 12:09 PM
Yep, it does have an extra layer and they seem to have their own dll. In the Matlab DA toolbox you first create an software object which interfaces with the board and then you add ports and lines to the object. You need not add all available ports and lines. So a "line" in the Mathworks toolbox corresponds to a particular port/line on the physical device. If you add ports and lines in the appropriate order then the lines in the Matlab object correspond to the physical output lines on the breakout box (which is rather nice). I've definitely understood this bit correctly as verified using the NI tools and the Test/Automation thingy . Furthermore, I've used Matlab for this sort of thing with other NI devices (e.g. PCI-6115) and it's worked fine. This problem with the USB-6509 is extraordinary. Either the Mathworks stuff is not adding the ports it claims to be adding or it's writing to the wrong ports having added them correctly. I haven't tried reading.
Rob