Had some help from an other VB forum to get things done.
The VB code is below.
Now need to work on the code to send the data back to the UNO if it is changed in the PC control panel.
So the display on the UNO displays the same data as the PC control panel and vice versa.
Private Sub MSComm1_OnComm()
Static strBuffer As String
Static boSync As Boolean
Dim strData As String
Dim strRec As String
Dim intPos As Integer
Dim boComplete As Boolean
With MSComm1
Select Case .CommEvent
Case comEvReceive
strData = .Input
strBuffer = strBuffer & strData
Do
intPos = InStr(strBuffer, vbCrLf)
If intPos > 0 Then
strRec = Mid$(strBuffer, 1, intPos - 1)
'
' Have we synchronised yet ?
'
If Not boSync Then
'
' Ignore everything until a "A" record is received
' Once it has been, then set the synchronised flag
' and start processing
'
If Mid$(strRec, 1, 1) = "A" Then
boSync = True
Call ProcessRecord(strRec)
End If
Else
'
' We are synchronised so process the data received
'
Call ProcessRecord(strRec)
Label12.Caption = "Syncronized"
Label12.ForeColor = vbBlack
End If
If Len(strBuffer) > intPos + 1 Then
strBuffer = Mid(strBuffer, intPos + 2)
Else
strBuffer = ""
boComplete = True
End If
Else
boComplete = True
End If
Loop Until boComplete = True
End Select
End With
End Sub
Private Sub ProcessRecord(strRec As String)
'
' StrRec is expected to be:
' Single Alphabetic character between A and K (inclusive, excluding I)
' followed by a comma
' followed by a number between 0 and 255 (inclusive)
' eg
' A,120
'
Dim strParts() As String
Dim strValue As String
Dim intI As Integer
Dim boError As Boolean
intI = 1
'
' Ignore null records
'
If strRec <> vbNullString Then
strParts = Split(strRec, ",")
'
' Check that there's two values
'
If UBound(strParts) = 1 Then
'
' Check that the second value is numeric
'
Do
If Mid$(strParts(1), intI, 1) < "0" Or Mid$(strParts(1), intI, 1) > "9" Then
boError = True
Else
intI = intI + 1
End If
Loop Until boError Or intI > Len(strParts(1))
If Not boError Then
'
' Second value is numeric check it's in the correct range
'
If CInt(strParts(1)) >= 0 And CInt(strParts(1)) <= 1024 Then
strValue = strParts(1)
'
' Set the appropriate TextBox to the value sent
'
Select Case strParts(0)
Case "A"
TextSensorValue.Text = strValue
Case "B"
TextStartSpeedValue.Text = strValue
Case "C"
TextSpeedCurveValue.Text = strValue
Case "D"
TextBrakeValue.Text = strValue
Case "E"
TextBrakeCurveValue.Text = strValue
Case "F"
TextSensorMinValue.Text = strValue
Case "G"
TextSensorMaxValue.Text = strValue
Case "H"
TextModelNumberValue.Text = strValue
Case "J"
TextSpeedValue.Text = strValue
Case "K"
TextDeathBandValue.Text = strValue
Case Else
'
' Unrecognised Letter
'
Debug.Print "Invalid Code Received: " & strRec, , "Process Record"
End Select
Else
'
' Value is out of range
'
Debug.Print "Value Received is out of range: " & strRec, , "Process Record"
End If
Else
'
' Value is non-numeric
'
Debug.Print "Non-Numeric Value Received: " & strRec, , "Process Record"
End If
Else
'
' Less than or more than two items in the data
'
'MsgBox "Invalid Record Format: " & strRec, , "Process Record"
Debug.Print "Invalid Record Format: " & strRec, , "Process Record"
End If
End If
'send the data to a progressbar
ARProgressBar1.Value = TextSpeedValue.Text
ARProgressBar2.Value = TextStartSpeedValue.Text
ARProgressBar3.Value = TextSpeedCurveValue.Text
ARProgressBar4.Value = TextBrakeValue.Text
ARProgressBar5.Value = TextBrakeCurveValue.Text
ARProgressBar6.Value = TextSensorValue.Text
End Sub