**5. LabView architecture**

In this section we show you the architecture that we use to run LabView code in Mater mode. We have chosen the *Producer/Consumer Architecture* [6].

The Producer/Consumer design pattern (**Figure 18**) is based on the Master/Slave pattern, and is geared towards enhanced data sharing between multiple loops running at different rates. The Producer/Consumer pattern is commonly used when acquiring multiple sets of data to be processed in order. Suppose you want to write an application that accepts data while processing them in the order they were received. Because queuing up (producing) this data is much faster than the actual processing (consuming), the Producer/Consumer design pattern is best suited for this application. In our project we can set a high sample rate (up to fs = 10 kHz) so in this can we can occur in a data loss case. With Producer/Consumer is sure that we are implementing a data lossless LabView architecture. But we have considerated also an architecture *Event-Driven* to catch the write instance from LabView vs. Arduino only if asked from the operator.

In **Figure 19** we show the front panel developed in LabView [7].

#### **5.1 Front panel**

On the left side of front panel are present a several controls to configure the DAQ (Arduino in Slave mode) in according with previous paragraphs. Instead on the right side we found a control to set the PWM value (analog output) and the digital output state. We use Waveform chart like oscilloscope to view the six signal.

**95**

exercise.

*LabView and Connections with Third-Party Hardware DOI: http://dx.doi.org/10.5772/intechopen.96056*

After defined the configuration you have to send a message at the serial VISA

After that the cycle Producer/Consumer starts and the sensor reading is shown

Inside the LabView Code (block diagram) there are three nodes. The first one composed by "While Loop" (**Figure 20a**) that waiting for user's hardware configuration. In this Loop we create a Boolean array with all hardware instance, at the end of the configuration the user pushes the button and send the array to subvi "open and configure.vi" (second node). It makes a rights sequence of op-code, open the Serial Port communication (in this case **com3**) and send it at Arduino (**Figure 20b**). During this phase you can observe the blinking LED on Arduino board, this means that the configuration message has correctly reached Arduino and it is processing

communication by the pressing of "SEND CONFIGURATION" button.

From **Figure 20b** is possible to verify that the serial port velocity

In this way the communication between Master and Slave does not make interference with acquiring. In fact one character, in ASCII encoding (1 byte), from Arduino to LabView is sent in 4 μsec. If we would configure all analog inputs (6) and all digital inputs (14) the maximum number of characters would be = 6 prefixes (#) + 6\*4 (digits of value among 0÷1023) + 14 prefixes (&) + 14 digital

Maximum time to transmit the entire message is 58 Byte \* 4 μsec = 232 μsec. This time is half of the minimum sampling time set in the code, that is 500 μsec. You could also reach 100 μsec of sampling rate that corresponds to 10 kHz of sampling frequency, in this case you have to merge the bits of the digital input, so it is possible to save 26 bytes but it is not enough. We have to modify the syntax of sending analog input values to reach at least 80 μsec of transmission time. This modification to the Arduino code we leave to the reader as an

In last one node, **Figure 21**, we can see the Producer Loop and the Consumer Loop. Both are connected by the queue, in queue process we read the Arduino's

on the Waveform Chart.

**5.2 Block diagram**

**Figure 19.** *LabView front panel.*

the op-code.

states = 58 bytes.

is 2Mbps.

**Figure 18.** *Event structure in producer/consumer design pattern.*

*LabView and Connections with Third-Party Hardware DOI: http://dx.doi.org/10.5772/intechopen.96056*

*LabVIEW - A Flexible Environment for Modeling and Daily Laboratory Use*

ing the dynamic channel configuration.

**5. LabView architecture**

**5.1 Front panel**

events procedure, respectively both in **Figure 12**.

**Figure 16** shows a small piece of code that is a good starting point for complet-

At this point we show the code about the blinking procedure and the Serial

In the end we report the loop() code, **Figure 17**. The code is very simple, the final message is made-up by concatenating the message in each "if" statement.

In this section we show you the architecture that we use to run LabView code in

The Producer/Consumer design pattern (**Figure 18**) is based on the Master/Slave pattern, and is geared towards enhanced data sharing between multiple loops running at different rates. The Producer/Consumer pattern is commonly used when acquiring multiple sets of data to be processed in order. Suppose you want to write an application that accepts data while processing them in the order they were received. Because queuing up (producing) this data is much faster than the actual processing (consuming), the Producer/Consumer design pattern is best suited for this application. In our project we can set a high sample rate (up to fs = 10 kHz) so in this can we can occur in a data loss case. With Producer/Consumer is sure that we are implementing a data lossless LabView architecture. But we have considerated also an architecture *Event-Driven* to catch the write instance from LabView vs. Arduino only if asked from the operator.

On the left side of front panel are present a several controls to configure the DAQ

(Arduino in Slave mode) in according with previous paragraphs. Instead on the right side we found a control to set the PWM value (analog output) and the digital output state. We use Waveform chart like oscilloscope to view the six signal.

Mater mode. We have chosen the *Producer/Consumer Architecture* [6].

In **Figure 19** we show the front panel developed in LabView [7].

**94**

**Figure 18.**

*Event structure in producer/consumer design pattern.*

After defined the configuration you have to send a message at the serial VISA communication by the pressing of "SEND CONFIGURATION" button.

After that the cycle Producer/Consumer starts and the sensor reading is shown on the Waveform Chart.

#### **5.2 Block diagram**

Inside the LabView Code (block diagram) there are three nodes. The first one composed by "While Loop" (**Figure 20a**) that waiting for user's hardware configuration. In this Loop we create a Boolean array with all hardware instance, at the end of the configuration the user pushes the button and send the array to subvi "open and configure.vi" (second node). It makes a rights sequence of op-code, open the Serial Port communication (in this case **com3**) and send it at Arduino (**Figure 20b**). During this phase you can observe the blinking LED on Arduino board, this means that the configuration message has correctly reached Arduino and it is processing the op-code.

From **Figure 20b** is possible to verify that the serial port velocity is 2Mbps.

In this way the communication between Master and Slave does not make interference with acquiring. In fact one character, in ASCII encoding (1 byte), from Arduino to LabView is sent in 4 μsec. If we would configure all analog inputs (6) and all digital inputs (14) the maximum number of characters would be = 6 prefixes (#) + 6\*4 (digits of value among 0÷1023) + 14 prefixes (&) + 14 digital states = 58 bytes.

Maximum time to transmit the entire message is 58 Byte \* 4 μsec = 232 μsec. This time is half of the minimum sampling time set in the code, that is 500 μsec. You could also reach 100 μsec of sampling rate that corresponds to 10 kHz of sampling frequency, in this case you have to merge the bits of the digital input, so it is possible to save 26 bytes but it is not enough. We have to modify the syntax of sending analog input values to reach at least 80 μsec of transmission time. This modification to the Arduino code we leave to the reader as an exercise.

In last one node, **Figure 21**, we can see the Producer Loop and the Consumer Loop. Both are connected by the queue, in queue process we read the Arduino's

**97**

**Figure 21.**

*Producer/consumer event-driven LabView CODE.*

*LabView and Connections with Third-Party Hardware DOI: http://dx.doi.org/10.5772/intechopen.96056*

**Figure 20.** *First node and second node in block diagram (a and b).*

*LabView and Connections with Third-Party Hardware DOI: http://dx.doi.org/10.5772/intechopen.96056*

**96**

**Figure 20.**

*First node and second node in block diagram (a and b).*

**Figure 21.** *Producer/consumer event-driven LabView CODE.*

message at maximum frequency and by consumer loop we process the data. The Event-Driven statement is configurated with the following **events.**
