While ("True")
If (newData <> "") Then
tbData = Text.Append("Data received : "+newData+nl,Controls.GetTextBoxText(tb))
Controls.SetTextBoxText(tb,tbData)
newData = ""
EndIf
Program.Delay(10)
EndWhile
Sub OnDataReceived
dataIn = Text.Append(dataIn,LDCommPort.RXAll())
If (Text.IsSubText(dataIn,nl)) Then
newData = LDText.Trim(dataIn)
dataIn = ""
EndIf
EndSub
Sub OnButtonClicked
button = Controls.LastClickedButton
If (button = clear) Then
tbData = ""
ElseIf (button = send) Then
val = Controls.GetTextBoxText(value)
If (val = Math.Round(val)) Then
tbData = Text.Append("*** "+val+" sent as integer ***"+nl,Controls.GetTextBoxText(tb))
val = "i"+val
ElseIf (val+0 = val) Then
tbData = Text.Append("*** "+val+" sent as float ***"+nl,Controls.GetTextBoxText(tb))
val = "f"+val
ElseIf (val <> "") Then
tbData = Text.Append("*** "+val+" sent as string ***"+nl,Controls.GetTextBoxText(tb))
val = "s"+val
Else
tbData = Text.Append("*** Nothing sent ***"+nl,Controls.GetTextBoxText(tb))
EndIf
If (val <> "") Then
LDCommPort.TXString(val)
EndIf
Else
For i = 1 To nButton
If (button = buttons[i]) Then
tbData = Text.Append("*** Action "+i+" instruction sent ***"+nl,Controls.GetTextBoxText(tb))
LDCommPort.TXString(i)
EndIf
EndFor
EndIf
Controls.SetTextBoxText(tb,tbData)
EndSub