LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Losing characters in serial communication

Hi.
I am trying to develop an application as part of an assignment.
The assignment requires that we use the serial compatibility mode (and
we have a stripped down serial link with no hardware handshaking).

The problem I have is quite straight forward.
One computer builds a string (a packet) and sends it byte by byte over
the serial line.
The other computer sits in a while loop, and waits for a special
character to signify the start of a string... (it is looking for a
"["). When it sees this, it moves to the next frame of a sequence,
and reads byte by byte appending to a string, until it sees the end
character (which is a "]").

If I run the receving end in highlight execution mode, everything
works as expected. If however,
I run the programs in normal mode, I
lose random characters from the start of the string..

So if I should receive "[a1:b1:test]" I might only receive "[:test]".

Can anyone suggest why this is happening, or another possible solution
which wont have this problem.

I have tried putting a 100ms delay in each loop, which seems to solve
this problem, but a 100ms delay is not acceptable for the purpose of
this application.

I am not asking for help completing the assignment, I am merely stuck
with this issue and cant continue until this problem is solved.

Any help is greatly appreciated,

Jason
0 Kudos
Message 1 of 4
(3,177 Views)
Hi Jason,

I haven't got the experience losing characters. But I do use a wait in the while loop. Most I use 10 milliseconds. I use "Bytes at serial Port" to get the number of bytes in the buffer. Then I read the buffer and concatenate the strings together. With the string functions I search for the delimiting characters. If I have found them I will remove the desired string. The rest of the string is holded in a shift register until the next packet is to extract.

This has a maximum delay of one wait.

So change your algorithm from byte by byte operation to string operation.

Waldemar.
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 2 of 4
(3,177 Views)
i have run into problems losing characters by having a read routine that clears the input buffer first. ie... my routine would:

-get number of bytes available
-read that number of bytes from port (but not save the output)
-send a command if one needed to be sent
-wait for characters to store/return, looking for a cr or end of line (or timing out)

this routine, when called in a loop, loses characters because the first few are erased. the routine was designed to clear the input buffer, send a command, then wait for a response. when using it oustide of that functionality to just wait for a response, it erased available bytes when starting.

this doesn't sound like your problem but perhaps some added insight.
0 Kudos
Message 3 of 4
(3,177 Views)
HI Jason,

Others have tried but I see no winners yet.

Post your code and someone will take a look.

I am much better with visual aides.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 4
(3,177 Views)