10-26-2018 01:25 PM
Hi all,
I am sure this should be a trivial question but I am not finding the answer. I am using a PCI 6221 card. This card has the capability to individually configure digital lines as inputs or outputs, it works fine in NIMAX. I am not seeing how to configure this programatically. Below a screenshot of what I tried, I do not understand why both options do not work. An error occurs on the first iteration of the second for loop. (operation could not be performed because the lines are reserved). This error happens only for the lines in port 0 which makes me think all the lines in a port should be either an input or output. In the examples I found a vi that configures a channel as a digital output and then proceeds to write to AND read from that channel. Should I just configure them all as outputs and then write to the lines that I want to be outputs and use a read block for the lines I want to read from (even though the line is configured as an output?)? Is the problem that I want to have digital inputs and outputs within a port? Ideally I would want all these lines in a task and then select each line individually to write to or read from. Can someone point me in the right direction to make this work? Any suggestions are appreciated. Let me know if I need to clarify anything. In the below screenshot, I of course run either option 1 or option 2, not both at the same time.
Solved! Go to Solution.
10-26-2018 02:57 PM
@ABSyn wrote:
Hi all,
I am sure this should be a trivial question but I am not finding the answer. I am using a PCI 6221 card. This card has the capability to individually configure digital lines as inputs or outputs, it works fine in NIMAX. I am not seeing how to configure this programatically. Below a screenshot of what I tried, I do not understand why both options do not work. An error occurs on the first iteration of the second for loop. (operation could not be performed because the lines are reserved). This error happens only for the lines in port 0 which makes me think all the lines in a port should be either an input or output. In the examples I found a vi that configures a channel as a digital output and then proceeds to write to AND read from that channel. Should I just configure them all as outputs and then write to the lines that I want to be outputs and use a read block for the lines I want to read from (even though the line is configured as an output?)? Is the problem that I want to have digital inputs and outputs within a port? Ideally I would want all these lines in a task and then select each line individually to write to or read from. Can someone point me in the right direction to make this work? Any suggestions are appreciated. Let me know if I need to clarify anything. In the below screenshot, I of course run either option 1 or option 2, not both at the same time.
There are a number of issues and maybe more than what I can spot right-off.
Option 1
You are indexing the tasks at the output so you are creating a bunch of tasks. Is that really hat you want?
Instead of "reserving" try to "Commit". I think reserving locks down all of the I/O and then nothing else can share that port.
Option 2
You are not indexing the task at the output of the For loop so only the last iteration task will be available at the output. Use a shift register if intend to put all of the DIO lines in a single task.
Generally when getting my hands on a new DAQmx widget I will got to MAX and configure a task the way I want it. Save the task as a name I can remember and save the task.
Then create a new VI and drop a DAmx task constant on the diagram.
Right-click it and choose "generate config and example"
The Wizard will script up code to match what worked in MAX.
Then I can kit-bash it as needed to scale it up.
Have fun!
Ben
10-26-2018 08:09 PM
The two options you show look the same as far as task configuration. Ben pointed out the only visible difference regarding task auto-indexing or not.
What specific error do you get? I recreated the option 1 code and the 1st two lines and names for both DI and DO, figuring that should be enough to tease out any port reservation errors. I ran it on a *simulated* PCI-6229, a real PCIe-6341, and then a simulated PCI-6221. No errors in any of those cases, though in fairness no tests used a real device from the same M-series family as yours.
I also tried to "commit" instead of "reserve" (note: commit will first reserve and then do some more things so it's actually a tougher test to pass). And then I tried starting all the tasks. And then I finally passed those tasks out from the loops to some code that would stop and clear them but only *after* the two config loops you started from. (This last thing was in case the compiler was auto-cleaning-up my tasks since I didn't wire them anywhere.)
For all those different cases, I couldn't make an error happen. The good news way of looking at it is that there should be a way for you to get it working too. Can you post actual code, preferably backsaved a few versions? (I'm still on LV 2016 for example). Also, what version of DAQmx do you have installed? My test machine is at 16.0.0f0
- Kevin P
10-28-2018 08:19 PM
Ben,
Thank you. That last suggestion did the trick. I did exactly that and it worked. It ended up being so trivial I almost feel dumb for asking the question in the first place.
Thanks everyone for the replies.
Arne