473,385 Members | 1,474 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,385 software developers and data experts.

SerialPort read VB.Net 2005 Beta 2

I need some codes that able to send and read data by serialport in VB.Net
2005 beta 2. I wrote some codes and It can send data via serialport but It
cannot read what I send. I have looked up on internet and msdn and found
some codes and samples but they are also can't read serial port. . It was so
easy in VB 6.0 with mscomm object and oncommread events but now I don't
understand how it reads data from serialport. You can see the codes bellow
but while It trys to read data from serialport the program is frozen. What
is it worng and how can I fix it?

Thank you.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
GetSerialPortNames()

End Sub

Private Sub cmdOpenPort_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdOpenPort.Click

If comPort.IsOpen Then comPort.Close()

OpenPort(cboPortName.Text)

End Sub

Private Function OpenPort(ByVal PortNo As String) As Boolean

With comPort

If .IsOpen = True Then Close() 'close the port

..PortName = PortNo

..BaudRate = 9600

..Open()

End With

OpenPort = True

End Function

Sub GetSerialPortNames()

' Show all available COM ports.

For Each sp As String In My.Computer.Ports.SerialPortNames

cboPortName.Items.Add(sp)

Next

End Sub

Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSend.Click

SendSerialData(txtOutput.Text)

End Sub

Sub SendSerialData(ByVal data As String)

' Send strings to a serial port.

If comPort.IsOpen = False Then

MsgBox("The port is not open")

Else

comPort.WriteLine(data)

End If

End Sub

Private Sub cmdRead_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdRead.Click

txtOutput.Text = ReveiveSerialData()

End Sub

Function ReveiveSerialData() As String

' Receive strings from a serial port.

Dim returnStr As String = ""

Do

Dim Incoming As String = comPort.ReadLine

If Incoming Is Nothing Then

Exit Do

Else

returnStr &= Incoming & vbCrLf

End If

Loop

Return returnStr

End Function

End Class

Nov 21 '05 #1
1 8554

"Tolgay Gül" <to****@gul.com> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP12.phx.gbl...
I need some codes that able to send and read data by serialport in VB.Net
2005 beta 2. I wrote some codes and It can send data via serialport but It
cannot read what I send. I have looked up on internet and msdn and found
some codes and samples but they are also can't read serial port. . It was so easy in VB 6.0 with mscomm object and oncommread events but now I don't
understand how it reads data from serialport. You can see the codes bellow
but while It trys to read data from serialport the program is frozen. What
is it worng and how can I fix it?

Thank you.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
GetSerialPortNames()

End Sub

Private Sub cmdOpenPort_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdOpenPort.Click

If comPort.IsOpen Then comPort.Close()

OpenPort(cboPortName.Text)

End Sub

Private Function OpenPort(ByVal PortNo As String) As Boolean

With comPort

If .IsOpen = True Then Close() 'close the port

.PortName = PortNo

.BaudRate = 9600

.Open()

End With

OpenPort = True

End Function

Sub GetSerialPortNames()

' Show all available COM ports.

For Each sp As String In My.Computer.Ports.SerialPortNames

cboPortName.Items.Add(sp)

Next

End Sub

Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSend.Click

SendSerialData(txtOutput.Text)

End Sub

Sub SendSerialData(ByVal data As String)

' Send strings to a serial port.

If comPort.IsOpen = False Then

MsgBox("The port is not open")

Else

comPort.WriteLine(data)

End If

End Sub

Private Sub cmdRead_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdRead.Click

txtOutput.Text = ReveiveSerialData()

End Sub

Function ReveiveSerialData() As String

' Receive strings from a serial port.

Dim returnStr As String = ""

Do

Dim Incoming As String = comPort.ReadLine

If Incoming Is Nothing Then

Exit Do

Else

returnStr &= Incoming & vbCrLf

End If

Loop

Return returnStr

End Function

End Class


Hi,

read this:
http://www.codeproject.com/csharp/Se...munication.asp

Greeting

Thomas
Nov 21 '05 #2

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

Similar topics

1
by: seankub | last post by:
I am trying to read data from com1 and I am using the new serialport control. I downloaded the script from microsoft that does a readline from the comm port, but I keep getting the "operation timed...
1
by: Richie Carey | last post by:
Here's my problem. I'm using Visual C# 2005 Express for a small project that requires simple AT modem commands to be sent to an external serial device. The device requires 2400 baud, no parity,...
0
by: Nathan Ie | last post by:
Hi there! Not sure how many of you out there are familiar with the Serialport Class, but I'm trying to add an event handler for every time I receive new incoming data from the serial port by...
1
by: Don Tucker | last post by:
Hello, I am using Visual Studio .Net 2005 beta. I have my computer's two comm ports connected with a serial cable (and null modem). I'm trying to write the letter 'a' out on comm port 1 with the...
6
by: DraguVaso | last post by:
Hi, I'm experimenting with the Serial Port in VB.NET 2005. Although it isn't that easy to get any feedback from my COM-port as I thought it would be... How can I read all the Data that the...
2
by: Andrea Judge | last post by:
Hi there, I'm developing an application to catch OBD sensors' data from my car. I connect it via a RS232 interface. Now. with HyperTerminal I can connect and send/receive data, but I'd like to...
7
by: Tamir.D | last post by:
is there a way to embed the System.IO.Ports.SerialPort object in my html . so that the client can access to a device connected to his SerialCOM ? i tried to wrap the System.IO.Ports.SerialPort in...
0
by: Audio_Developer | last post by:
Hello, I have a problem with the SerialPort Control under VC# Express 2005. In my application I have to read data from an external device through RS 232. The process is built on a software-based...
3
by: Adriano | last post by:
Hello, I'm developing an application in VB.NET 2005 that communicates with a device through RS232, and need to send the following sequence of hexadecimal data to the device: 0xFF, 0x01, 0xC3,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.