LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

digital inputs from multiple sources

Solved!
Go to solution

Hello everyone, 

 

I have developed a simple VI which acquires 3 digital inputs, corresponding to the states of a machine (000 off, 001 setup, 010 automatic mode etc.). It checks the state every 500 msec and then - if the state has changed - writes the acquired data into an Excel file. It works well. I attach the code.

 

Now I want to acquire the same digital inputs from multiple machines in parallel (let's say 15 machines). Machines will be connected to different lines. For example, machine 1 is connected to port 0 lines 0 to 2, machine 2 to port 0 lines 3 to 5 etc.

 

How can I use the same code? Do I need a for loop somewhere? 

0 Kudos
Message 1 of 10
(2,533 Views)

Buon giorno Davide,

 


How can I use the same code? Do I need a for loop somewhere? 


You could just extend that DI task to read more lines, depending on the number of machines.

Then you get an array of 6, 9, 12, … bits instead of the 3 bits right now.

Reshape that array into a 2D array of x rows by 3 columns.

Now use a FOR loop to examine each machine's state row by row.

 

I would separate DAQmx loop from file writing loop by using a queue and employing a producer-consumer scheme. This way you can organize your code into (kind of) modules dedicated to special jobs (DAQmx, file write)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 10
(2,511 Views)

There are a few ways you could approach this problem.

One option is to use Array Subset in a For loop to get each block of 3 values, then process these in the same way that you currently do.

A possible extension is to bundle those 3 values to form an array of clusters, which will retain the grouping more easily for considering handling of the blocks.

Using a 2D boolean array (with the same splitting mechanism, or a Reshape Array node) is also an option. (Edit: GerdW already mentioned Reshape Array while I was creating the example. It's probably a better choice...)

An example image showing this in your VI is below:

blocksChanged.png

A smaller test VI to play with is here as a snippet (without DAQmx etc)

Example_VI.png

 

Third example, with Reshape Array added (and a comment to explain the outer For loop purpose in case not clear)

Example_VI.png


GCentral
0 Kudos
Message 3 of 10
(2,494 Views)

Hello Gerd:



You could just extend that DI task to read more lines, depending on the number of machines. Then you get an array of 6, 9, 12, … bits instead of the 3 bits right now.


I was obviously going to do that, sorry not to mention it. It is the next step which I find difficult:

 

Reshape that array into a 2D array of x rows by 3 columns.


I understand I have to use Reshape array after Daqmx Read (as I did in the attachment) but then I got stuck.. can you give me an example?

Thanks a lot for your reply

 

0 Kudos
Message 4 of 10
(2,479 Views)

Hello Gerd,

I added the Reshape array (I attach the code) but then I got stuck:

 

Now use a FOR loop to examine each machine's state row by row.

 

I would separate DAQmx loop from file writing loop by using a queue and employing a producer-consumer scheme. This way you can organize your code into (kind of) modules dedicated to special jobs (DAQmx, file write)…


This part is not clear to me. Not even the first: I have a single wire out of Reshape array.

How can i separate the machines ? (line 0-2 machine 2, line 3-5 machine 2 etc.). Can you give me an example? 

Thanks a lot

0 Kudos
Message 5 of 10
(2,476 Views)
Solution
Accepted by topic author DavideB

Hi Davide,

 

something like this:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 10
(2,474 Views)

Hello Gerd

thanks again for your excellent support. I understand the 2D array goes into the for loop.

But I want to write only in case the state of the i-th machine has changed. I used a shift register in the while loop, which is not available in the for loop. How would you do that?

Obviously the machine number (that is the raw number of the 2D array) should be written in the text file as well, as first field of the record).

I attach my attempt so far. Thanks

0 Kudos
Message 7 of 10
(2,446 Views)

You can, if you wish, use a Shift Register on a For loop (the same as with a While loop).

 

My example (3rd post in this thread) shows the use of either a 2D array or a cluster of arrays, together with a For loop, to determine in which "blocks" the value (combined from 3 values) has changed. Was it not sufficient?

 

You should be able to use the values created with the "Block Changed?" indicators to connect to your output case.


GCentral
Message 8 of 10
(2,440 Views)

You are right.. I am missing something.

My while loop acquires the whole sequence. Therefore in the very first iteration I write the state of all machines. But after that, I want to write only the state of the machines which have changed.

I will check your example again. Thanks a lot

0 Kudos
Message 9 of 10
(2,433 Views)
Solution
Accepted by topic author DavideB

@DavideB wrote:

My while loop acquires the whole sequence. Therefore in the very first iteration I write the state of all machines. But after that, I want to write only the state of the machines which have changed.


Do you want to write all in the first iteration? If not, you can combine the "first call?" node (or i=0, I'm sometimes suspicious about the first call node) with your booleans to prevent in that case.


GCentral
Message 10 of 10
(2,430 Views)