
' ============================================================
'  This example receives the file line by line
'  It works also with short buffers
' ============================================================

FileName = "FileReceived.csv"
COM Open 13 115200
Gosub ReceiveFileFromCOM
Stop

Label ReceiveFileFromCOM
	Variable String FileName
	Variable String Str1
	'
	COM DiscardInBuffer
	'
	Str1 = ""
	For v1 = 1 To 9e99
		s1 = COM_Received
		If s1 <> ""
			s1 = Replace(s1, "{{{CRLF}}}", CRLF)
			Str1 = Str1 + s1
			If s1 = "{{{FileEndMarker}}}"
				Str1 = Replace(Str1, "{{{FileEndMarker}}}", "")
				Save DeleteFile FileName
				Save StringToFile Str1 FileName
				Exit
			EndIf
		EndIf
		Wait Seconds 0.01
	Next
Return


'WATCH s1
