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

            Catch ex As Exception

            End Try
        End With


    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)))

    '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


    End Sub

    Private Sub UpdateTextbox() 'WORKING

        TextBox1.Text = recievedData   'HexString("ABC")

    End Sub

End Class

Thanks in advance

6 Years
Discussion Span
Last Post by ÜnLoCo

try this one and see if it fits

Function StrToHex(ByVal str As String) As String
        Dim hexStr = ""
        For Each letter In str
            hexStr &= Hex(Asc(letter)) + " "
        Return hexStr
    End Function

output example:
StrToHex("a1X") = "61 31 58"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.