Shop OBEX P1 Docs P2 Docs Learn Events
spin question - pulling substrings out of a string — Parallax Forums

spin question - pulling substrings out of a string

russ christensenruss christensen Posts: 84
edited 2009-03-02 03:42 in Propeller 1
Hi guys, i'm sending commands from my vb program to the robot, and so far everythig is working great. but i'm trying to kill two birds with one stone. when i click on a particular button, i want to send the value of a control in this form "spd" + (bar.value*2).tostring This works great, but i need a way in the spin to recognize the prefix "spd" and pull out what the speed is being set to. Is there a way to do this? Does anybody have any example code? i'm going to assume its as easy as just looking at the correct bytes, but i'm not sure exactly how to do this in spin. Thanks in advance.

Comments

  • jazzedjazzed Posts: 11,803
    edited 2009-03-02 02:38
    There doesn't appear to be a "String" package in the obex. You can create an indexOf method to scan the string array for your "spd" token pretty easily if you know how to deal with spin arrays .... byte[noparse][[/noparse]ptr+n] is a char in a string, ptr+n is a string, ptr := @array or ptr = string("hello world"), etc.... Spin has some string commands that help: BYTEMOVE, STRING, STRSIZE, and STRCOMP. I've always just used single or double char names at the beginning of a command string for passing properties.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve
  • russ christensenruss christensen Posts: 84
    edited 2009-03-02 02:52
    i figured as much. i think i'm just going to send an spd, which will tell it to read the next packet for the speed. may be easier. on a similar note, is there a limit to how many serial drivers you can use? i am using 2 so far, but when i add the momoctrl object it adds a third and my program goes haywire. any advice?
  • jazzedjazzed Posts: 11,803
    edited 2009-03-02 03:05
    Tim Moore made a 4 port fullduplexserial object. http://obex.parallax.com/objects/340/

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve
  • russ christensenruss christensen Posts: 84
    edited 2009-03-02 03:09
    Awesome, i'll have to check it out tomorrow, wifey wants me to help put the kids in bed. See you guys tomorrow!
  • russ christensenruss christensen Posts: 84
    edited 2009-03-02 03:42
    Ok i snuck back to working. It looks like that could be the way to go. I'm afraid i'm going to have to rewrite a bunch of code though. Oh well. i'll look into it more tomorrow.

    Russ
Sign In or Register to comment.