LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Very Simple DIO with NI-DAQmx

I have a 6509 card that I am using to read/write static lines. This card requires NI-DAQmx and, despite the tutorials and examples, I am having difficulty deciding on the best way to use this. I have used traditional DAQ with other cards, and this was very simple. But the model for NI-DAQmx is generalized to address so many more complicated situations (tasks, etc) that I cannot quite grasp how the simplest situation should be handled.

For this application, all of the lines to control are static -- no handshaking, no clocking, nothing fancy. Some 8 bit ports are read, some are write. Each bit is completely unrelated to the others, so either I maintain a map of {port,bit} to named "lines", or else it seems like NI-DAQmx allows me to create
named "tasks" [? odd name] for each {port,bit}.

My question is: how to best use NI-DAQmx to control many independent static lines? How best to cleanly map individual lines to port/bit?

Thank you.
0 Kudos
Message 1 of 4
(2,636 Views)
Hey Mike,
Using DAQmx can be a bit of a shock to Traditional DAQ users, but it should be a rewarding transition. I have included two VIs that show different ways to control digital lines. The first creates two channels where each channel has only one bit (line) in the channel. The second creates tasks that can have multiple bits (lines). As you can see, you can control the direction of each line. By using one scenario or the other, you can write(read) to(from) multiple lines at a time or just one at a time. The choice is yours for your application.
Good luck!
Gavin G.
Applications Engineer
National Instruments
Download All
0 Kudos
Message 2 of 4
(2,636 Views)
Thanks Gavin. I think the part giving me the most fits is the need to "Start" a "Task". That isn't very intuitive for a static operation. Also, it doesn't appear to be necessary either.... since the original posting I have gotten things running without using a StartTask -- is this a problem?

Managing Tasks :
--------------
Admittedly there are dozens of ways to do this but...

I originally tried to dynamically Create a group of global tasks in a one-time "init" VI. A global BOOLEAN was used to indicate that "init" was complete. I could then use these tasks when needed. This appeared to work fine, but I found that the global tasks become stale when the "creating" vi stops running, which was inconvenient for my main application and associated debu
gging applications.

I ended up creating 12 Global NIDAQ Tasks in MAX; one for each 8 bit port. Then the application and the debugging panels can access all the bits without regard to initializing/creating "tasks". The named allocation of bits within the ports is handled with a enum control with an ordered set of values.

I haven't tried this next part, but it looks like I can export the 12 NIDAQ tasks in NI-MAX for making this easier to install.
0 Kudos
Message 3 of 4
(2,636 Views)
Hi Mike,

To answer your questions...

Start Task actually does more than just start the timeclock for multi-point operations. It also loads the task in memory if it hasn't been already, reserves the resources needed for the operation, etc, and this is necessary whether the operation is single or multi point.

You are correct in recognizing that explicitly calling Start Task is not necessary. This is the same for Stop Task and Clear Task. This is because NI-DAQmx calls these for you if you don't. Basically if the task hasn't been started prior to a Read or Write Task, NI-DAQmx implicity calls Start Task before the Read and before the Write if "auto start" is true. (The default for "auto start" is true on single point writes.) However, if you
are calling Write or Read in a loop, it is still recommended that you call Start Task and Stop Task explicitly outside of the loop for performance reasons. If Stop Task isn't called explicity, Stop Task is called implicity by Clear Task. And if Clear Task is never called before the top level of a VI hierarchy stops running, Clear Task is implicitly called on any still open tasks.

So if you want your tasks in your "creating" vi to not become stale, don't call Clear Task in your creating vi. Either call it in a "clean up" vi when your application ends or let NI-DAQmx call it implicity for you when the top level VI stops.

There is more info on state transitions in the NI-DAQmx help document installed with NI-DAQmx. You can find this doc from your Start menu in National Instruments > NI-DAQ > NI-DAQmx Help.

And yes, you can export NI-DAQmx tasks from MAX and import them on another computer.

Deborah Bryant
National Instruments
0 Kudos
Message 4 of 4
(2,636 Views)