From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

producer -consumer code with several variables (types)

I keep saying it, but thank you very much to you all for your help. I would have never been to create such a VI without your help. And if my code look messy to you, I am a little bit proud of it 😄

 

so:

1) 500ms linked to the dequeue. done.

2) this is more or less answeed by 1)

3) hello confusion, my old friend! soooo, I get that I have an unreacheable piece of code (the case "0" in my third loop). What if I delete the case structure? would that solve?

Also you say: Acquire + Display and Log in the next loop. isn't that what I am already doing ? I dont get the hint here.

finaly, why should I use a write to delimiter ? Should I gather everything to an array then send it to that function?

 

Thabk you all !

 

(messy) Flo

0 Kudos
Message 41 of 47
(1,336 Views)

Dear Messy (but I hope we are helping you become Neat),

 

I notice a huge structure in Controller v5 where you have about a dozen Floats that you convert into a string (a dozen times), then concatenate with commas between them.

 

Here's a suggestion:

  • Build an array with "Build Array" to get a 1D array of your dozen floats.
  • Do one more Build Array to create a 2D array.
  • Wire this to an Array to Spreadsheet String.  You need to specify a Format (I recommend <space>%f) and a delimiter (,).  You now have a String.
  • Write String to Text file. 

Write Floats.png

Bob Schor

0 Kudos
Message 42 of 47
(1,320 Views)

Re everyone !

 

I have worked a little bit more on my code. I also did my best to make it less messy. I think It's looking better now.

 

I have tried to take into account every suggestion here. 

 

1st loop: should be done by now

2nd loop: I've added the DAQmx functions. As my real DAQ ins't plugged in right now, I've just copied the input of my DAQ asistant. 

3rd loop: I've removed the case structure and added a way to average each colomn every minute (hence every ~120 iterations of the 2nd /3rd loop). this piece of code works well. I've tried it with simple data on a separate VI that I am keen to give away if anyone is iterested.

I've also added a way to save each new row generated every minute (or 120 iterations) to a text file.

 

Let me know what could go wrong? what's wrong? what's good maybe ?

 

Thank you all !

 

Flo

Download All
0 Kudos
Message 43 of 47
(1,295 Views)
  • What is that "General controller library.lvlib" with lots of network published global variables? You do not use these in your main VI.
  • Still a big mess:
    • Crazy huge block diagram, learn how to use subVIs properly (also create some descriptive icon for your subVIs), and structure your BD in a cleaner tighter way...
    • Lots of overlapping objects, cannot see wires at some places
    • Learn how to use Type Defined Cluster for your Queues (commands Queue and Data queue)!
    • No Stop function to stop the application in a sane way. Do not use the red Abort button for stopping the VI. Create a stop button in your Event structure!
    • You read 1D array of Waveform with DAQmx Read. Then you split this signal in the same DAQ loop, and then Enqueue-ing them in the Queue. Just send the 1D array of Waveforms to the other loop.
    • Lots of Rube Goldberg constructs, like the averaging function in that Case structure in the bottom While loop. Also here you have memory leaks, you build arrays infinitely...After a while your PC's RAM will get full...

Anyway, I see the improvement in your work, do not give it up, and use the online courses to learn further...

0 Kudos
Message 44 of 47
(1,286 Views)

Thx Blokk,

 

1) will do

2) well...

3)I am still unsure about what this is, and how it would help me. 

4)yeup, that's something I forgot. I will add that stpo button straight away!

5) done

6) So yeah, I may not be the best programmer in the world. but it does hte job. 

 

My real concern here is that this array will eventually eat all my RAM. Do you have any way to prevent that ??

 

Thank you,

Flo

0 Kudos
Message 45 of 47
(1,265 Views)

@Flo-w wrote:

Thx Blokk,

 

1) will do

2) well...

3)I am still unsure about what this is, and how it would help me. 

4)yeup, that's something I forgot. I will add that stpo button straight away!

5) done

6) So yeah, I may not be the best programmer in the world. but it does hte job. 

 

My real concern here is that this array will eventually eat all my RAM. Do you have any way to prevent that ??

 

Thank you,

Flo


Type definied clusters are very useful things. I give a little example here to show you how to use them. First of all, drop an empty cluster on any Front Panel. After this, right click on it, and select: "Make Type Def.". Right click on this cluster control again, and select: "Open Type def.". Now an extra window opens where you can work with your new type definied cluster, lets add 3 elements to it just for this example (right click inside the empty cluster and browse out the required element from your palette):

  • an array of Waveforms type control,
  • and 2 double values, lets call them "Serial1", "Serial2".

Lets also customize the icon of this type def cluster control: double click on the icon at the top right corner, and change it to some descriptive, maybe some text. When you are done with this, save this "ctrl" file into your LV project folder (it should be added automatically to your opened project, or you can do this manually too). This type def cluster should look like this now, see it below. You see that a little black triangle appeared at the topleft corner visible in te BD? That triangle means that this is not a simple control, but a typedef control!

 

typedef1.png

 

Why is this very useful in a LabVIEW project? Easy to use it with the "Bundle by name" and "unbundle by name" functions. Even more important is the following: imagine, you use this typedef control at many places in your code. What about if one day you need to extend your code?? For example, if you need to add one more serial com to your measurement. If you do not use a typedef control, you have to search for EVERY instances in your code where you used that non-typdef cluster, and manually change ALL. But if you use a type def, you only need to right click on a SINGLE instance of such typdef control, open up the saved CTRL file ("Open type def."), and modify it as you need. After saving the modification, ALL of its instances in the block diagram will be updated at once! You see how much better this?

 

I attach a sample project zipped up, do not run the main VI, it is just for experimentation how you can add/remove elements from this typedef cluster (hint--> when you drop a typdef cluster into a VI, you can quickly change between control/indicator/constant types using right click):

 

typdef_main.png

 

My real concern here is that this array will eventually eat all my RAM. Do you have any way to prevent that ??

You should not build these arrays indefinitelly. You could use Charts instead of Graphs, Charts have "memory", by default they can show up to 1024 data points. So if you use Charts, you do not need those shift registers with the forever growing arrays...

 

0 Kudos
Message 46 of 47
(1,260 Views)

I am back from hollidays, and ready to update that code a little bit more before checking it !

 

I've added those modifications ! 

 

I now bundle and unbundle by name, which makes the code a bit more readible. I've not created subVIs yet, as I find it easier to read it that way. I'll do it (but later 🙂 )

 

I've also changed the waveform graphs for charts. The only memory leak right now, as far as my understanding of labview goes, is represented by this 2D array of strings (3rd loop). I'd like to display the data in the array throughout the acquisition, but this would lead to a build up in the RAM.

 

Any suggestions ?

 

Thanks again for your help!

Flo

0 Kudos
Message 47 of 47
(1,192 Views)