Decimal variable input with HSERIN command


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1

    Question Decimal variable input with HSERIN command

    Hello,

    I would like to do a simple thing with the HSERIN command :

    I send from my computer the ASCII chain "A1234". What I want it's to store the number (1234) in a variable (for instance, "vartest").
    Also, if I send from my computer the ASCII chain "B0005", I want to store the number (5) into an another variable (let's say "vartest2").

    I think it's quite simple, but I don't know how to handle that within a loop.

    Thanks
    Last edited by pxidr84; - 18th April 2013 at 18:06.

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


    Did you find this post helpful? Yes | No

    Default Re: Decimal variable input with HSERIN command

    Hello,

    Perhaps something like this
    Code:
    CMD VAR BYTE
    TestVar1 VAR BYTE
    TestVar2 VAR BYTE
    
    HSERIN [CMD]
    
    Select Case CMD
      Case "A"
        HSERIN[DEC4 TestVar1]
      Case "B"
        HSERIN[DEC4 TestVar2]
    END SELECT
    /Henrik.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Decimal variable input with HSERIN command

    Thanks a lot Henrik, it works fine.

    The only problem I got is that HSERIN hangs my loop...

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


    Did you find this post helpful? Yes | No

    Default Re: Decimal variable input with HSERIN command

    Yes, that's the way it works....
    If the loop time is less that 2 "byte-times" you can poll the receive flag each time thru the loop and get the byte(s) from the receive buffer. If the loop time is longer you need to use interrupts.

    /Henrik.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Decimal variable input with HSERIN command

    Quote Originally Posted by HenrikOlsson View Post
    Yes, that's the way it works....
    If the loop time is less that 2 "byte-times" you can poll the receive flag each time thru the loop and get the byte(s) from the receive buffer. If the loop time is longer you need to use interrupts.

    /Henrik.
    Hmm right now I just want to retreive a 4-number decimal value in my loop, and put it in the "ref" variable. I don't even need a letter, I just send raw numbers (in ASCII) , like "0586" from my computer.
    The problem is that in my program I use very precise and quick timing interrupts so it's a bit annoying.
    Maybe there is a way to send not an ASCII number but directly a hex number, so 0586 will be 24A... max value is 1200 (4B0, so I use 2 bytes)

    I have no idea how to use the RX buffer...
    Last edited by pxidr84; - 21st April 2013 at 21:43.

  6. #6
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Decimal variable input with HSERIN command

    You can add timeout label. Then it won't hang forever..
    HSERIN 10,TimeOut, [CMD]

    Code:
    Select Case CMD
      Case "A"
        HSERIN  10,TimeOut,[DEC4 TestVar1]
      Case "B"
        HSERIN 10,TimeOut,[DEC4 TestVar2]
    END SELECT
    TimeOut:

Similar Threads

  1. Recieve decimal with HSERIN
    By mel4853 in forum Serial
    Replies: 2
    Last Post: - 12th February 2012, 03:43
  2. HSERIN for variable length string
    By Pic2008 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 19th February 2010, 05:58
  3. variable + decimal
    By savnik in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 18th August 2009, 14:21
  4. Midi input, using hserin?
    By TonyA in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 26th June 2007, 12:18
  5. Convert a word variable to decimal
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th December 2004, 20:02

Members who have read this thread : 0

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