LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW code merging

Solved!
Go to solution

Hi,

Greetings. I have attached 3 different codes here. 1st code is about pump on/off based EC level control of a fertilizer supply system. It works without any problem. 2nd one, DAQ system, where I can measure individual nitrogen, potassium, calcium, pH, and EC level of the same fertilizer control system. It also works without any problem. In the 3rd, I tried to merge the 1st and 2nd code. Although there is no error in the code, practically it doesn't work. Specifically, the fertilizer pump doesn't turn off after reaching the target EC level and the DAQ also doesn't work properly... Would anyone suggest to me, where is the problem, please?

0 Kudos
Message 1 of 8
(2,753 Views)

The top loop uses "RMS" to get the value from an array. Perhaps you wanted the Mean instead?

I don't see anything immediately obvious about the bottom loop (which I think is what you're describing as "the DAQ"?). What exactly doesn't work?

 

If the problem is with the recording of data, it may be the Dynamic Data Type (blue wires) causing a problem. They always confuse me, because(/and so) I never use them - I would advise you to use other wire types and avoid the Dynamic Data Type. They have peculiar behaviour with arrays, with conversion, and they don't display enough information to know what's going on without a bunch of configuration panels (which is also a problem for e.g. the DAQ Assistant node).

 


GCentral
Message 2 of 8
(2,665 Views)

Hello Mr. Cbutcher,

I have replaced the "RMS" into "Mean.vi". Now the code works. But still facing some problems in DAQ (Consumer loop). The data saving rate is not smooth. As you mentioned, it may occur due to the "Dynamic Data Type (blue wires)".  I also tried to replace these wires by Double (DBL) type wire but failed to connect with "Write to Measurement File.vi"  How can I change the wire type? Thanks in advance. 

 

 Wire.JPG

0 Kudos
Message 3 of 8
(2,602 Views)

Unfortunately, you have chosen to use the Express VIs that NI designed many years ago to "hide" the (relatively-simple) learning process for acquiring and handling signals.  They introduced the Dreaded DAQ Assistant (DDA) and its Evil Twin, the Dynamic Data Wire, which saves beginners a few hours of lectures or exercises learning about Waveforms, DAQmx (for which they developed wonderful tutorials), and File I/O.

 

So one "solution" to your problem, which will stand you in very good stead if you continue to learn/use LabVIEW, is to "learn more LabVIEW", specifically the use of Waveforms (for data files), DAQmx (to acquire Data), and File I/O (to write the data in a variety of formats, including text-based files like the "LabVIEW Measurement" (.lvm) format that the Express VI uses.  In fact, if you look "under the hood", one of the first things that Write to Measurement Files does is to take the Signals Input (as a Dynamic Data Wire) and convert it (using Dynamic to Waveform Array) into an Array of Waveforms, converting the data to a SpreadSheet String, and ultimately writing it as a byte string of characters.

 

Bob Schor

Message 4 of 8
(2,578 Views)

Hello Mr. Bob_Schor

Thanks for your guidelines. Actually, I am used to using express VIs. I have replaced the 'Write to Measurement File' into 'Write Delimited Spreadsheet'. Now I am facing 2 problems.
1. Does this vi has 'use next available filename' option? I mean auto-generation of another file during several tests...

2. I need a time column. Is it possible in this 'Write Delimited Spreadsheet.vi'?

 

Thanks in advance. 

0 Kudos
Message 5 of 8
(2,560 Views)

@Chowdhury_Milon wrote:

Hello Mr. Bob_Schor

Thanks for your guidelines. Actually, I am used to using express VIs. I have replaced the 'Write to Measurement File' into 'Write Delimited Spreadsheet'. Now I am facing 2 problems.
1. Does this vi has 'use next available filename' option? I mean auto-generation of another file during several tests...

2. I need a time column. Is it possible in this 'Write Delimited Spreadsheet.vi'?

 

Thanks in advance. 


1. No - but there is a VI that can do that for you! Create File with Incrementing Suffix VI

2. It isn't built-in, but you can generate this yourself, or if you have a waveform, then the dt and t0 are enough to define a time column. The waveform palette has VIs to create such an array if you want it explicitly written, e.g. Get Waveform Time Array VI (produces a timestamp array, but you could convert to doubles).


GCentral
Message 6 of 8
(2,548 Views)

Hello Mr. Cbutcher & Mr. Bob-Schor

I am sorry. I have complicated the code. I can't understand which one would be better for me...

0 Kudos
Message 7 of 8
(2,535 Views)
Solution
Accepted by topic author Chowdhury_Milon

Here are some (what-I-hope-are-helpful) suggestions:

  • I used to use Index Array the same way you do, wiring 0 .. 4 to each Row index.  Then someone on the Forums said "Don't do that!".  If you simply pull down 5 instances and don't wire them, they will take their default values, 0 .. 4.  Much neater code, and you "can't make a mistake" (by accidentally wiring 0, 2, 1, 3, 4, for example).
  • Never hide labels on the Block Diagram.  I saw some Indicators getting 2D arrays from Build Array functions, and had no idea what they were.  Turning on the Labels showed me "NO3 ion level", "K ion level", and "Ca ion level" (charts).  Oh, that makes sense ...
  • "Hide" messy code (the complicated math that differs for each channel in your Consumer) in a sub-VI.  Use the 4-2-2-4 Connector Pattern for (almost all) your sub-VIs, putting Error In and Error Out on the lower corners.  Make a Custom Icon, say a Colored Box (with black border) with a 3-line Name (e.g. NO3 Calc) to make code "self-documenting".
  • If you want a Time Column (which you already figured out that you configure as a Time Row, build an Array of Rows, then Transpose Array), go ahead and generate it (feel free to use another sub-VI to "hide the details") and add it in with the other Data Rows (I presume you'd put Time first).
  • Note that since you are ultimately writing a Spreadsheet Array as Strings, you can (after you get it transposed so the rows are samples and the columns are data channels), you can add a "row in front" that contains nice Column Labels ("T", "NO3 Level", "K Level", "Ca Level", etc.).
  • You have now taken charge of creating and writing your data file(s).  I see you are using a Producer/Consumer design (good!), and are using a Stream Channel to pass data from Producer to Consumer (even better!).

Some other things to consider:

  • When, how often, and how do you want to name your Data Files?  In many cases, a single run of a Program will produce a single Data File.  Unique names can be created by using the "Create File with Incrementing Suffix" VI found on the File I/O, Advanced File Functions Palette.
  • You probably want to Open/Create the File just before you open the Consumer Loop (as you use the File only in the Consumer), and to Close it when the Consumer exits.  [I do this all the time ...].
  • I hope you are using LabVIEW Project (i.e. you started with creating a new Project, not a new VI).  I tend to keep all of the VIs in my Projects inside a (physical) Project Folder, which often contains sub-Folders such as "Tests", "Documentation", "Types", and "Sub-VIs".  My Project "Folders" are the same as my physical folders -- this works best for me.
  • I also hope you have available some form of Version Control System (two popular ones with LabVIEW Developers are Subversion, which I use, and git).  Commit Early, Commit Often.

Bob Schor

Message 8 of 8
(2,521 Views)