.NET2 SerialPort - 100% CPU problem

Hi,

I'm having a similar problem with VB express 2005 beta 2.

I have this code in the form_load:

Dim com1As IO.Ports.SerialPort

com1 =My.Computer.Ports.OpenSerialPort("COM1")' init com port

com1.Parity = IO.Ports.Parity.None

com1.StopBits = IO.Ports.StopBits.One

com1.BaudRate = 9600

That runs fine, but as soon as it gets to this code, it hangs. Occasionally it displays the correct data, but it stays hung.

While (5 = 5)

com1.Read(stuff, 0, 1)

TextBox1.Text = TextBox1.Text & stuff(0)' shoove it in textbox1

System.Threading.Thread.Sleep(1000) ' delay for a second

EndWhile
I have tried using read, readline, readchar and even readbyte, but exactly the same happens.

[1351 byte] By [Olim] at [2007-12-16]
# 1
Aha - found a nice fix for it. Just check if comobject.bytestoread is not zero. I discovered it only hangs if there's no data to recieve. I believe this can also be now put in a tight loop to get fast data recieveal.
Olim at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified