VB program to retrieve and transmit code

W

Thread Starter

Willie Greer

I was working on this program in VB 2008, that is suppose to retrieve this 8-bit code from a transmitter and then convert it to text to display it on the screen that I have created. I have fixed all errors but still I get no readout?? Any help or suggestions
<pre>
Imports System.IO.Ports
Imports System.Threading.Thread
Imports System

Public Class Form1

Public Delegate Sub StringSubPointer(ByVal Buffer As String)
Dim WithEvents COMPort As New SerialPort

Private Sub Receiver(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles COMPort.DataReceived
Me.BeginInvoke(New StringSubPointer(AddressOf Display), COMPort.ReadLine)
End Sub
Private Sub Display(ByVal Buffer As String)
txtReceived.AppendText(Buffer)

' Initialization somewhere in the program where you open the port.

COMPort.PortName = "COM1"
COMPort.BaudRate = 19200
COMPort.DataBits = 8
COMPort.Parity = Parity.None
COMPort.StopBits = StopBits.One
COMPort.ReadTimeout = 2000

' COMPort.NewLine = Chr(xx) in case the telegram is not terminated with Line Feed.

Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub MyFormClosing(ByVal sender As Object, ByVal e As ComponentModel.CancelEventArgs) Handles MyBase.Closing
If MessageBox.Show("Do you really want to close the window", "", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No Then

e.Cancel = True

Else

If COMPort.IsOpen Then COMPort.Close()
End If
End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtReceived.Clear()
txtTransmitter.Clear()
End Sub
End Class
</pre>
 
I don't understand why did you choose not to put the serial port control in the form and only to invoke a delegate to update the text when the data is received, but I don't see where do You open the port.
 
Top