LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parallel Read timer action

Hello,

 

I have a program, which is based on a queued message handler. I use this structure to send commands from the UI to the logic of my application. But I also need to implement some functions which have a really long runtime. For example I need to send a high number of instructions to a power supply. The duration for this process can be up to 5 minutes. But the user must can control the user interface during that time. Because of this, I created a second loop. I pass the data from my "consumer loop" with a queue to this loop.

 

It works, but is there a better way?

 

I hope so, because a part of the data I need to send is from a special datatype from a special API and I cant initialize it outside my producer loop. Same problem with reference from serial port, bacause I initialize my serial Port later in the consumerloop. So everytime I start my application an error occurs (I can click continue and then it works).

Download All
0 Kudos
Message 1 of 11
(1,295 Views)

Hi lvhvl,

 


@lvhvl wrote:

I have a program, …

It works, but is there a better way?


Probably yes.

But you failed in attaching your code so we cannot comment on your code problems…

 


@lvhvl wrote:

So everytime I start my application an error occurs (I can click continue and then it works).


This just means you failed to implement error handling (or proper initialisation) in your VI…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(1,290 Views)

Thanks for your reply,

 

I edited my Question and added my code. I know that the error occurs because there is no initialization... but I cant initialize it because I open my serial port in my consumer loop. And if I put the declaration of the queue inside the loop, It doesnt work.

0 Kudos
Message 3 of 11
(1,281 Views)

Hi lvhvl,

 


@lvhvl wrote:

I edited my Question and added my code.


Don't you remember those messages in your other thread?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 11
(1,267 Views)

Which one do you mean?

 

I used everything I can from the messages... I know that there are some things to improve... And as I mentioned in my question, it is working with a queued message handler. But I hope that there is a better way...

0 Kudos
Message 5 of 11
(1,255 Views)

Hi lvhvl,

 


@lvhvl wrote:

Which one do you mean?


I mean the message I linked to, especially the very first sentence… (There are similar sentences in other messages of the same thread.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 11
(1,251 Views)

Sorry, my fault.

 

hope this vi works for your,  because I cant convert the private library I am using to older versions. But my vi will not help much because, because the error occurs with this library.

 

So I want to clarify my problem a little more. I need to pass data out of my consumer loop to some other loops that have a large runtime. This works fine with a queue. But I need to declare the data type of the queue outside my consumer loop right? And my data type is the can chanel from the libary. But I cant initialize the chanel at this point. I initialize the chanel in my consumer loop if the user presses a button. Because of this, at the start there is an error. I know that I can prevent the error with correct error handling. But when I do this, the queue doesnt work when I pass an element later.

0 Kudos
Message 7 of 11
(1,218 Views)

Hi lvhvl,

 


@lvhvl wrote:

But I need to declare the data type of the queue outside my consumer loop right? And my data type is the can chanel from the libary. But I cant initialize the chanel at this point. I initialize the chanel in my consumer loop if the user presses a button. Because of this, at the start there is an error. I know that I can prevent the error with correct error handling. But when I do this, the queue doesnt work when I pass an element later.


You are mixing two things into one: "datatype" and "data value"…

You can define the queue with its datatype, no matter if you know a valid data value at that time.

You can send messages using the queue later on with correct data values!

 

General comments on your VI:

  • That VI is way too big. Try to implement it using more subVIs and (maybe!?) a better program design…
  • Your consumer will annoy the user with endless OneButtonDialogs when an upstream error occurs. The user will not be able to end the VI in this case…
  • Do you really need to handle CAN data using strings? Why not use byte arrays or arrays of clusters (to hold your CAN signals)?
  • IMHO you are using way too much local variables (or "value" property nodes)…
  • Lot of Rube-Goldberg like this:
  • When handling CAN frames usually the ArbID is given as hexadecimal value. You can make your VI more readable when you set the radix of the case structure condition to "hex"…

@lvhvl wrote:

But I cant initialize the chanel at this point. I initialize the chanel in my consumer loop if the user presses a button. Because of this, at the start there is an error.


There is an error just because you use queues in an Rube-Goldberg manner!

Why do you read those queue(s) using PreviewQueueElement!?

Why don't you use a proper ReadQueueElement???

Why don't you use the TimeOut output of the ReadQueue (with a proper timeout) to handle the "no element in queue" conditions???

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 11
(1,214 Views)

Thanks a lot for your help and thanks that you also reviewed the rest of the code a little bit.

 

Yeah, I was mixing up datatype and data value in this case. My fault.

 

I know that there is probably a lot of useless and over complicated code. I am using labview since 2-3 weeks and this is basically my first project so I have to improve the code step by step.

 

I use the preview queue because I add one element to the queue when I click init. And then I doesnt want to "lose" this channel element (the code will not execute a second time if there is no more element).

But youre right, this is not really good (and if the user will change the channel, the code will not work).

Thanks for your tip with the timeout element. Do you have any idea how I can "save" an element and pass it to the code every time it executes as long as there is a new element in the queue?

0 Kudos
Message 9 of 11
(1,202 Views)

Hi lvhvl,

 


@lvhvl wrote:

I use the preview queue because I add one element to the queue when I click init. And then I doesnt want to "lose" this channel element (the code will not execute a second time if there is no more element).

But youre right, this is not really good (and if the user will change the channel, the code will not work).

Thanks for your tip with the timeout element. Do you have any idea how I can "save" an element and pass it to the code every time it executes as long as there is a new element in the queue?


Suggestion:

When a loop (statemachine, QMH) needs to store "internal" (private) data you should use a shift register. When there is more than one data element I often use clusters to hold those private data. (Then it's just one step further to an OOP implementation…)

 

Maybe you should change the queue datatype(s) to allow a better producer-consumer scheme: often we use a cluster of [command enum/string, variant data]. This way you can easily send commands with their data to control statemachines or QMHs…

Best regards,
GerdW


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