01-10-2012 12:35 PM
Hi Labview Champs,
I am using serial port(SPI) to read some data. My code would skip every alternate packet. e.g. Data sent 11,12,13,14,15,16 ; Data received 11,13,15.
By probing into code and using breakpoints, I found that the iteration count of main loop while(or for) loop, which contains most of the code, increments by 2. e.g. 0,2,4,6,8,10... or 1,3,5,7,9... which is very strange..! This happens with both for and while loop.
If I set a breakpoint at the last instruction, and step into code, the iteration count would increment by 1 (which is something I expect). There are no horrific conditions for the main loop, just simple T/F control. i.e. while loop would exit if button has been pressed otherwise stay in loop.
If I change this condition so that main loop should run once only, and run vi by pressing "run continuously", I would get my lost packet. however, this way of running code clashes with some rules of sub vis I am using.
Help me, please?
01-10-2012 12:57 PM
Your VI would help.
01-10-2012 01:20 PM
Thanks for the reply. I have attached the vi.
01-10-2012 01:29 PM
I can not look at the code, but in these cases I usually suspect a hardware issue, often from banging the I/O too quickly. If you happen to have an error line in your loop I would probe it to see if it throws an error. It could be that you are getting errors in every other cycle and perhaps you could slow down a little bit.
01-10-2012 01:40 PM
I was able to open the VI except for the SPI-related VIs.
My suggestion which is similar to Darin.K would be to do as much data processing outside of your loop.
01-10-2012 02:18 PM
@EdgeTrigger wrote:
By probing into code and using breakpoints, I found that the iteration count of main loop while(or for) loop, which contains most of the code, increments by 2. e.g. 0,2,4,6,8,10... or 1,3,5,7,9... which is very strange..! This happens with both for and while loop.
I assume you are talking about the coerced "Numeric 3" indicator.
01-10-2012 03:59 PM - edited 01-10-2012 04:04 PM
You are sure doing a lot to convert an array of U8s to an array of U16s Just replacing the array functions (and cleaning up the (i+1)*2-1 to the equivalent i*2-1) saves a lot of BD space
I'm also guessing there is an easier way to cast a U16 into an I16
01-10-2012 04:40 PM
You can also add i+i+1. No multiply needed.
Both lines on the right carry the same values.
Lynn
01-10-2012 04:53 PM
I would suggest Altenback is correct. I don't know that it's hardware related, but your while loop is not "skipping" iterations. You say you are using breakpoints? Have you tried slowing things down by turning on Highlight execution? You will see your indicator changing at the proper rate with no skips. I suspect that on odd iterations, your loop is running through faster for you to see it.
01-11-2012 12:22 PM
Thanks a lot for your useful replies. Loop was not skipping iterations which I confirmed by using a auto indexed array. It's not hardware related. Indeed, I needed to save this data in a file, which confirms I am reading it correctly. Thanks again.