Menu

Read entire string from usart

Help
2012-01-12
2013-05-30
  • Nobody/Anonymous

    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

     
  • Nobody/Anonymous

    Should you add timeout code? 

    What if you did not get the return (13) or the 40 characters?  The program will hang there.

     
  • Dimitris Katsaounis

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.