Shop OBEX P1 Docs P2 Docs Learn Events
Recieving typed string from PC — Parallax Forums

Recieving typed string from PC

BasilBasil Posts: 380
edited 2008-08-12 23:10 in Propeller 1
Hi All, [noparse]:)[/noparse]

I have an application where the user needs to typed command an a PC needs to be sent to the prop and acted upon.

I am using simple_serial as I don't need full duplex.

I have it working no problems when using single letter commands, but how do I get the prop to wait until the user presses return ($0D) before acting on the command.

In other words, the command is a string not a single character.

Thanks for the assistance!

Alec

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec

My our page

Comments

  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-08-12 22:00
    The $ is the parallax way of defining hex. $D is the same as 13. The windows expanded calculator is very handy for this sort of thing. All you have to do is do a

    repeat until serial.rx==13
    dowhateveryouwant
  • BasilBasil Posts: 380
    edited 2008-08-12 22:05
    Hello [noparse]:)[/noparse]

    Yeah, I know the $ = hex thing.

    Here is some psuedo code of what I want to do. It doesn't quite work in practice :P

    repeat until user_chr == $0D
    user_chr = serial.rx
    user_str = user_str + user_chr

    Thanks for the help [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-08-12 22:35
    $orry you already knew. Perhaps the thing to do is shift left and add each character to a long, then compare the long and look for $d in the lower byte?
  • BasilBasil Posts: 380
    edited 2008-08-12 22:38
    Theres an option [noparse]:)[/noparse]

    I will try that out, thanks!

    Any other suggestions are helpfull

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
  • parts-man73parts-man73 Posts: 830
    edited 2008-08-12 22:59
    I just stumbled upon an object written by Martin Hebel - Extended_FDSerial

    RXStr - "Accepts a string of characters - up to 15 - to be passed by reference
    String acceptance terminates with a carriage return.
    Will accept up to 15 characters before passing back."

    seems perfect for your needs

    http://forums.parallax.com/showthread.php?p=624624

    It also will convert ascii strings of numbers and convert them to a value, both Decimal and Hex.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Brian

    uController.com - home of SpinStudio - the modular Development system for the Propeller

    PropNIC - Add ethernet ability to your Propeller! PropJoy - Plug in a joystick and play some games!

    SD card Adapter - mass storage for the masses Audio/Video adapter add composite video and sound to your Proto Board
  • BasilBasil Posts: 380
    edited 2008-08-12 23:00
    Ooo nice [noparse]:)[/noparse] Thanks perfect thanks!

    Seems I didn't search hard enough!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
  • tpw_mantpw_man Posts: 276
    edited 2008-08-12 23:03
    What I use is this handy loop. It assumes echo is not turned on on the serial terminal. Also handles delete. Delete the 'if in == 8' if to disable that. Might have a couple bugs as I copied it from memory.

    repeat i from 0 to <max number of chars - 1>
      in := ser.rx
      if in == 13
        input_str[i] := 0
        ser.tx(in)
        quit
      if in == 8
        i--
        ser.tx(in)
        input_str[noparse][[/noparse]i--] := 0
        next
      input_str[i] := in
      ser.tx(in)
    
    [/i][/i]
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I am 1011, so be surprised!


    Advertisement sponsored by dfletch:
    Come and join us on the Propeller IRC channel for fast and easy help!
    Channel: #propeller
    Server: irc.freenode.net or freenode.net
    If you don't want to bother installing an IRC client, use Mibbit. www.mibbit.com
    tongue.gif
  • BasilBasil Posts: 380
    edited 2008-08-12 23:10
    Nice and short, thats probably more like what im looking for.

    The previously linked solution uses fullduplexserial which resets the prop when USS is not connected so it would probably cause problems.

    Thanks for that [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
Sign In or Register to comment.