Menu

HserReceive

Help
2016-12-18
2016-12-24
  • Fábio Almeida

    Fábio Almeida - 2016-12-18

    Hello,
    I have a problem with HserReceive

    Example:

    HserReceive Value

    If value = "1" then Set LED on
    if value = "0" then Set LED off

    This code works well with numbers from 0 to 9

    Numbers greater than 10 already have a problem.

    Detail:
    The LED lights up with values from 10 to 19 and from 100 to 199, that is, the HserReceive only reads the first digit

    The same happens with letters, the HserReceive only reads the first letter

     
  • William Roth

    William Roth - 2016-12-18

    Need more info.

    1. GCB Version
    2. What Chip you are using.
    3. Complete source Code

    Perhaps tell us what device is sending the data. An RF module? Something else?
    If it is another chip using Great Cow Basic then please post that code as well.

    Is the sending device actaully sending a "1" (ASCII 49) or is it sending a byte value of 1 ?

    I suspect the sending device is sending ASCII strings. For example, sending a value of 149. it actually sends three bytes. (49, 52, 57). Or if sending a vale of 33, it would send ( 51,51).

    HserReceive only receives 1 byte.

     
  • mmotte

    mmotte - 2016-12-18

    Yes, I agree with William, You are sending an ascii char and comparing it to an ascii char "1". So when you send a "10" it actually sends a "1" and a"0", two chars.

    An alternative is to use the command "HSerGetNum myNum". It will put input a number from the sending device in the range of 0 to 65535 (word size). The command checks that only numbers are input disregarding other characters while waiting for the ending <cr>.
    So you would send "1", <cr> which is like 1 and "enter key"
    OR "1", "0", <cr>....... 10 enterkey
    OR "1", "4","9",<cr>....... 149 enterkey</cr></cr></cr></cr>

    See the help files under the "cow with a question mark on" in the tool bar.
    command references>serial communication>RS232(hardware)

    Good Luck
    Mike

     
  • Fábio Almeida

    Fábio Almeida - 2016-12-24

    William and Mmotte,

    I using atmega328p

    not send in ASCII.
    Ex:
    Send 49
    Receiver 4
    Receiver 9

    I using corrent version of GCB.

     
  • Peter

    Peter - 2016-12-24

    HserReceive ten
    HserReceive one
    Value = ten * 10 + one

    Will that work?

     

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.