Can Somebody please help a newbie ?
I`ve searched high and low for an answer, but just can`t seem to get it working !
I`m trying to write a programme ,in VB2008 Express, to receive Serial Port Ascii data ( from a Multimeter) and display it as Hex Data in a textbox.
I can get the Ascii data to show, but just cannot convert it into Hex.
Once I can do this I want to write a new front end for the Mulimeter software.
This is what i`ve written so far :
Imports System
Imports System.IO.Ports
Imports System.Text
Namespace WindowsApplication1
End Namespace
Public Class Form1
Private WithEvents serialPort As New IO.Ports.SerialPort
Private recievedData As String
Public Delegate Sub UpdateRecievedData()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With serialPort
.PortName = "COM1"
.BaudRate = 2400
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
'.Encoding = System.Text.Encoding.ASCII
.ReadTimeout = 2000
Try
Catch ex As Exception
MsgBox(ex.Message)
End Try
End With
serialPort.Open()
End Sub
Private Sub serialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serialPort.DataReceived
recievedData += serialPort.ReadExisting
Me.Invoke(New UpdateRecievedData(AddressOf UpdateTextbox)) 'WORKING
End Sub
'Private Function HexString(ByVal EvalString As String) As String
'Dim intStrLen As Integer
'Dim intLoop As Integer
'Dim strHex As String
' EvalString = Trim(EvalString)
' intStrLen = Len(EvalString)
'For intLoop = 1 To intStrLen
' strHex = strHex & " " & Hex(Asc(Mid(EvalString, intLoop, 1)))
'Next
'HexString = strHex
'Dim strOut As String
' strOut = HexString("ABC")
'End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
serialPort.Close()
End Sub
Private Sub UpdateTextbox() 'WORKING
TextBox1.Text = recievedData 'HexString("ABC")
End Sub
End Class
Thanks in advance