473,287 Members | 1,834 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,287 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 8552

"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,...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.