LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need guidance in getting data from condition and while loop

Solved!
Go to solution

Hi,

 

Sorry to disturb you again I prepared avarage part in code but it is giving random/rong values.

 

Kindly please guide where I am doing mistake.

 

Kind regards

Hasham

Download All
0 Kudos
Message 31 of 61
(379 Views)

I guess that Channel Data looks very strange due to how you've constructed that For loop.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 32 of 61
(376 Views)
Solution
Accepted by topic author Hasham622x

Hi Hasham,

 


@Hasham622x wrote:

Sorry to disturb you again I prepared avarage part in code but it is giving random/rong values.

 

Kindly please guide where I am doing mistake.


Placing the averaging code inside the while loop is nonsense as your 2D array consists of just one row of data (and so only one element per column)!

 

Placing the averaging after the while loop looks better and should do what you asked for.

Unfortunately we still cannot debug/edit/run images in LabVIEW, so you need to debug on your own!

 

Suggestion:

  1. Place the averaging code in a subVI, with a 2D array input and a 1D array output.
  2. Run your mainVI, have the subVI open while running.
  3. After stopping the mainVI you set all values in your subVI as default and save the subVI.
  4. Attach the subVI so we can debug it…

 

Btw. what's your problem with creating block diagrams with straight wires? Ever heard of LabVIEW Style Guide?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 33 of 61
(372 Views)

Hi,

 

Thanks for your reply. Yes, you are right, and I didn't hear of LabView Style Guide.

 

I attached code to this reply as an attachment, and I am getting data in two 8 bits formats.

 

Kind regards

Hasham

0 Kudos
Message 34 of 61
(360 Views)

Hi Hasham,

 


@Hasham622x wrote:

I attached code to this reply as an attachment,


You forgot about message #22

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 35 of 61
(353 Views)

I still cannot look at any of your code because you don't "save for previous" before attaching.

If you like an answer, give it kudos. It is not helpful to basically mark almost every comment as solution to the thread. Typically there should only be one solution for each thread (unless there are two very different, but equally good solutions).

 

You are streaming the data to disk one row at a time and you can do a ptbypt average at the same time avoiding the need to store an ever-growing array in an autoindexing tunnel or other mechanism. All you need is keep the sum of all data and the number of averages, you could even display the running average of all data processed so far in an indicator. Nothing should ever be outside the toplevel loop. Think state machine.

 

On another note, your entire string processing is still extremely convoluted. Long ago, I asked how the received string looks like, so we can offer guidance how to do all that with code the size of a postage stamp. Most likely all you need to do is unflatten the string to a U16 array (swap byte order as needed). Each data "packet" seems to be fixed size, so growing an array in a shift register is just plain Rube Goldberg! Also, why would you build your "dt" into an array if you never use that array? Why would you append dt AND write to file even if no new data has arrived?

 

 

Message 36 of 61
(341 Views)

See if this quick simulation can give you some ideas at simplifications. All you need to do is substitute your serial read, potentially change the byte order, and implement some error handing as needed.

 

altenbach_0-1720024515528.png

 

Message 37 of 61
(330 Views)

Hi,

I attached code in older version of LV19

 

"I am sorry to disturb you again. I am stuck in code and need your guidance. I tried calculating the averages of columns of the 2D array, but it gave the wrong values. My data is in the form of two 8 bits, and I am confused about how to convert it into floating format and at which point of code... I tried all three options to calculate the averages."

 

Kind regards

Hasham

0 Kudos
Message 38 of 61
(314 Views)

sorry, my bad data is in 12-bit format 0 to 3000 

0 Kudos
Message 39 of 61
(305 Views)
  • Why do you think you need three autoindexing output tunnels and three transpose arrays instead of branching after the transpose operation?
  • Why do you have terminals with no labels? It is a bad habit to set labels to an empty string. You can always show the caption or hide the label on the front panel, but they need to show in the diagram to avid confusion!
  • Taking the array sum of U16 can easily overflow (wraparound), so don't do that! The solution with the mean is all you need.
  • In what way is the result wrong? Is the U32 data correct? Maybe you have the wrong byte order?
  • Please use my technique! 80% less code and easier to maintain and debug.
  • Autoindexing on a while loop output can be problematic, because you will run out of memory if the program runs forever. Also, if you abort the VI (instead of correctly stopping the loop), all data is lost forever!
  • Please do not maximize the front panel to the screen. Super annoying!
  • Do a few more basic tutorial and simplify, simplify!
  • etc. etc.
  •  

As an example, let's have a look at your inner loop. All three produce the same output, but some versions are arguably simpler!

 

altenbach_0-1720052316347.png

 

 

Message 40 of 61
(303 Views)