LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

rs232 very slow

hello all,
wonder if you could help

im running a program on an item of automated test equipment and as part of the functionality i am sending rs232 "commands" to the box under test and then after a delay reading the response.
this function sits inside 2 while loops.
when i run the function i find that the data is not correct etc.

now when i run in debug mode (i.e. very slowly) the data i receive is correct). am i doing something wrong with the while loops?

i think that the os may not have enough time to do what it needs to do and my program is racing ahead.

although i thought that if i was in a while loop and did a visa read then write (with a 30ms delay in between) that would be ok.

im not an expert but i thought this would work


any ideas?

many thanks
0 Kudos
Message 1 of 11
(3,634 Views)
have a thought that if i had the rs232 function in a seperate while loop outside the nested 2 and passed information via variables this would free it up.

sound possible?

ta
0 Kudos
Message 2 of 11
(3,625 Views)

if you can, please post your VI. I, personally, find text descriptions of graphical code a bit challenging.

I typically do the following for RS232:

  1. Configure port outside of loop, passing reference in.
  2. FLUSH the buffer.
  3. Write the string.
  4. Start looping.
  5. wait up to 3s in 10ms increments checking for Bytes At port
  6. Read bytes and wait 10ms until no bytes ready.
  7. End looping
  8. Close port reference.

Good luck.

 

0 Kudos
Message 3 of 11
(3,614 Views)
aaaaaah!

i just noticed that in the inner while loop i have no timer.

this wouldn't help would it?
0 Kudos
Message 4 of 11
(3,604 Views)
In LabVIEW you should pretty much always have some soft of delay in a loop... else you LOAD the computer down.
Anything is better than no delay, but I typically do 10ms.
Message 5 of 11
(3,600 Views)
so to ask a stupid question.

is this why it may me running slow?
0 Kudos
Message 6 of 11
(3,599 Views)
Only way to know for sure is to try it! Let me know what you find.
0 Kudos
Message 7 of 11
(3,592 Views)
i will

thanks very much
0 Kudos
Message 8 of 11
(3,590 Views)
hi MattH,

hope i'm not hitting your patience threshold.
the reason i ask is i'm a hardware  eng doing this project.

its about the timer in the while loop.
i may have got it wrong about what this timer does.

would i be right, now i think about it, in saying that the 10ms timer allocates cpu (os) time every 10 ms, or as i originally thought allocates 10 ms at the end of the while loop.


because if it's the latter then a timer wouldn't help as i'm in the loop until i finish the task and so the os would still be stuffed.

ta (until i let you know what happened)
0 Kudos
Message 9 of 11
(3,587 Views)
Okay:
 
if you simply drop the delay in the loop and connect a 10ms delay it will start as soon as the loop begins (other code in the loop running) and won't allow the loop to continue until at least that 10ms has passed. LabVIEW uses a sleep wait which releases the processor for other tasks.
 
if you use the express VI (blue) and wire the error cluster into the code, then the delay will occur at the point in which it is placed.
 
The key here is that everything in LabVIEW is dataflow, meaning that nothing executes until all the data at it's input is ready. Code in structures (while loops etc) won't execute again until ALL code in the loop has completed... this is similar to what you see when you run the VI with Highlight Execution set. (The Light bulb on the toolbar of the block diagram) You will see the data moving along the wires and codes doesn't execute until all wires have data.
 
AND
 
your not testing my patience at all, this is what we do in the LabVIEW community. Helping and teaching others is part of it! Smiley Wink
0 Kudos
Message 10 of 11
(3,581 Views)