OpenComPort
Stop


Label OpenComPort
	String  DeviceID = "Recognition"
	Numeric Bauds    = 1000000
	String  ComPort
	Numeric ComIndex
	Numeric ComRetry1
	Numeric ComRetry2
	For ComRetry1 = 1 To 10
		For ComIndex = 0 To GetSeparatedStringCount(COM_PortNames) - 1
			ComPort = GetSeparatedString(COM_PortNames, ComIndex)
			COM Open ComPort Bauds
			If COM_Status = "OPENED"
				For ComRetry2 = 1 To 3
					COM DiscardOutBuffer
					COM DiscardInBuffer
					COM WriteString "GetID" + CRLF
					Wait Seconds 0.01
					If COM_ReceiveUntil(CRLF) = DeviceID + CRLF
						ComIndex = -1
						Beep "440-1,0-80,880-1"
						s1 = COM_Status
						s1 = "Port Status: "  + ComPort + " IS " + s1 + " at " + Bauds + CRLF
						s1 = s1 + "Valid ports: " + COM_PortNames + CRLF + CRLF
						Print s1
						Return
					EndIf
				Next
			EndIf
		Next
	Next
	If ComIndex >= 0
		Print "COM PORT NOT FOUND"
		TTS SelectVoice "ENGF"
		TTS Speak "Com port not found."
		TTS Speak "Please test connections and retry."
		Wait Not TTSspeaking
		End
	EndIf
Return





