Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Setting a Discrete? (porting from EasyIO to DAQmx)

Solved!
Go to solution

Hey,

I am porting a couple of old LabWindows libraries to use DAQmx for setting/reading analog and discrete signals. These are used to set or read signals individually by various applications.

Each of these two libraries use an ini file which states the configuration of the physical port + device etc. required, similarly maybe to how MAX stores virtual channels.

The reason I have to continue using my own lookup method is that applications have been written to set/read signals by both a signal name string (as stated in the ini file) and by an ID (number in the ini file). For example discretes can be set in an application by iterating a range of discrete ID numbers in a for loop.

If it was possible to associate in MAX an ID number with a virtual channel name I could drop the ini files altogether and just create MAX configurations for each of the systems that have applications that use these libraries.

 

Anyway, I am still at a loss as to how to replace for example the EasyIO function WriteToDigitalLine which would set an individual bit on a port to a particular logic state to the DAQmx equivalent.

 

I understand and have written code to create a task, to create a channel for the individual signal, to start the task, but do not know which function would be used to actually set an individual discrete to 1/0 as WriteToDigitalLine would.

 

I am having to learn this new method and re-write code just because a replacement card does not support Traditional DAQ.

 

Anyone have a code snippet to say set a discrete to a logic 1....seems a simple thing to ask but I have wasted hours so far.

0 Kudos
Message 1 of 5
(4,611 Views)
Since you are using LabWindows, did you look at any of the examples such as WriteDigChan? In LabWindows, select Library>DAQmx>Write Functions. There are several functions such as DAQmxWriteDigitalLines, DAQmxWriteDigitalScalarU32, etc. There is help associated with each function.
Message 2 of 5
(4,602 Views)

Thanks for your reply.

 

Yes I have looked at the various functions listed such as DAQmxWriteDigitalLines but as they seem to set 8 lines of a port at once I wondered if it was possible to find a function which affects just 1 bit of a port. Of course I could record all values set on a particular port so that when another bit on the same port is changed I send the whole port's channel state information at once, keeping the previously set values.

 

Is this what is required I wonder? There is also the extra parameter # Samples Per Channel on these functions. This doesn't seem relevant to just setting a line on a port from logic 0 to logic 1 so I guess just set this to 1?

 

The CVI examples set all bits on a port rather than show how to set just an individual bit which is what I would like.

0 Kudos
Message 3 of 5
(4,597 Views)
Solution
Accepted by AndyJD
WriteDigitalScalar is for a single bit. You can also use the WriteDigitalLines. If you only have a single line in the task, then you just have to pass a 0 or 1. Just because the functions are capable of writing to multiple lines, does not at all mean that you have to write to multiple lines. It's the same for the functions where you pass a Boolean array. The array can contain 1 or many elements.
Message 4 of 5
(4,594 Views)
Great, thanks very much. Array of 1 element !
0 Kudos
Message 5 of 5
(4,590 Views)