Converting HSERIN Data to Number


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Converting HSERIN Data to Number

    Hi,
    The UART RX interrupt always* fires for each byte that comes into the RX buffer, there's no way to set a "threshold" on when the interrupt fires. After all, the buffer is only two bytes deep. But yes, you could set your code up so that after proper sync, adress, command etc you grab one byte and that's it.

    * Well not always but that's details details details.....

    /Henrik.

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Converting HSERIN Data to Number

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    The UART RX interrupt always* fires for each byte that comes into the RX buffer, there's no way to set a "threshold" on when the interrupt fires. After all, the buffer is only two bytes deep. But yes, you could set your code up so that after proper sync, adress, command etc you grab one byte and that's it.

    * Well not always but that's details details details.....

    /Henrik.
    Thanks again, Henrik. Much appreciated. I'm going to try all this out tonight.

  3. #3
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Converting HSERIN Data to Number

    Code:
    serialbuffer byte [4]
    serialbyte var byte
    index var byte
    
    …
    
    ‘ ooh looky here… a serial byte arrived
    for index = 1 to 3
    serialbuffer[index] = serialbuffer[index-1]
    next index
    serialbuffer[0] = serialbyte
    Now instead of checking for the first byte in the serial string,
    check for what you call the termination byte.
    I don’t know what that is, so now it’s $FE.

    Code:
    if serialbuffer[0] = $FE then
    ‘ we know the bytes serialbuffer [0,1,2,3] are the desired 4 byte string in reverse
    ‘ unless only a partial command was received
    if serialbuffer[3] = “S” then
    ‘ we know now that the entire four byte command was received if there was no serial error
    endif
    endif

  4. #4
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Converting HSERIN Data to Number

    Now if you only wanted to grab say byte 2 (beginning counting from zero).

    Code:
    counter var byte
    counter = 0
    
    'oh looky here.. a serial byte arrived
    
    if serialbyte = “S” then
    counter = 0
    else
    counter = counter + 1
    endif
    
    if counter = 2 then
    byteyoucareabout = serialbyte
    endif
    A lot of this will fall apart if another byte of the command can be the same value as the “S” or the termination character,
    which is why it’s better to go something close to the first way, and check both start and end chars if they are always the same.
    Last edited by Art; - 18th November 2015 at 05:29.

Similar Threads

  1. Replies: 3
    Last Post: - 22nd June 2015, 16:15
  2. read bytes number in Hserin
    By Rony in forum Serial
    Replies: 13
    Last Post: - 13th August 2010, 10:32
  3. Unable to use the number 8 in DATA statement
    By dbachman in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 7th December 2008, 06:34
  4. Problem converting data to what I need
    By oldcarguy85 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd November 2007, 22:43
  5. Need help converting NMEA data
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 21st August 2004, 08:28

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts