LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

serial read lag

Lab view people,

I seem to be having a weird issue with the serial read command…  This is the situation; I have a PIC that is configured to send the serial string AE if it detects and error. It is important to note that it almost never sends that command, and it doesn’t send anything else. (Disregard the BE, that you can see in the jpg.)

My issue is that during a certain loop of my VI I need lab view to read the port and make sure that the PIC isn’t sending AE. If it is then I need it to send add, if it isn’t then I need it to instantly move on.  The problem is that if it doesn’t receive the AE the VI lags for a bit and then moves on. If it receives the AE then the program does not lag. I believe the issue is due to the fact that lab view is expecting to receive the string, and since under normal operation it won’t receive it, it causes it lag a few seconds.

The lag is bad because it prohibits my program from reading a shaft encoder, causing my robot to go crazy. That’s not important really.

I have looked at the serial examples many times, and I understand them fully. (I think) but in my code I can’t have a case to switch between read and write. It has to read then continue a loop…

I’m not sure that I explained that in a matter that makes sense so please let me know what I can do to clarify this.

I am using lab view 8.5 on a windows XP machine.

Rather than try and attach all of my code, I simply cut down a screenshot of the area causing the problem. I should mention that if I remove the code in the jpg. From the main program it works perfectly. The serial setup command is not visually connected, because I had to cut and paste it from another spot on the code. I can’t fit the full image with print screen… but rest assured in my actual program it is connected. In my VI I have many other serial write commands but no other reads….

Just FYI, I added the visa close into it to try and speed it up... I’m not sure why you need the close, but it seems to speed it up a bit…. Also, I always get timeout errors and things when I use serial commands, so I use the error scrubber to make them go away. Thoughts?

Thanks for the help!

0 Kudos
Message 1 of 6
(3,182 Views)

I should also mention that the PIC is part of a homemade DAQ board. Ultimately I want that board to send position data from shaft encoders and other random data. The AE and BE is simply a test from the PIC to try and troubleshoot my read issue. I have noticed that I get this delay no matter what I do. If I want to read something and then write something I always have this problem.

If I tell my PIC to constantly send out a termination character regardless of the AE error data, will that cause the read to move on? The problem there is that I’m not sure how to enter a termination character. I believe I have to wire a True to the enable thing, and then wire a hex value for the letter I want. So if I want to use E as my termination value shouldn’t I use the number, 45?

It also seems that when I try and use termination characters lab view randomly crashes.

0 Kudos
Message 2 of 6
(3,181 Views)

You really could have included more of the code on the screenshot or even the VI itself so we can see the structure of the rest of the program.Smiley Wink

Why are you closing the VISA reference immediately after the read?  And then again immediately after the write within the case structure?  I think what is happening is that you read something, close the com port, then when you go to write something, it takes time for the com port to reopen again.

I assume this is all part of a larger loop that you didn't show.  Open and/or configure the com port before the loop, do your reads and writes within the loop, and only close the com port after the loop.


kd5pff wrote:

.

If I tell my PIC to constantly send out a termination character regardless of the AE error data, will that cause the read to move on? The problem there is that I’m not sure how to enter a termination character. I believe I have to wire a True to the enable thing, and then wire a hex value for the letter I want. So if I want to use E as my termination value shouldn’t I use the number, 45?

It also seems that when I try and use termination characters lab view randomly crashes.



Termination character is enabled by default.  The value is the decimal value of the ascii character, so for E you would need 69.  (The default is 10, linefeed).  You have to be careful with termination characters, if you pick something that could be part an ordinary data stream, then you risk the read terminating early.  Are you sure you are always receiving 2 bytes?  What if you are only getting 1, or more than 2?  Don't clear the error coming out.  Wire it to an indicator of an error cluster on the front panel so you can see if you are getting any errors.  Error wires should be wired through the various functions, not indiscriminately cleared.
 
Yes, the Read will move on when either the number of bytes to read is received or the termination character is received.
0 Kudos
Message 3 of 6
(3,168 Views)

Hi kd5pff,

I have found that many of the examples set up the serial port to timeout or wait for a number bytes to come in.

I prefer to not use that methodology.  Instead, use a property node to inspect how many bytes are waiting at the port, then read that number of bytes.  That way you are never waiting for the timeout to occur.  If you are looking for a single byte (no other messages coming in) then it will be simple to scan the data for the byte you are looking for.  In more complex situations, I set up a state machine to hold partial messages between serial port reads, since you can never guarantee that when you read the data you have included a full message, or that it is valid.

For example, if messages are streaming in, and your standard message is 10 bytes, you can set it up so you read 10 bytes from the serial port.  But those 10 bytes may be actually spanning two messages......

Best regard and good luck!

Message 4 of 6
(3,152 Views)

LabVIEW people,

                Thanks for the input! The property node technique seems to have worked perfectly… I wont know for sure until I hook up to the beast, but it using the virtual port and watching my serial streams, seems to be working perfectly. I really appreciate it.. Hopefully someday ill be able to answer some questions for you guys. It always amazes me that there is always someone on this forum able to solve any problem…. Thanks again…

 

BTW I posted a less zoomed in version of my code… I still need to clean it up and make it more efficient, but its getting close…

0 Kudos
Message 5 of 6
(3,128 Views)
Hi kd5pff,

I wouldn't call it "but its getting close" when having several "stop" functions in the code (inside a while loop, inside sequence, inside while, inside while, inside case) Smiley Very Happy


Message Edited by GerdW on 04-14-2008 04:50 PM
Best regards,
GerdW


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