Shop OBEX P1 Docs P2 Docs Learn Events
Confimation on sending strings — Parallax Forums

Confimation on sending strings

John BoardJohn Board Posts: 371
edited 2012-08-17 23:28 in Propeller 1
G'day,

I'm in a bit of a hurry getting a robot ready for some comps, I would just like a quick confirmation that this is how you send a string from one prop to another using the FullDuplexSerialPlus (or extended FullDuplexSerial) object:

Sender:
CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

OBJ

  Serial: "FullDuplexSerialPlus"

PUB Main

  Serial.Start(rx, tx, 0, 115200)

  Serial.Str(String("This is a test"))
  Serial.tx(13)

  repeat


Receiver:
CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

OBJ

  Serial: "FullDuplexSerialPlus"

VAR

  long recv

PUB Main

  Serial.Start(rx, tx, 0, 115200)

  Serial.RxStr(@recv)
  
  'Do whatever with the string now

  repeat


I have tried this code on my platform, not appearing to work, I would appreciate if anyone could confirm that this is right,

John

[EDIT] I know that the 2-way props communication is secure as I have been able to send dec values easily.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-08-16 21:02
    I believe the method is called GetStr. Look at the source code comments in FullDuplexSerialPlus for specifics. This stores a carriage return terminated string in the buffer whose address is passed to it. A zero byte is substituted for the carriage return in the buffer. You've allowed only a 4 byte long as the buffer. You'll need more space than that. Your transmitted string takes at least 15 bytes.
  • msrobotsmsrobots Posts: 3,709
    edited 2012-08-16 21:10
    Well,

    a long (recv) to receive a string is a little short.

    try a byte-array aka

    VAR
    byre recv[42]

    so you have more space

    Enjoy!

    Mike
  • John BoardJohn Board Posts: 371
    edited 2012-08-16 21:11
    So, apart from the function's name (which is correct, RxStr), I am to have:
    VAR
      
      long recv[5]
    
    

    (Or however much, not necisarily 5)

    ?

    Thanks for the response!

    -John
  • msrobotsmsrobots Posts: 3,709
    edited 2012-08-16 21:16
    yes,

    you need a buffer to store the transmitted string.

    on the sending side the String()-Function in Spin is doing this behind your back.

    Enjoy!

    Mike
  • John BoardJohn Board Posts: 371
    edited 2012-08-16 21:17
    Thanks, sorry, I posted my last post before I saw yours!

    Anyway, thanks again :)
  • John BoardJohn Board Posts: 371
    edited 2012-08-17 22:44
    G'day

    Tried a few things, no prevail, I've attached master and slave code, the Master code is really in SlaveInterface.spin, you should see the Serial setup code and sending of the string at the top, and the code for the slave is in Slave.Spin

    When I have the Recv var set to "long" (even if I have an array) it shows nothing on the LCD. If I have a byte array, it shows stuff, but it's purely random gibberish. Any help would be appreeciated. I am using the Parallax 4x20 backlit LCD, you can find the code in LCD.spin which is in the slave's archive.

    Sorry for the lack of information, I'm on a tight schedule.

    -John
  • kuronekokuroneko Posts: 3,623
    edited 2012-08-17 23:03
    The str method usually takes an address (of a string). So your loop should look something like this:
    repeat
        LCD.clearScreen       ' [COLOR="#FF0000"]this should probably come after the RxStr call[/COLOR]
    
        Serial.RxStr(@recv)
        LCD.Str([COLOR="#FF0000"]@[/COLOR]recv)   
    
    And you really only need a byte array of 16 which is the longest string returned by RxStr (including terminator).

    Also, in the SlaveInterface start method you use a local variable temp which is evaluated (once) while uninitialised.
  • John BoardJohn Board Posts: 371
    edited 2012-08-17 23:07
    Thanks, I'll look into these.
  • John BoardJohn Board Posts: 371
    edited 2012-08-17 23:21
    kuroneko wrote: »
    Also, in the SlaveInterface start method you use a local variable temp which is evaluated (once) while uninitialised.

    I think your refering to:
    repeat until temp == 1
        temp := Serial.RxDec
    

    But I'm not sure if I understand. Although I haven't previously defined temp, it should start as "0", which is what I want. Then it continually recieves decs off the serial until it is "1", or the "Init Bit". Am I doing something wrong?

    Thanks again,

    Ohh, I also got it working! Would I be able to treat "@recv" like a variable string now? So, would I be able to do: strcomp(@recv, String("Test."))?

    Thanks,

    John
  • kuronekokuroneko Posts: 3,623
    edited 2012-08-17 23:28
    John Board wrote: »
    But I'm not sure if I understand. Although I haven't previously defined temp, it should start as "0", which is what I want. Then it continually recieves decs off the serial until it is "1", or the "Init Bit". Am I doing something wrong?
    Only result is preset to 0, all other local variables are undefined.
    John Board wrote: »
    Would I be able to treat "@recv" like a variable string now? So, would I be able to do: strcomp(@recv, String("Test."))?
    Sure. Note that when you use e.g. string("fred") more than once it would be better to put it in a DAT section and refer to it from there. Otherwise each usage of string("fred") will store/allocate a new copy of the string.
Sign In or Register to comment.