Jump to content

Multiple DAQ writes Efficieny


Recommended Posts

Hello,

 

I have created a vi that controls multiple writes (individually) by a switch. I have it so one individual switch controls one individual write (And is linked to individual clear, stop, error daqmx blocks). I do not think this is efficient as it takes about 4-6 seconds for the switch to actually write (True or False). 

 

So, I was wondering if someone could help me make my code more efficient so it would run a bit faster.

 

Thank you

Digital Outs fine.vi

Link to comment

That example can only write to one line at a time since the channel line entering through that while loop only contains one line (At least that is what I think it does).

 

However, I think the reason why my code is inefficient is because I am stopping and clearing every time in my while loop. And my stop button logic has way to many not gates I could probably combine it into one not gate and send that out to multiple writes.

 

Is that something that would fix my inefficiency? Or could it be that I have a fatal flaw in my program that I am not realizing through this example and my program.

Edited by pkeny
Link to comment

However, I think the reason why my code is inefficient is because I am stopping and clearing every time in my while loop. 

Yes

 

 And my stop button logic has way to many not gates I could probably combine it into one not gate and send that out to multiple writes.

 

Is that something that would fix my inefficiency? 

No

 

Use a DAQ Assistant (1 for each device) in a loop.  Its a beginners friend (and sometimes advanced users).  It automatically sets up things for you so you don't have to worry about starting and stopping every loop.  If possible write to the whole port at the same time.

 

Hint:

post-549-0-59932200-1436994029.png

  • Like 1
Link to comment

Thank you guys for your answers,

 

After moving my stop, clear, and error daq blocks to outside the loop, the program now is able to switch on and off in about a second. 

 

I have been told using daq assistant is a very bad idea from other people. They tell me they always get errors and using daq accomplishes the same task as using daq assistant but more efficiently (I'm probably not using daq correctly so using daq assistant might be better). So, anyways I really want to learn efficient use of daq.

Link to comment

Thank you guys for your answers,

 

After moving my stop, clear, and error daq blocks to outside the loop, the program now is able to switch on and off in about a second. 

 

I have been told using daq assistant is a very bad idea from other people. They tell me they always get errors and using daq accomplishes the same task as using daq assistant but more efficiently (I'm probably not using daq correctly so using daq assistant might be better). So, anyways I really want to learn efficient use of daq.

 

When starting out with simple tasks, get a task to work with the assistant.  Then copy it and open the front panel to convert it to a VI and poke around in the Block Diagram.  Basically ready-made example code for your simple application which will help you understand how to make more complex operations.

  • Like 1
Link to comment

That example can only write to one line at a time since the channel line entering through that while loop only contains one line (At least that is what I think it does).

 

However, I think the reason why my code is inefficient is because I am stopping and clearing every time in my while loop. And my stop button logic has way to many not gates I could probably combine it into one not gate and send that out to multiple writes.

 

Is that something that would fix my inefficiency? Or could it be that I have a fatal flaw in my program that I am not realizing through this example and my program.

 

No, that example writes to many lines at the same time. Look at the channel input: Dev1/port0/line0:7. That means that the "channel" is 8 lines. The input being an array goes along with this. Writing all the lines at the same time should be more efficient that writing them individually.

Edited by infinitenothing
Link to comment

No, that example writes to many lines at the same time. Look at the channel input: Dev1/port0/line0:7. That means that the "channel" is 8 lines. The input being an array goes along with this. Writing all the lines at the same time should be more efficient that writing them individually.

Ah, thank you for clarifying that.

 

I believe I have made a much more efficient daq VI. 

 

However, I have a problem that I cannot figure out. In this VI, I have made a task that includes 8 lines. Then I have a boolean array of push buttons which will toggle the write data on/off. I also have a stop button that will end the while loop and stop writing. However, I want to make it so that the when the user presses the stop button, it will reset all the boolean switches to off (false).

 

So, in order to do that I made an event structure that contains a local variable for the boolean switches. However, for some reason when the timeout is at 5ms and I press the stop button it switches all the boolean switches to on (true). But, if I make the timeout at 1ms and I press the stop button it switches all the boolean switches to off (false), which is what I want.

 

Can someone explain to me why it is doing this, and maybe what would be a better way in accomplishing my task?

 

Thanks

Digital Outs.vi

Link to comment

To me, it seems that the logic is correct. When the stop button is pressed it returns a value of true. So I send it through a not gate, which will make it false. Then use that false value to initialize an array containing all false values with the same size as the number of elements in the switch array.

 

Next, I send it to the event structure which will execute if the stop value changes. So when the stop value changes, it will give a false value to the boolean switch array's local variable, which should set them all to false.

 

I cannot understand why it would set them to true. And especially I cannot understands why it would set them to true if I change the timeout constant to 5ms, versus 1ms.

 

What do I seem to be missing in my thinking?

 

But, regarding the picture with the conditional event logic. Can someone explain to me the shift register's role in that? I somewhat understand how shift registers work but I am unable to figure out how to incorporate them into a program. I know that they are used to pass data along a for loop, and they can store previous iteration values.

Edited by pkeny
Link to comment
  • Your VI is going to read the stop button (False)
  • then invert that (True)
  • make an array from that
  • Sit at the edge of the event structure for a bit
  • Lets say you press stop 2 ms into the event structure wait—you have an array of true waiting at the incoming edge of the event structure. That true is going to go into your "data array".
  • The next iteration starts, the "true" at the stop control is read at the begging of the loop, you wait and execute the timeout event

You can verify the above sequence if you are patient and set a really long timeout (~30 seconds) and turn on highlight execution

 

In the picture, the shift register is just a way to make the first iteration different from all the others. On the first iteration, the timeout is 0. All other iterations have a timeout of -1.

 

Most of us like trigger our actions based on events rather than letting the timeout lazily pick up changes as needed. To that end, you can create an event that will start executing as soon as your "data" array changes.

 

Also, your DAQmx clear and stop are being performed in the wrong order. Follow the examples.

Edited by infinitenothing
Link to comment

Thank you Infinite,

 

I could not figure out how to setup my event structure so that it will execute when my data array changes, and it will still set the local variable to false. However, I found a workaround using a case structure instead of an event structure. The case structure will occur when the stop button is pressed and then it will set the local variable to false.

 

Now, I have another question, hopefully this is the last one. 

When I open my program my boolean array is not initialized on the front panel. It is grayed out. So, the program will have an error since my task contains 8 lines, and when the boolean array is grayed out is has zero lines. 

 

How can I make it so when the VI file is opened, it will have all eight, false initialized boolean array, versus a grayed out boolean array. I have attached a picture of my front panel when I open the file.

 

 

 

 

post-53751-0-41252000-1437317840.png

post-53751-0-29554800-1437317847.png

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.