VB2005 Serial Port Loosing Memory When Receiving Data

P

p-metcalfe

I'm having serious problems using the serial port with VB / VS2005.

I'm running CF2.0 on this little board ...
http://www.fs-net.de/Home_Eng/Products/NetDCU/NetDCU8/netdcu8.html

It works fine, in that I can send and receive bytes, but I slowly loose
program memory WHEN there's data being received. I can transmit data
for ever and the memory remains constant. But when data is being
received by the NetDCU8 board, (even if there's no code in place to
read it) the memory slowly fills up and eventually (after about 20
minutes) the board almost stops because there's no memory left. I only
see the problem when the port is Open AND data is being received by the
board, then the memory slowly disappears no matter what I do with the
code, even if I continuously clear the 'In' buffer etc.

If I Close the COM Port or if I stop sending data to the board, the
memory stops filling up. But the memory never recovers until I stop the
application. If I insert a Break point, or Pause the program or even
close the port and call the "GarbageCollector", the memory never
recovers. The only way I've found to recover the memory is to end the
program.

I've written a simple example program to just echo everything received
from COM3 straight back out again.

My code looks like this;

Imports System.IO.Ports

Dim Rs232 As New SerialPort("COM3", 38400)

Dim x(2) as Byte

Sub Main

Rs232.Open()

While (True)

x(0) = Rs232.ReadByte() ' Wait for 1 byte, grab from
'In' buffer and store in X(0).

Rs232.DiscardInBuffer() ' Ensure the 'In' buffer is now
empty

Rs232.WriteByte(x , 0 , 1) ' Transmit 1 byte from buffer
x() at Offset 0

End While

End Sub

This code works fine and will run for ever with no data being received.
When I send data to the board, the program still works OK and echoes
all the characters perfectly but the memory starts to slowly get used
up and after 10 to 20 minutes of receiving data continuously it will
slow right down because there's no memory left.

If I simplify the code to look like this I get the same problem....

Imports System.IO.Ports

Dim Rs232 As New SerialPort("COM3", 38400)

Sub Main

Rs232.Open()

While (True)

Rs232.DiscardInBuffer() ' Ensure the 'In' buffer is now
empty

End While

End Sub

This code does nothing except clear the In buffer and the memory still
fills up IF there's data being sent to the board. I can remove the
"DiscardInBuffer" line and the I get the same problem.

I'm observing the "Program Memory" using the System Properties program
under Control Panel.

Is this a hardware fault, Driver Fault, Windows Fault?

Can you help me or suggest what to do next. I'm completely stuck now!

Many thanks



Paul.
 
G

Guest

If you do a similar test with a native C app (even something like a terminal
emulator) do you see the same problem? It could be a leak in the driver.

-Chris
 
D

Dick Grier

Hi,

I haven't seen this on my Pocket PC (Axim x51v). I suspect a problem
somewhere other than VS2005.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top