Public Sub NewData (data() As Byte)
Dim msg As String
msg = BytesToString(data, 0, data.Length, "UTF-8")
msg = msg.Trim
'Sanity check
If msg.Length = 0 Then
Log("Error: Empty message received")
Return
End If
'Dim param As String = msg
Dim paramnum() As String = Regex.Split("\&", msg)
'Let's see what command came in
If paramnum(0) = "Command1" Then
'Let's process our parameters for Command1
For i = 1 To paramnum.Length-1
'Log all non-empty parameters
If paramnum(i) <> "" Then
log(paramnum(i))
End If
'Sleep(0)
Next
'Let's send out for Command2
If connected = True Then
SendData(Bconv.StringToBytes("1"&"Command2~", "UTF-8"))
End If
Else If paramnum(0) = "Command2" Then
'Command2 came in, let's log the single parameter associated with it
'Let's make sure it came in correctly
If paramnum.Length = 2 Then
Log(paramnum(1))
Else
Log("Error: Expected 1 parameter with Command2 but received: " & paramnum.Length - 1 & " commands")
Log("Error (cont.): Message received was: " & msg)
End If
Else
'We neither received Command1 nor Command2, something is up
Log("Error: Neither Command1 nor Command2 was received.")
Log("Error (cont.): Message received was: " & msg)
End If
End Sub