LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error: unbundle by name

Solved!
Go to solution

My code should read the changes of state of 10 to 15 machines on the shopfloor of a factory. It should write all the changes to an Excel file (or csv).

The state of each machine is determined by three bits: 000 off, 001 setup etc.

I think the attached vi (a prototype for 2 machines) is close to what I want. Thanks

0 Kudos
Message 11 of 20
(842 Views)

The VI you've written will work for any number of input lines (or at least any multiple of 3, with non-multiples it might be a little odd on the last group) but you should probably initialize your shift register to some set of values.

 

At present, you'll get an empty 2D boolean array on the shift register the first time you run the VI, and then the For loop will iterate 0 times. Crucially, in the case of multiple things controlling the number of iterations (N) for a For loop, the "chosen" value will be the lowest number.

 

In your case, the options are 6/3 = 2, or 0. So you get N=0 iterations, and no logging for the first change.

 

In your second iteration of the While loop, everything becomes fine because you have the 6 elements (2x3) from the first iteration, so your two options at the For loop are 6/3 = 2, or 2 (rows in the shift register). The value of min(2,2) is 2, so you're all good.

 

If you don't care about writing the first state, you don't need to change anything really, but you'll never get that first iteration with the way it's currently set for the reason above.

 

A minor change that you could consider is to use Array to Spreadsheet String rather than manually inserting tab characters - it might be a little cleaner:

originaloriginalalternativealternative

Either way should work, so do whichever you're happier with. The alternative only requires one write to file each While loop iteration over one per change in the For loop though, so is probably faster.

 

You might also look at using DAQmx Timing rather than a Wait until ms Multiple node, if timing requirements are more exact, but it doesn't sound like this is too crucial.


GCentral
Message 12 of 20
(823 Views)

Thanks cbutcher,

 

your solution is to the point. I just don't understand how you do the "write only if value change".

Also, I thought I had to set N (in the for loop) to dimension size - 1, as in the attached VI. Correct?

I will address the missing first iteration later: this requirement is not still clear to me (if i have to collect it or not…)

0 Kudos
Message 13 of 20
(808 Views)

@DavideB wrote:

I just don't understand how you do the "write only if value change".


Right click on the tunnel and where you can choose Tunnel Mode there are 3 options, a sort of line, then a 4th. The first three (Last Value, Indexing, Concatenate) control the output datatype (e.g. single value, array with one element per iteration, array where the array passed to the tunnels are joined together).

 

The 4th option is "Conditional" which can be separately toggled on or off, and adds that little green question mark under the tunnel. If this appears, then the values are only included if the boolean is true. So in this specific case, you'll get a 2D array of strings, where a 1D row is formed inside the For loop, and then a row is output each time the boolean is true. So this can be between 0 and N-1 rows.

 


@DavideB wrote:

Also, I thought I had to set N (in the for loop) to dimension size - 1, as in the attached VI. Correct?


In the new attached VI (SCADA4.vi), you have 3 conditions that limit your For loops number of iterations. You wired a value to N, and you have 2 autoindexing arrays.

As I tried to describe (apparently not quite successfully - sorry!) in my previous post, a For loop will iterate the minimum number of times it works out. 

These examples demonstrate this, perhaps better than words have:

Example_VI.png

Does that make more sense?


GCentral
Message 14 of 20
(793 Views)

Thanks cbutcher,

now I understand the for loop number of iterations. In my case, solution one is perfect.

Unfortunately, I have an older versione (2010) of Labview, therefore tunnel mode is not available. I think I have to use the case structure.

 

0 Kudos
Message 15 of 20
(783 Views)

@DavideB wrote:

Thanks cbutcher,

now I understand the for loop number of iterations. In my case, solution one is perfect.

 


Great, just be careful when you have multiple "autoindexing" array inputs to a loop. Especially if one is a shift register, in the first case one array is often shorter than the other, and that can lead to unexpected behaviour.

 


@DavideB wrote:

Unfortunately, I have an older versione (2010) of Labview, therefore tunnel mode is not available. I think I have to use the case structure.

 


Fair enough! Glad it's all sorted now anyway.


GCentral
0 Kudos
Message 16 of 20
(780 Views)

A quick note to the inner formatting. This could be done simpler. Here are two alternatives. (You also don't need to get the time, because current time is the default).

You could also just create the 1D string of version 2, conditionally autoindex at the loop boundary and covert the resulting 2D string array to a spreadsheet string all at once after the loop (not shown). Same difference 😉

 

Note that the format for version 3 is in \-codes display.

 

FormatIt3x.png

0 Kudos
Message 17 of 20
(777 Views)

Thanks a lot cbutcher. I understand there are some benefits with the second option. Still, I have to implement it with the case structure , which is not an issue, I think.

You put the array to string and the write to file outside of the for loop, which diminishes the number of write-to operations, which is good.

Only, I do not understand how you substitute the concatenate string: what is the object?

thanks

 

0 Kudos
Message 18 of 20
(747 Views)

@DavideB wrote:

Only, I do not understand how you substitute the concatenate string: what is the object?


I assume you are talking about "built array". "conditional tunnel", and "array to spreadsheet string".

0 Kudos
Message 19 of 20
(736 Views)

Well, now I'm miles outside of the bounds of this question but... any chance of an upgrade?


@DavideB wrote:

... Still, I have to implement it with the case structure , which is not an issue, I think.

You put the array to string and the write to file outside of the for loop, which diminishes the number of write-to operations, which is good.

 


I'm not certain (at least without testing) that you can use the second option I suggested if you don't have conditional tunnels.

 

Doing what I suggested without a conditional tunnel will result in some empty rows in your 2D string array, which I'd guess will result in empty rows in your text file. Probably not what you wanted.

It is possible by using something like a shift register and either a Case Structure or Select node and an additional Build Array node, but then you've reintroduced a bunch of 'complexity'...

 

You could, I suppose, use a Concatenate mode tunnel, end up with a 1D array of strings (outputting an empty array when you don't have changes) then reshape the array before passing it to the Array to Spreadsheet String node (since you have a fixed number of elements per row). Not sure if that's better or not - it will allow you to still avoid multiple writes though 🙂

 


GCentral
0 Kudos
Message 20 of 20
(726 Views)