This is my subroutine to read entire string from hardware usart
'Read entire string (<=40 characters long) from usart
Sub GetUsartString ( out Buffer, Optional BufferLength=40)
Temp=0
Buffer=""
BufferSize=0
Do Until Temp=13 or BufferSize=BufferLength
'Get a byte from the terminal
HSerReceive Temp
SerData=0
If Temp >= 32 Then ' Character must be printable
BufferSize = BufferSize + 1
Buffer(0)=BufferSize
Buffer(BufferSize) = Temp
End If
Loop
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The variable BufferLength is Optional. That meens the user can define the length (max 40 characters) of string to be receive. The subroutine waits until string length reach the BufferLength value.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is my subroutine to read entire string from hardware usart
'Read entire string (<=40 characters long) from usart
Sub GetUsartString ( out Buffer, Optional BufferLength=40)
Temp=0
Buffer=""
BufferSize=0
Do Until Temp=13 or BufferSize=BufferLength
'Get a byte from the terminal
HSerReceive Temp
SerData=0
If Temp >= 32 Then ' Character must be printable
BufferSize = BufferSize + 1
Buffer(0)=BufferSize
Buffer(BufferSize) = Temp
End If
Loop
end sub
Should you add timeout code?
What if you did not get the return (13) or the 40 characters? The program will hang there.
The variable BufferLength is Optional. That meens the user can define the length (max 40 characters) of string to be receive. The subroutine waits until string length reach the BufferLength value.