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: 

Project guidance - Timeout checker

Hello all,

 

I could use some help with code I'm about to write.  I have been working with communications over Ethernet with Arduinos and things go well ~80% of the time.  The other 20% I'm receiving a timeout error.  My current method for timeout checking is a butchered version of the LIFA code (originally USB communications) that I got working (Reference current_method.png ).  I have been thinking about redoing that code because it doesn't make sense to me.  From my understanding, it writes the data, then reads data being sent back, and if they aren't the same, continues reading the data.  However, the Arduino only sends the response once.  So, say I missed that response, I'm not going to see a new response sent. (Note, the original code has a wait for bytes at port property in the read visa area).  

 

Therefore, I'd like to create a system in which LV would send a command, wait a bit, and then read.  If the number of bytes being read isn't the same as the number that I am expecting, I want it to flush the buffer and retry up to 10 times.  

 

The first part I believe I have being sent correctly (Reference LVhelp.png).  My problem is with seeing if it is false, then redo the loop.  I was originally thinking about using a feedback node and put a case structure where if false, then loop again.

 

Any tips?

Download All
0 Kudos
Message 1 of 4
(2,034 Views)

Hi uke,

 


I was originally thinking about using a feedback node and put a case structure where if false, then loop again.


When I have to tackle a problem like yours I think of a While Loop set to continue as long as FALSE condition is given (or as is worded by LabVIEW: stop on TRUE)... 

 

What's the sense of reading zero bytes?

What's the sense of the wait function when you still have to wait for bytes to receive?

Best regards,
GerdW


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

Thanks for the response.

 

I just whipped that up the VI really quick to help illustrate my idea. In all actuality, bytes to be read would be a control and not a 0.  

 

Is there a way I can increment a number to hit 10 and then stop for a while loop?  I have been toying with that idea now but I am nusure how to get it to increment.  I believe I want to use a shift register.

 

If this works, the only thing I have left to do is create an error that says time out.

 

Matt

 

Edit:

I believe I got a proper VI working.  The attached LVhelp.png file is the actual code I'm going to impliment.

Download All
0 Kudos
Message 3 of 4
(1,995 Views)

So the code works better, but I'm still running into a problem.  When I start to get a timeout, the main problem is that I lose connection to my Arduino.  

 

can I use a case structure with shift register on the error to check for feedback if the connection is lost?  

 

My general confusion is with using a loop to give me feedback from the previous iteration.  My belief is that a shift register will take the variables previous loop value and use it for the current loop, such as the time out variable.  Where the first loop its 0, then 1, then 2, etc.  Is this the correct way to think of a shift register?

 

Matt

0 Kudos
Message 4 of 4
(1,988 Views)