Here is my code:
Imports System
Imports System.IO.Ports
Public Class Form1
Public Delegate Sub myDelegate()
Dim WithEvents port As SerialPort = New System.IO.Ports.SerialPort("COM5", 9600, Parity.Even, 8, StopBits.One)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CheckForIllegalCrossThreadCalls = False
If port.IsOpen = False Then
Try
port.Open()
'MessageBox.Show("Open")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub
Public Sub updateTextBox()
Dim strarr(8) As String
Dim str1 As String
str1 = port.ReadLine
txtreceive.AppendText(str1)
strarr = str1.Split(",")
Dim x1 As Double
x1 = Val(strarr(0))
MsgBox(x1)
txtreceive.ScrollToCaret()
End Sub
Private Sub port_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles port.DataReceived
txtreceive.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {})
End Sub

New Topic/Question
Reply




MultiQuote








|