LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Tips to remember when using Queued State machine

Solved!
Go to solution

Edit: another image attached

I may not be perfect, but I'm all I got!
0 Kudos
Message 61 of 75
(2,281 Views)

VeeJay,

 

The images help.  Seeing the entire VI (or a simplified version of it) will be best.

 

In the version where the deQ output goes to the shift register and the left side of the shift register is wired to the acse structure of the state machine, the state machine can begin workin on the data from the previous iteration immediately without waiting for the next dequeue.  In that sense it may be somewhat faster.  It really is impossible to say without knowing all the timing details.

 

Lynn

0 Kudos
Message 62 of 75
(2,268 Views)

I am really working hard to get a version posted. Will do that pretty soon.

 

I am still lost with these timeouts and it is really affecting my application. Questions:

 

1) What is the use of timeout on VISA configure? It gains precedence in controlling my 1st loop hence my 2nd loop runs at that. From what I tested, once constant communcation starts, Loop 1 has a time of 200ms per iteration. I want loop 2 my state machine to run at 10ms and not be affected by loop1

 

2) What is a timeout on a Q? I guess I am confused on what a timeout in general means? Basic examples will help me understand.

 

3) If I decrease timeout of VISA Configure to 10ms just to make sure my loop 2 state machine runs at 10ms, my cluster that I deQ from Loop 1 keeps changing values every iteration.

 

4) There are very basic definitions on what timeout it without concrete examples. It is getting very difficult to understand with so many timeouts in my application 😞

 

5) What does wait until ms time have to offer in this situation?

 

Any help will be grately appreciated. Thanks!

I may not be perfect, but I'm all I got!
0 Kudos
Message 63 of 75
(2,260 Views)

VeeJay,

 

I will start with question 2)b What are timeouts in general?

 

A timeout is used to keep a portion of the program from waiting forever.  Look at the case of a serial read. In your serial loop you try to read one byte.  If the remote device has failed or the cable has been disconnected, the VISA Read has no way of knowing that so it will wait indefinitely for that byte.  Because of dataflow the loop will not complete its iteration until that byte is read. So, you cannot stop the loop and anything which depends on that loop like the enqueued data will also be delayed.  The timeout, in effect, is a way for the function to say, "I am tired of waiting for the byte which is past due and may not be coming at all." 

 

Using timeouts to set the loop timing is a secondary effect and will not be accurate if data arrives before the timeout.  This is because the Read (or Dequeue or whatever) returns immediately when the expected data is present. The timeout will set that maximum time to wait but not the minimum.

 

1) The timeout on VISA configure sets the timeout for all VISA functions on that port which may need to wait for data, primarily the Read function.  The primary purpose of serial port timeouts is to allow the program to recover from disconnected cables or non-responsive external devices.

 

The default timeout for serial ports is 10 seconds (not milliseconds!). The VISA timeout has nothing to do with the loop 1 timing.  If it is taking 200 ms, that most likely is due to the time it takes the remote device to respond.  I think we determined that it only takes a little over 10 ms to transmit the data (plus a few more ms to send the ACK). To get that much extra delay in the loop something else must be happening.

 

2) Timeout on the Dequeue function is the maximum time the function will wait for an element to appear in the queue. If an element is already present when the fucntionis called, it returns the element immediately and timed out? is False.  If no element is in the queue when Dequeue is called, the function waits until an element appears or the timeout is reached, whichever comes first.  If data shows up at 9.99 ms, the element will be at the output and timed out? is False.  If no data shows up before the timeout, then the data output has the default value for the datatype and timed out? is True.

 

3) The VISA Configure timeout can only be set in integer seconds.  To get shorter timeouts you must use the property node.  The cluster at the Dequeue will be exactly what the cluster at the Enqueue was unless a timeout occurred in which case the value will be default.  This is why it is necessary to check the timed out? output on the Dequeue function.

 

4) Yes!

 

Sorry, that is not very helpful.  This is why I suggested a timing diagram or flow chart of some type to try to define what should happen and when.

 

5) Probably nothing.  It may make you feel like you have the timing under control, but it mostly adds anaother layer of complexity.

 

Lynn

Message 64 of 75
(2,255 Views)


I will start with question 2)b What are timeouts in general?

 

A timeout is used to keep a portion of the program from waiting forever.  Look at the case of a serial read. In your serial loop you try to read one byte.  If the remote device has failed or the cable has been disconnected, the VISA Read has no way of knowing that so it will wait indefinitely for that byte.  Because of dataflow the loop will not complete its iteration until that byte is read. So, you cannot stop the loop and anything which depends on that loop like the enqueued data will also be delayed.  The timeout, in effect, is a way for the function to say, "I am tired of waiting for the byte which is past due and may not be coming at all." 

 

Ok That clarifies what timeouts are. I thought it was something to do with the inability to read the data even though it is available. I wonder why my assumption went there.

 

Using timeouts to set the loop timing is a secondary effect and will not be accurate if data arrives before the timeout.  This is because the Read (or Dequeue or whatever) returns immediately when the expected data is present. The timeout will set that maximum time to wait but not the minimum.

 

Understoood! But, why is it that if I set VISA READ to a small value timeout like 50 ms, Loop 1 is runs at 50ms but with many many problems: 1) I get the error -1073807339 all the time and sometimes it flip flops between error and no error 2) When I set VISA READ timeout to 1 second (1000), I see that loop 1 runs at 200ms and it directs loop2 to run at 200ms, in this case, I don't see the error -1073807339 once communication starts.

 

1) The timeout on VISA configure sets the timeout for all VISA functions on that port which may need to wait for data, primarily the Read function.  The primary purpose of serial port timeouts is to allow the program to recover from disconnected cables or non-responsive external devices.

 

OK!!

 

The default timeout for serial ports is 10 seconds (not milliseconds!). The VISA timeout has nothing to do with the loop 1 timing.  If it is taking 200 ms, that most likely is due to the time it takes the remote device to respond.  I think we determined that it only takes a little over 10 ms to transmit the data (plus a few more ms to send the ACK). To get that much extra delay in the loop something else must be happening.

 

THe VISA Configure Timeout defaults to 10000, so can I not set 200 for it to mean ms? Just curious.!! 🙂

I think you are right in that the device responds that late. At this stage, I have set Q and Notifier timeout to 0ms and calculating the iteration time reveals 200ms which should be solely due to VISA functions. In this case, VISA timeout is set to 1 sec as explained before.

 

2) Timeout on the Dequeue function is the maximum time the function will wait for an element to appear in the queue. If an element is already present when the fucntionis called, it returns the element immediately and timed out? is False.  If no element is in the queue when Dequeue is called, the function waits until an element appears or the timeout is reached, whichever comes first.  If data shows up at 9.99 ms, the element will be at the output and timed out? is False.  If no data shows up before the timeout, then the data output has the default value for the datatype and timed out? is True

 

IN my model, I am making sure there is an element all the time. DeQ keeps up with enQ or lags by a few elements. Hence, I hypothesize that I should never get timeouts. But, somehow, I see some timeouts and this is mainly in the fast case scenerio and not when loops run at 200ms

 

Is it that my model ties up VISA to a Q that there is so much complication? I somehow feel like my Loop1 and Loop2 are somehow in sequence because of the Q. I never had problems when I was using wireless communication using property nodes to send data from loop1 to loop2.

 

OK Maybe this is what I have been missing out. "If no data shows up before the timeout, then the data output has the default value for the datatype and timed out? is True" Where is this default value coming from? Is it the constant cluster connected to the Q to represent datatype? The specific reason to avoid this is why I use shift registers, but if the deQ is setting to default values due to timeout, then feeding that to shift register makes no difference. Maybe I should use the timeout TRUE to ignore the defaults.

 

3) The VISA Configure timeout can only be set in integer seconds.  To get shorter timeouts you must use the property node.  The cluster at the Dequeue will be exactly what the cluster at the Enqueue was unless a timeout occurred in which case the value will be default.  This is why it is necessary to check the timed out? output on the Dequeue function.

 

Get it now. I think I understand why I see those default values when I want what values I sent.

 

4) Yes!

 

Sorry, that is not very helpful.  This is why I suggested a timing diagram or flow chart of some type to try to define what should happen and when.

 

5) Probably nothing.  It may make you feel like you have the timing under control, but it mostly adds anaother layer of complexity.

 

 

In Summary, I want my state machine to run at 10ms cycle and dont care how fast or slow Loop1 runs. But somehow, Loop1 controls Loop2 speed and that is causing problems. 







VJ

I may not be perfect, but I'm all I got!
0 Kudos
Message 65 of 75
(2,249 Views)

VeeJay,

 

I see where there has been some misunderstanding.  I thought you knew some things which apparently you did not. And I made some mistakes of my own.

 

I think we have clarified the concept of timeouts and can move on to specific implementation issues.

 

The label on the timeout input of the VISA Configure is "timeout (10 second)."  I did not look at the default value.  The default is 10000 and is in milliseconds.  You are right. It can be set to shorter values without using the property node.

 

When you are running VISA Read with 50 ms timeout and getting frequent -1073807339 (timeout) errors, this suggests that the remote device is taking longer than 50 ms to respond.  We determined that it only takes 2-10 ms to transmit the data.  By eliminattion this suggests that the device does not begin transmitting immediately, but takes ~200 ms to get ready.  This is not unusual, depending on what the device does. Since you have Speed and Angle outputs from the device, I infer that it involves mechanical motion of some type. For devices like that tens to hundreds of milliseconds to respond is common.  It probably sends a burst of bytes (few ms) and then pauses (~200 ms) before the next burst.  If you have access to the data lines and an oscilloscope you could see a pattern like that.

 

The VISA timeout of 1 second is probably about right.  If you get the timeout error with that setting, it likely indicates a problem with the device.

 

2) 3) and Summary) Yes. Use the timed out? output.  If it is True, do not put anything into the shift register (or perhaps the queue). This shoudl be checked on any function which is set for a finite timeout.

 

This is where you need to look at the overall timing of your program.   Do you want to rely on queues having something enqueued every 10 ms whether there is any new data or not? How will you handle the "nothing changed" situation?  Considering that it appears that your device only generates new data 5 times per second, does spinning the loops at 100 times per second make sense?

 

Remember that LabVIEW is a dataflow language.  Your system appears to be driven by the data from the device. Let your program do something only when new data arrives (including new inputs from the user via the front panel).  This will require thinking about things in a somewhat different manner, but may lead to a ssimple and more responsive program.

 

Lynn

0 Kudos
Message 66 of 75
(2,239 Views)

Hi Lynn,

 

I did some testing and here are some more comments. I feel I am gettting closer to getting the timing parameters right. Here is what I observed.

 

1) Notifiers have a timeout 0ms since I feel that they don't really matter in this equation.

2) Event Loop like you said need not run every 10ms timeout. I tried that and it works. But, for some event cases, I want latch action boolean but the RT menus new value is not so. Hence, I reset them in timeout case. To enter into say "RESET" case of SM, I choose RT menu "RESET", its new value will be TRUE, I enter the RESET CASE in SM of Loop2  and I set RESET=FALSE in timeout case of event structure else it RESETS constantly.

 

3)Even if I set timeout for Event structure Q, I make it 0ms to not interfere with my SM loop iteration time WHICH i need it to be 10ms because of the way my DAQ acquisition has been setup and averaging and stuff.

 

4) The main contributor is Loop1 SERIAL loop. I think you are right, VISA COnfigure is seconds. When I set default, I saw 10000ms = 10sec hence I was setting that value to like 150 etc which means 150s. Now I use your method.

 

5) The only problem I am having is the following.

 

VISA READ = 10ms -> SM loop runs around 15ms at that speed. by earlier calculations VISA needs some more time, it ends up being around15ms.

 

deQ from SERIAL Q timeout is set to 10ms ==> causes constant timeouts and gets me those default values which is affecting my system.

 

deQ timeout = -1 , SERIAL timeout =10ms makes Loop1 and SM loop2 run closer to required 10ms. Seems to work GREAT 🙂

I just don't want to change any of my DAQ measurements which have been tuned to 10ms reading and averaging. If loop timings dont make sense to you, then I will have to take that into account. By not letting my deQ timeout, I am saving myself from those default valuve which honeslty I dont know how to solve. Shift registers don't work here to maintain values because they are being fed from deQ timeout constant cluster.

I may not be perfect, but I'm all I got!
0 Kudos
Message 67 of 75
(2,237 Views)
Solution
Accepted by topic author VeeJay

VeeJay,

 

1) I agree that the the notifier is not an issue.  The default value is False and you only care about True outputs.  The True output will only occur when the Stop notification is sent.

 

2) I have not seen the state machine, so I cannot comment here.

 

3) Consider whether the DAQ should be in a parallel loop of its own, running at 10 ms.  Then you get to add another queue!  Just when you thought this was starting to make sense, I complicate it again.Smiley Happy

 

Lynn

Message 68 of 75
(2,235 Views)
Haha Lynn! I invite complication. Few weeks back I was intimidated to use queues now I am comfortable thanks to u!

I kinda went opposite to what you suggested with regards to visa timeout. What I noticed with my device which actually is another software on the same computer that sends data through com port which I loop back to the same computer for labview to read, is that deQ is an extension of the serial loop. Hence, having no timeout on the deQ with a timeout of required 10ms helped because in my system technically there should not be any timeout coz values are enQd and deQd all the time

I do However like ur suggestion regarding separate looP for daq analog voltage multiple channels and Qing them in

V
I may not be perfect, but I'm all I got!
0 Kudos
Message 69 of 75
(2,232 Views)

Hi Lynn,

 

How are you? Things are moving along quite well, but now am dealing with DAQ analog inputs because my loop rate has changed. Basically, since it is slower, I am not getting as many data points. BUt, I am working on that .

 

I am however wondering how I can avoid the constants filling in when I apply a timeout on the deQ from Loop1. I am just not seeing how I can check for timeout and pass the right values through. The main problem is that my deQ values are controlled by Loop1.

I may not be perfect, but I'm all I got!
0 Kudos
Message 70 of 75
(2,205 Views)