Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

matlab 6509

Solved!
Go to solution

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

0 Kudos
Message 1 of 5
(5,614 Views)
Solution
Accepted by topic author raacampbell
Hi Rob,

If I understand correctly, the pins of the USB-6509 are outputing in pairs (1&2, 3&4) rather than outputing on the single pin designated by the port/line. After pin 10, all lines corresponding to these pins are not operational. This behavior is not found in when using the Test Panel in Measurement and Automation Explorer, infact, you're seeing proper output behavior.

Since the Data Acquisition Toolbox v2.12 doesn't directly support the USB-6509, you edited your ini file per the knowledgebase article on the Mathworks website. This allows you to access the board but the behavior is not what's expected.

There are a few things that could be happening. You could be simply passing the wrong parameters to DAQmx or calling the wrong functions. I would recommend contacting The Mathworks and referencing the knowledgebase you used to get support for their software product (as you've identified this doesn't appear to be a hardware problem). 

You may find some help on some of our other forum threads, specifically this one: http://forums.ni.com/ni/board/message?board.id=250&message.id=10165

Finally, National Instruments has a product called NI-DAQmx Tools for specific integration into MATLAB. You may find success with this. http://zone.ni.com/devzone/cda/tut/p/id/3005
PBear
NI RF
Message 2 of 5
(5,588 Views)

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

 

 

0 Kudos
Message 3 of 5
(5,581 Views)

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.

PBear
NI RF
0 Kudos
Message 4 of 5
(5,564 Views)
> Again, I'm not familiar with the Data Acquisition Toolbox so it may create a layer on top of our driver

 

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
0 Kudos
Message 5 of 5
(5,562 Views)