473,569 Members | 2,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ReceiveSerialDa ta() As String
' Receive strings from a serial port.
Dim returnStr As String = ""

Using com1 As IO.Ports.Serial Port = _
My.Computer.Por ts.OpenSerialPo rt("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 1481
ken <so******@out.t here> 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.ReadLin e on a computer without a
keyboard attached.

--
Jon Skeet - <sk***@pobox.co m>
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.t here> 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.co m>
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.publi c.dotnet.langua ges.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.publi c.dotnet.langua ges.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
3608
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 the given position not set" (anything like that I think, I have the error in german and here I mean, I have just translated it, but not sure, if the...
3
1626
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 very fancy just something basic that will compile and run my C programs (with some kind of editor window if it isn't too much extra). What do you...
17
2692
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 pattern1 print >>orcfilename, line I am pretty sure my code isn't close to what I want. I need to be able
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.