473,394 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

newbe question on VB.net. programming hanging

ken
Hi all,
I copied this code from the examples. "How to: Receive Strings From
Serial Ports in Visual Basic" When I call the function and using the
single step method it hangs at Dim Incoming As String =
com1.ReadLine(). I don't have anything connect to Comm1. Does anyone
know why this is happening? Thanks for the help.
Regards,
Ken
Function ReceiveSerialData() As String
' Receive strings from a serial port.
Dim returnStr As String = ""

Using com1 As IO.Ports.SerialPort = _
My.Computer.Ports.OpenSerialPort("COM1")
Do
Dim Incoming As String = com1.ReadLine()
If Incoming Is Nothing Then
Exit Do
Else
returnStr &= Incoming & vbCrLf
End If
Loop
End Using

Return returnStr
End Function
Jan 16 '06 #1
6 1473
ken <so******@out.there> wrote:
I copied this code from the examples. "How to: Receive Strings From
Serial Ports in Visual Basic" When I call the function and using the
single step method it hangs at Dim Incoming As String =
com1.ReadLine(). I don't have anything connect to Comm1. Does anyone
know why this is happening?


Yes - it's waiting for a line of data to come into Comm1. If you
haven't got anything on Comm1, it's never going to receive a line of
data. Think of it as a call to Console.ReadLine on a computer without a
keyboard attached.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 16 '06 #2
Possibly solutions to this are peek() (although not sure if this works
in all circumstances) - or more advisably, although more difficult, is
to run another thread.

Ian

Jan 16 '06 #3
ken
I understand that but, Don't the next two lines of code address that?
Dim Incoming As String = com1.ReadLine()
If Incoming Is Nothing Then
Exit Do
Ken
Jan 16 '06 #4
ken <so******@out.there> wrote:
I understand that but, Don't the next two lines of code address that?
Dim Incoming As String = com1.ReadLine()
If Incoming Is Nothing Then
Exit Do


No, they won'y address it if ReadLine returns Nothing if there's
nothing attached to the serial port. Does the documention suggest that
that's the case? I can't see anything to that effect.

I'd expect a serial port to act as a potentially never-ending stream of
data. Then again, I don't know much about serial port programming...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 16 '06 #5
Ken,

If you want, you can ask this question in the newsgroup

microsoft.public.dotnet.languages.vb

However, put Serial Port in the subject of your question

Dick Grier will probably answer you then. He has probably an automatic
search on that. I thought he has this group as well in that search so you
can sent it as well with a new subject to this, but I am not sure of that
he searches here as well.

I hope this helps,

Cor
Jan 16 '06 #6
ken
Thank you Jon and Cor for the reply. Being new to Vb I need all the
help I can get and I will poet my question to
microsoft.public.dotnet.languages.vb in the future.
Regards,
Ken
Jan 16 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Arben Qarkaxhija | last post by:
Hello all, I'm new to AS400 and we have a problem here with a sql-procedure, that is running OK over the Client Access Navigator, but over the 5250 emulator hanging with an error "pointer for...
3
by: Les Coover | last post by:
I am taking my first structured programming class and we will be doing some C programming. Perhaps latter I will be taking other classes developing C programming further but I don't need anything...
17
by: Eric_Dexter | last post by:
def simplecsdtoorc(filename): file = open(filename,"r") alllines = file.read_until("</CsInstruments>") pattern1 = re.compile("</") orcfilename = filename + "orc" for line in alllines: if not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.