Page 1 of 1

OnRead getdata in buffer although BufferSize=0 !!!

Posted: Wed Sep 01, 2004 3:49 pm
by Alon
Hello,

I've got a problem regarding the "OnRead" event of the SerialTools for Pocket PC.

Here is my "OnRead" sub:

Private Sub objPort_OnRead(ByVal Data As String) Handles objPort.OnRead
If Data Is Nothing Then
'[Do Nothing]
Else
'[Do Something Function]
End If
End Sub

In [Do Something Function] I'm reading the data I got from the port. To be sure the data is good for me I'm using a checksum which is in the last byte.
Now, for example, I'm supposed to get 97 long bytes array (the checksum will be on the 97 place in the array).
At present, the OnRead Event is triggered after 32 bytes has been received - this activate the [Do Something Function] which in it's turn get a failed checksum (the last byte in this 32 bytes array is not true checksum since it was supposed to be 97 long and the checksum is on last byte - in place 97...)

I just want to emphasize that my BufferSize is set to Zero (when I defined it to 80 for example it worked just fine - the OnRead event triggered only when it had 80 bytes in it's magazine, but I cannot use it since my data's length is not set).

My BaudRate is 4800 and the Timeout is 5000.

Anyone knows if this a problem or this is it for this product (which means i must search for other com port solution....) ?

thanks,

Alon

RE: OnRead getdata in buffer although BufferSize=0 !!!

Posted: Wed Sep 01, 2004 3:52 pm
by johan
This is something you solve with the design in your application. You need to save the data coming in the OnRead() event in a buffer. Then each time you parse that buffer to see if you got a complete and good sentence with valid checksum.

Regards,
Johan

Franson Support

RE: OnRead getdata in buffer although BufferSize=0 !!!

Posted: Wed Sep 01, 2004 4:15 pm
by Alon
well, then the timeout and the buffersize=0 are loosing their value ...
you see, between each of my sentences, the comport get GPS and my application transfer it into the "Destinator" navigation program. i distinct the GPS and my good sentences with the timeout (anyway, i wanted to).

so, if there's no a solution for this, i need to read each byte (buffersize=1, timeout=0), collect the bytes into my buffer and run a timer of my own to check the data...

RE: OnRead getdata in buffer although BufferSize=0 !!!

Posted: Wed Sep 01, 2004 4:21 pm
by johan
Take a look at Port.EndTrigger in the reference manual. It will probably help you.

Regards,
Johan

Franson Support

RE: OnRead getdata in buffer although BufferSize=0 !!!

Posted: Sun Sep 12, 2004 6:49 pm
by rguarino
I am having a similar problem and cannot use End Trigger since my messages are both Text and Binary. I have buffer to 0 and expected it would fire onread each time anything was in the buffer. When i ask for a binary message I only get the first char 'E' but the record is 65 bytes in total length. Whne i display length of data in buffer it is 1.
When I do the same in hyper terminal i see the binary message appears after the send.
What is happening here with the onread event and what could make it not read the rest of the binary message?
Thanks

RE: OnRead getdata in buffer although BufferSize=0 !!!

Posted: Sun Sep 12, 2004 7:36 pm
by rguarino
Additional info. i am using the stringtobytearray method. Here is a sample of the code.
'objPort.Read(0, 5000)
bytes = objPort.StringToByteArray(Data)
Dim ms As New MemoryStream(bytes)
Dim r As New BinaryReader(ms)
MsgBox("message size " & ms.Length)
msg = objPort.ByteArrayToString(bytes)
ms.length is 1 and msg is 'E' Vers 1.20 of Serial tools, VB.net on XP Pro.
Also when i try the Noevents sample on the port which is on Com7 it says itis not in use when in fact i try it under terminal and it works fine. Also works with the Sample1 which i am using as the base for my program. Any idea on that? Was trying the noevents to see what it found on the port.
Thanks Rich

RE: OnRead getdata in buffer although BufferSize=0 !!!

Posted: Mon Sep 13, 2004 9:56 am
by Alon
hi,
I've solved my problem with the following code:

Private DataBuffer As String = String.Empty

Private Sub objPort_OnRead(ByVal Data As String) Handles objPort.OnRead
If Data Is Nothing Then
If DataBuffer <> String.Empty Then
HandleReadData(DataBuffer)
DataBuffer = ""
End If
Else
DataBuffer += Data
End If
End Sub

where "DataBuffer" is a global variable who collect the data from the port and "HandleReadData" is the function who deals with the whole data come from the port between 2 timeouts.
hope it will help you,

Cheers,