LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Repeatedly adding elements to an array of unknown size

Solved!
Go to solution

Hey,

 

I made an application that communicates with a device (a microwave generator) through RS-232 modbus protocol. The whole thing is inside a state machine. The VI first executes generator initialization and then goes to "Idle" state, where I have an event structure to monitor any control change value. In this event structure a timeout of 300 ms is implemented, because the communication to the generator has to be active at least every second (otherwise a fault is reported). In this timeout event I read from all register and display the values.

In this timeout I would like to save an indicator value ("Pfwd measure") repeatedly to an array of 1-D (size of the array is unknown!!). However I would like for the variable to be saved only when indicator "MW?" is "TRUE". And everytime "MW?" goes from "FALSE" to "TRUE" I would like to start writing to an array from the beginning.

I tried several options, including reshape array, but I can't get it to work. Or it works in a separate VI, but when I use it inside event structure and State machine, nothing works.

 

If someone has an idea, it would be most welcome...

 

Thanks,

 

Regards

0 Kudos
Message 1 of 9
(3,756 Views)

It's impossible to say why its not working without seeing what you have written.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 9
(3,750 Views)

I'm sorry, I thought I attached the picture...

0 Kudos
Message 3 of 9
(3,743 Views)

Well one thing I see is that none of the 4 tunnels from the "Idle" case structure that are going to shift registers are fully wired. Notice how the tunnels look sourt of white ot lighter in the middle. That means that those tunnels are configured to use the default value if unwired - and there are cases where they are all unwired.

 

What about the other cases?

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 4 of 9
(3,738 Views)

Hey,

 

that is just because I have a state "alarm" prepared to write code for different alarm situations (and I think is irrelevant to the problem). This alarm case never executes. Those squares disappear if I wire the wire from one point of state to the other. However, what I am trying to do does not involve any of those 4 lines I am using. It is only about storing "Pfwd measure" into an array of unknown size under conditions I desribed in my first post.

 

 

Grega

0 Kudos
Message 5 of 9
(3,730 Views)
Solution
Accepted by grega

Create another shift register that is initialized with an empty array of the correct data type and use the Build Array node to append data to it whenever you want it added.

 

In LV the size of an array does not have to be declared ahead of time.

 

Mike...

 

PS: those other tunnels should be wired across,


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 6 of 9
(3,723 Views)

You need to cache two sets of data - the array for Pfwd measure and the last value of MW?.  A shift register works very well for this in your situation.  As you figured out, you will need to dynamically manage the size of the Pfwd measure array.  I would recommend you preallocate an array before your loop, then dynamically manage it in the events.  You will need two more variables - write location (a simple index pointing to where the next point will go in the array) and actual array size (another integer which stores the current size of the array).  At each iteration, check to see if the write location is outside the bounds of the array.  If so, resize the array to double its current size.  Then write your point.  If you need to display the array, your write pointer will give you the number of points to show.  When MW? changes from FALSE to TRUE, simply set the write pointer back to zero.  You may or may not want to resize the array at that point.  You should not need to erase old points, since you know where they are and can avoid using them.

 

I wrote up a post awhile back, for a different reason, which shows a lot of these operations.  You can get it here.  Look at the second example.

Message 7 of 9
(3,716 Views)

And one more point..

 

you will end up with 5 shift registers, one for Pfwd array, one fore False/True status, one fore cluster as you already have, one for Handle as you already have and one for error which is already there.

 

instead, you create a cluster that will hold handles, other required inputs to the vis, Pwfd array, index number, array sizes, True/False status of MW, etc and then pass that one cluster through the shift register.

 

 

Regards
Freelance_LV
TestAutomation Consultant
0 Kudos
Message 8 of 9
(3,680 Views)

Thanks to all. Both solutions work, so all good here.

 

Grega

0 Kudos
Message 9 of 9
(3,655 Views)