Shop OBEX P1 Docs P2 Docs Learn Events
Serial Communication - Receiving a String — Parallax Forums

Serial Communication - Receiving a String

SnyggisSnyggis Posts: 14
edited 2009-11-29 20:46 in Propeller 1
This seems like a basic question, but I cannot find information in the documentation about how to receive a string through fullduplexserial. Anyone know how this is done, I was thinking of using Debug.getstr. I am also trying to read in decimal values, when using Debug.getdec - when I try to type in 9.8 on the terminal the propeller reads in 98. Thanks for the help, though I know rather basic.

Comments

  • DonEduardoDonEduardo Posts: 54
    edited 2009-11-28 23:19
    I can't find it on the computer I'm working at but I think you want to use fullduplexserialPLUS. Can't remember where I downloaded it. Did a quick search in the object
    exchange and it wasn't there, although there was another one called Extended Serial.

    I'll have a look on my laptop later if no one else responds.
  • SnyggisSnyggis Posts: 14
    edited 2009-11-28 23:27
    Thanks, seems like I have heard of it before.. I have been looking and cant seem to find it.
  • DonEduardoDonEduardo Posts: 54
    edited 2009-11-28 23:27
    Okay, found it in the Propeller Education Kit Examples. I think I downloaded that package separately a long time ago but looks like it is part of the newest Propeller Tool Download. Hope that helps.
  • SnyggisSnyggis Posts: 14
    edited 2009-11-28 23:56
    Thanks, another question on how to use it. The documentation for the fullduplex serial plus says the following:

    The PUB getstr(stringptr)
    Gets zero terminated string and stores it, starting at the stringptr memory address

    How do I determine where the stringptr memory address should be? As I am reading this new string in, should I look at my available memory in the Stack/Free and just address it to an opened spot?
  • DonEduardoDonEduardo Posts: 54
    edited 2009-11-29 00:15
    I think I just declared a byte array in my main program.

    Something like

    byte mystrptr[noparse][[/noparse]80]
  • SnyggisSnyggis Posts: 14
    edited 2009-11-29 00:52
    I appreciate the help, but I am still struggling to get this to work. I am trying to loop an if statement, so that if "CPU10" is typed in, to will make the statement true and continue through the logic. Any suggestions would be great.

    repeat
    Debug.getstr(400)
    if String(400) == "CPU10"
    Debug.Str(String("CPU","10 ","Ready", 13))
    Motor := Debug.getDec
    if Motor == 1
  • DonEduardoDonEduardo Posts: 54
    edited 2009-11-29 01:28
    Naw, that's not gonna work.

    First declare in the VAR section a byte array as I said above.

    Then, you pass the address of that variable to getstr . Ex: getstr(@mystrptr)

    then do a string compare; Ex: strcomp(@mystrptr,string("CPU10") ) Can't remember if strcomp is standard or requires a string object of some kind.

    I'm not at my development computer so I'm just going from memory, but the above will get you closer than you already are.
  • DonEduardoDonEduardo Posts: 54
    edited 2009-11-29 03:04
    Here's something to get you started:

    VAR
    byte mystrptr[noparse][[/noparse]80]   
       
    PUB TestMessages
       waitcnt(clkfreq *5 + cnt)
      ''Send test messages to Parallax Serial Terminal.
     
      Debug.start(31, 30, 0, 57600)
    
      repeat
        Debug.str(string("Please enter hello!", 13))
        waitcnt(clkfreq + cnt)
        debug.getstr(@mystrptr)
        if strcomp(@mystrptr,string("hello")) == true
            debug.str(string("got it"))
    
    
  • SnyggisSnyggis Posts: 14
    edited 2009-11-29 04:20
    Yep.. that did it.. Thanks so much, now I am able to control 48 stepper motors using Matlab.. Thanks, now my Saturday wasnt a complete waste!
  • edited 2009-11-29 20:46
    Snyggis and others,

    For future reference, there's a how-to for getting started with the FullDuplexSerialPlus object in the textbook that comes with the Propeller Education Kit (Propeller Education Kit Labs: Fundamentals).··A .pdf of this book is included in·the Propeller Tool software's Help menu (v1.2.6 and newer), just click Help and select Propeller Education Kit.· Instructions and examples for using FullDuplexSerialPlus start in the Propeller Chip - PC Terminal Communication section starting on page 95 in the v1.1 textbook.· There's also a quick start example at forums.parallax.com· -> Propeller Chip·-> Propeller Education Kit Labs, Tools, and Applications·->·Propeller·<-> PC Terminal Communication.

    On the next revision of the textbook, we'll be switching from FullDuplexSerialPlus to the Parallax Serial Terminal object.· I use it a lot.· In fact, when I start developing code, I just about always begin with a stripped down version of Parallax Serial Terminal Quick Start.spin.· It makes it really easy to display variable values at certain points during development.·

    You can find the Parallax Serial Terminal Quick Start·object in the Propeller Tool software using File -> Open From -> Propeller Library - Demos.· There's also an object in the same folder named Parallax Serial Terminal Demo that shows how to use more of the Parallax Serial Terminal object's features.

    Andy

    P.S. @Snyggis, here's a link to a paper that might have some useful information.· It uses MATLAB and the Propeller control a robotic arm with a Wii Nunchuck.· .spin and .m code examples are in the appendices.

    http://www.aaronklapheck.com/Downloads/MiniMover5/Final_Report_MiniMover5.pdf·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 11/29/2009 8:57:13 PM GMT
Sign In or Register to comment.