' ----------------------------------------13 Feb 2025-
' LoopBack test program for hardware verification
' ----------------------------------------------------
' Valid ONLY for USB to RS232 9 or 25 pin adapter
' Installa jumper to generate a short circuit between
' pin 2 and pin 3.
' ----------------------------------------------------

Option Speed 9
Controls OpenTextBox
Controls ClearTextBox
String Port  = 17
Numeric Bauds = 921600
COM Open Port Bauds
COM DiscardInBuffer
s1 = COM_Status
s1 = "Port status: "  + Port + " IS " + s1 + " at " + Bauds + CRLF
s1 = s1 + "Valid ports: " + COM_PortNames + CRLF + CRLF
Print s1

Button 1 Label "SendToSerial"

ReceiveLoop

Label SendToSerial
	For v1 = 20 To 255
		s1 = Chr(v1)
		'Print Asc(s1) + " "
		COM WriteString s1
	Next
	COM WriteString CRLF
Return

ReceiveLoop

Label ReceiveLoop
	ReceiveFromSerial
	Wait Seconds 0.01
Goto ReceiveLoop

Label ReceiveFromSerial
	String Terminator = Chr(13)+Chr(10)
	String ReceivedLine
	String HexLine
	ReceivedLine = COM_ReceiveUntil(Terminator)
	If ReceivedLine <> ""
		HexLine = ""
		For v1 = 1 To Len(ReceivedLine)
			HexLine = HexLine + Right("0" + Hex(Asc(Mid(ReceivedLine, v1))), 2) + " "
		Next
		Controls ClearTextBox
		Print HexLine + CRLF
	EndIf
Return


'BOOKMARKS 

'EDITEDLINES 2 8 0 8 7 1 1 3 5 7 6 8 11 9 27 10 

'WATCH dummy
'WATCH dummy
