LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reset an Array


@Ray1981 wrote:

 

Next i will see if i can fix this to a shift register 🙂


Yes, but that code has very little to do with the picture you showed. As I said, you can use select with the feedback node too, so you don't really need a shift register. I would use a shift register thought, so you can tap into it for saving (see below).

 

Do you want to to reset the array to an empty array or do you want to keep the size the same, but have all elements zero? In the second case, multiplying with zero is easier than what you are currently doing. I think you actually want to reset it to zero length, though.

 

Your code has serious problems overall, for example the case structure in the upper middle has basically the same code in both cases with the only difference being a 0 or a 1 input. If you would remove the case structure and only keep the TRUE case, nothing would change. Simplify! How many times do you think you need to calculate "boolean to 0,1" from the same value in parallel? Once is enough! You can branch the wire afterwards instead.

 

Shouldn't these dll calls occur in a certain order? Why not line them up using the error wires?

 

There are still race conditions everywhere due to blatant overuse of local variables. Just tap into the array from the shift registers instead of reading from a local variable.

0 Kudos
Message 11 of 19
(3,008 Views)

First RavensFan his code seems to do what I want. But I like to take the advise from Altenbach as well to make the code better and less CPU demanding. The sad thing is I don't understand all the comments exactly.

 

Yes all I wanted is to make the array empty and not all the existing elements 0. 

If I change the Upper Middle case as you suggested my I/O keeps on when the program will be shut down therefore I thought i had to make it as it is.

 

With the three dll calls in the upper middle case all I wanted that 3 leds turned on here on my I/O board thats all.

 

If I try to recreate RavensFan his code it doesnt work the same as his code. This trully shows that i mis understand somthing although i think i see what it is. The outer tunnel looks different as his. And i dont know why and how to change that. It keeps having a very small white dot inside the outgoing tunnel.

0 Kudos
Message 12 of 19
(3,001 Views)

@Ray1981 wrote:

 

If I change the Upper Middle case as you suggested my I/O keeps on when the program will be shut down therefore I thought i had to make it as it is.

 

 


Both cases contain the same code and there will be no functional difference with or without the case structure, so I don't understand. If you want a certain state when stop is pressed, you can arrange that.

 

Here's a quick rewrite of what I had in mind. You might also want to call the config case on first call.

0 Kudos
Message 13 of 19
(2,999 Views)

LOL a quick rewrite this looks beautyfull. Now i need to understand it good. 

 

So first question what does this error do? I dont see exactly why one would use that for processing the code. I thought this is for error handling.

 

Second what is the difference between these two tunnels? The outputs are different IMO and an essential key for my mistake.

Screenshot_6.png

 

Screenshot_7.png

0 Kudos
Message 14 of 19
(2,994 Views)

Altenbach there is something else I dont understand the timer doesnt run longer as 1 sec (0.9 to be more percise)

0 Kudos
Message 15 of 19
(2,992 Views)

About the timer, I removed the TRUE diagram constant because I thought it is configured for autoreset anyway. Try to put it back. Also check what time is configured.

 

The error wire ensures that the various calls occur in a defined order. You are calling them in parallel and to protect from simultanous calls, you run them in the UI thread. The error wire ensure that only one call occurs at any given moment and you might even be able to run them in any thread for better performance (less thread switching and less load on the UI thread).

The error wire also prevents nodes from executing if they receive an error. For example if the configuration returns an error, it would not make sense to do all the other calls later so they will get skipped.

 

A solid tunnel gets data in all cases (note that the array is wired across unchanged in the other case of the bigger structure). If the tunnel is shaded, it is configured to return the default value (right-click..use default if unwired) for the datatype if left unwired in a case. The default array is an empty array and that's what you get when reset is TRUE.

0 Kudos
Message 16 of 19
(2,987 Views)

The timer is solved (i think) by default it is set to 1 sec, so I can make a constant to set a preset max time in that case the timer wont run forever.

 

Regarding the tunnel when I wired it and right click and use default if unwired becomes shaded (the small white dot in the middle. I was not able to make it solid orange, now i think that was because i did not wire the False case (eureka). 

The error wiring i think i get it but i will jump in the manual again to get a better understand and be able to use it next time. To code looks way more simple and pretty like this.

 

I think i will even start to like LV 🙂

0 Kudos
Message 17 of 19
(2,980 Views)

Yes, if all cases provide data to the case output tunnel, you can't tell the difference by just looking at it. If some cases are unwired, the tunnel is either open (and the VI broken) or shaded (not breaking the code) depending on the tunnel setting.

0 Kudos
Message 18 of 19
(2,974 Views)

Thanks a lot for all the help I have learned a lot today 🙂

0 Kudos
Message 19 of 19
(2,967 Views)