ni.com is currently experiencing unexpected issues.

Some services may be unavailable at this time.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Why Do Digital Writes Only Work Occasionally? - Use Different Method?

We are making an application that relys on setting digital outs on an NI card.  I am using VB.net to program.  Here is an example of what I am doing.
 
        doTask = New Task()
        doTask.DOChannels.CreateChannel("Dev1/port1/line0", "l0t", ChannelLineGrouping.OneChannelForEachLine)
        awriterS = New DigitalSingleChannelWriter(doTask.Stream)
        awriterS.BeginWriteSingleSampleSingleLine(True, s0, hSt("Line 0 set to " & s0.ToString), Nothing)
        doTask.WaitUntilDone()
        doTask.Dispose()
 
        doTask = New Task()
        doTask.DOChannels.CreateChannel("Dev1/port1/line1", "l1t", ChannelLineGrouping.OneChannelForEachLine)
        awriterS = New DigitalSingleChannelWriter(doTask.Stream)
        awriterS.BeginWriteSingleSampleSingleLine(True, s1, hSt("Line 1 set to " & s1.ToString), Nothing)
        doTask.WaitUntilDone()
        doTask.Dispose()
 
This seems like the simplest way to change a digital out.  However, this will only work half of the time.  Half of the time it will perform the write, do the callback, and the digital out will not have been changed!
 
Is there a different method that I can use to make sure the write always works?  This application NEEDS to do what I tell it to every time.
Thanks for the help
0 Kudos
Message 1 of 4
(3,988 Views)

HI COD3 MONK,


Welcome to the NI discussion forums. One suggestion I would have would be to put both digital output writes in the same task. One task can have multiple channels (or digital lines in this case). Doing so can simplify your code and prevent the need to wait for one task to complete before the next task can be created and executed.
I would take a look at the examples referenced in the following DevZone Article:


Using NI-DAQmx in Text Based Programming Environments

Examples located at:
C:\Program Files\National Instruments\MeasurementStudioVS2005\DotNET\Examples\DAQmx or C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DotNET2.0

Folders named VB contain Visual Basic.NET examples, and folders named CS contain C# examples.  One example that shows a multiple digital output VB .Net example is located at: (one of the two paths above)\Digital\Generate Values\WriteDigChan\vb

Another suggestion would be to use the synchronous function WriteSingleSampleSingleLine as opposed to the asynchronous write BeginWriteSingleSampleSingleLine. Is there a reason that you are using the asynchronous write?  Combining the first and second suggestion you could use a function like WriteSingleSampleMultiLine to write to all of your digital lines in one task.  This is the way it is done in the example program mentioned above.


Hope this helps,

Jared  T.
 

Jared T.
0 Kudos
Message 2 of 4
(3,949 Views)
or do the following:

Create a workerThread which processes DigitalOut Jobs (by sending the data to a DOAdapter class)
Create a JobManagement Thread to manage which jobs can be send parallel
and create a Writer class which is created by defining its write ports and which has private variables with the target ports

then you can do
_DigOut = new DigitalOut(sHardwarePorts)
YourWriter = DigitalOut.NewWriter(new Integer() {1,2,3,4,5,6,7} )

and then a
YourWriter.Write( new Boolean() {True, True, False, False, True, True, False})
would do the job.

can contact me if this way would be interesting.
so you have 1 DigitalOut task, managing all Ports for digital out, and many small objects, with which you can  write to some ports.
Its relative easy to create some kind of Bus system that way, where e.g. you cna register bits 0-7 for 8 Writers, and Writer0 has CS Bit 8, Writer1 has CS bit 9 ...
0 Kudos
Message 3 of 4
(3,916 Views)

Wow.  Thanks for the suggestions.  The second sounds a little too complicated 0.0.

I have been using the first method.  Instead of writing asynchronously I am simply writing the task synchronously.  I think I was having issues running a thread that was running the digiwrites asyncronously.  Now im having my thread simply write the lines and it seems to be alot more reliable.

0 Kudos
Message 4 of 4
(3,909 Views)