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 with analog and digital inputs and outputs

Solved!
Go to solution

Hi everyone,

 

I am working on a control system program for some practical test work. Currently I am working on the data acuisition component of the Labview program. My architecture is produced-consumer loops with a que. My system will have analog inputs, analog outputs, digital inputs and digital outputs. It's not a time critical sytem, but I would like all of the data acquisition to be synchronised. I have attached my program as it is at the moment. I am having trouble getting all of the data into the que since I have two data types. Also, I'm not sure if i've synchronised the four read/write sequences correctly. I would greatly appreciate if somebody could take a look at my program and give me some advice. Thanks in advance.

0 Kudos
Message 1 of 27
(4,857 Views)

Hi DarkMarc86,

 

The constant you have defined for the queues at the Obtain Queue.vi is a 1D array of Waveform data. Change this to a 2D array of Waveform data and you should be able to use the queues how you want.

 

Below is an example of synchronization as well. It uses a master/slave architecture to achieve synchronization. 

 

https://decibel.ni.com/content/docs/DOC-26326

 

Hope this helps

Robert R. | Applications Engineer | National Instruments
0 Kudos
Message 2 of 27
(4,779 Views)

Hi Robert,

 

How would changing the que to a 2D array help? As I understand, each element in an array has to be the same data type. I am having some success with converting my digital waveform to an analog waveform though I have not tested my code yet.

 

Also, I have a question regarding architecture: The way I want my program to work is:

 

1. Read from all input sensors.

2. Perform calculations on input sensors.

3. Update PID controllers using calculations from step 2.

4. Write results from step 3 to output sensors.

 

Do you think a producer/consumer architecture is the type for my program? Currently my program reads and write to sensors in the producer loop, so I guess the writing to outputs (step 4) would be done with data thats from the previous cycle.

0 Kudos
Message 3 of 27
(4,769 Views)

DarkMarc86,

 

You are correct in that the data type in an array has to be the same. You could create a cluster of the two waveform arrays and send that through the queue, otherwise you would have to use two seperate queues.

 

In regards to architecture, you can use a producer/consumer for what you are doing. You would have the producer loop read from the input sensors, while the consumer loop would write to the output sensors. In your consumer loop right now, you are just updating the indicators on the Front Panel, but not actually writing to the sensors. The Is Task Done.vi just checks for errors in the output task, but doen not update the values to write. You will need a DAQmx Write.vi to do this in the consumer loop.

 

Here is an example of how to do this with a DAQmx Read and a Write to TDMS. You would just need to replace the Write to TDMS with the DAQmx Write.vi. This example, along with the previous one for synchronization should be able to help you out.

 

https://decibel.ni.com/content/docs/DOC-2431

 

Best of luck.

 

 

Robert R. | Applications Engineer | National Instruments
0 Kudos
Message 4 of 27
(4,713 Views)

Robert,

 

Thanks for your suggestion of moving the write function to the consumer loop. I have managed to get the output to work by using the 'DAQmx Create Channel (AO Current)' function. However I would like to read my channels from a task in MAX. Instead of the 'DAQmx Create Channel (AO Current)' function I am using the 'Sample clock' function, which gets fed the task, sampling frequency and sample mode. No matter what sample mode I used (continious or finite) I seem to get errors related to the output buffer being empty. I have tried modifying the output buffer size with the 'DAQmx configure output buffer' function but with no luck. I don't understand why it works fine with the Create Channel function but not with a MAX tast.

 

Any suggestions would be appreciated.

0 Kudos
Message 5 of 27
(4,451 Views)

DarkMarc86,

 

Can you give more information about the error you are seeing? Does it have an error code associated with it? Where in your code does it occur?

 

Generally this is seen when you start an output task without writing anything to the buffer. You will still need a DAQmx Write.vi for your output tasks before your DAQmx Start Task.vi as well as a DAQmx Write.vi in the loop. 

 

Let me know if this helps.

Robert R. | Applications Engineer | National Instruments
0 Kudos
Message 6 of 27
(4,431 Views)

Robert, the specific error that I get is:

 

Error -200462 occurred at DAQmx Start Task.vi:6

 

Possible reason(s):

Generation cannot be started because the output buffer is empty. 

Write data before starting a buffered generation. The following actions can empty the buffer: changing the size of the buffer, unreserving a task, setting the Regeneration Mode property, changing the Sample Mode, or configuring retriggering.

Task Name: Heater testing lab digital outputs

 

This error occurs at the 'DAQmx write.vi' function. I just want to sent one sample per second, for each channel. I would like the producer and consumer loops to each run once every second.

 

I have attached part of my code with just the data acquisition and writing. Any help would be greatly appreciated.

0 Kudos
Message 7 of 27
(4,395 Views)

DarkMarc86,

 

You need two DAQmx Write.vis in your code to accomplish what you want. The first will need to be implemented before the DAQmx Start Task.vi for each write task you have. The second is in the While Loop like you have now. This should clear up that error. 

Robert R. | Applications Engineer | National Instruments
0 Kudos
Message 8 of 27
(4,367 Views)

Hi Robert,

 

I have implemented your advice into my VI. Because of the additional 'DAQmx Write' I have had to use initial values as well, which I was hoping to avoid. Now I am getting a new error:

 

Error -200294 occurred at control_v2_ML_simple.vi

 

Possible reason(s):

Specified route cannot be satisfied, because it requires resources that are currently in use by another route.

Source Device: cDAQ1 Source Terminal: di/SampleClock Destination Device: cDAQ1 Destination Terminal: Slot5/ConvertPulse

Required Resources in Use by Task Name: Heater testing lab digital outputs Source Device: cDAQ1 Source Terminal: do/SampleClock Destination Device: cDAQ1 Destination Terminal: Slot5/ConvertPulse

Task Name: Heater testing lab digital inputs

0 Kudos
Message 9 of 27
(4,342 Views)

DarkMarc86,

 

What is your hardware set up like? Specifically what Digital I/O Module are you using? Both of your digital tasks are trying to access the same terminal, the Slot5/ConvertPulse, at the same time. There are some Digital I/O modules that can either read or write, but not at the same time. But there are some that can do both simultaneously.

 

Have you ever received this error before? 

 

I would also recommend clearing the tasks at the end of your write tasks.

Robert R. | Applications Engineer | National Instruments
0 Kudos
Message 10 of 27
(4,325 Views)