Shop OBEX P1 Docs P2 Docs Learn Events
Building A String — Parallax Forums

Building A String

LightfootLightfoot Posts: 228
edited 2010-06-28 01:36 in Propeller 1
With spin, how do you build a string with the two variables name and IDNum in the specified locations in the string?


'Pseudocode:

name := string("Gordon Lightfoot")
IDNum := 6453789

SER.str(string("His name is " <name> ". The ID number is " <id>)



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2010-06-27 17:28
    Simply separate:

    SER.str( string("His name is ") )
    SER.str(@name)
    SER.str( string(". The ID number is ") )
    SER.dec( IDNum )

    or

    SER.hex( IDNum, 8 )

    or

    SER.bin( IDNum, 32 )
  • LightfootLightfoot Posts: 228
    edited 2010-06-27 17:36
    Can it be sent as one string?

    What i want to do is send the string and compare it to another string in the receiver method for equality.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • MagIO2MagIO2 Posts: 2,243
    edited 2010-06-27 17:54
    What's the difference? The string-end character ( $00 ) will not be send anyway. If you need an end character you have to add it to the string anyway:
    SER.dec( IDNum )
    SER.tx( $0d )
    would for example a carriage return to the string which can be used as end-character.

    The serial interface is buffering the characters. So, the receiver won't notice that you used several calls instead of one because it's very unlikely that the buffer runs out of character before the next call of a SER.* function in your case.
  • LightfootLightfoot Posts: 228
    edited 2010-06-27 19:09
    I am sending a string from a transmitter to a receiver . The string contains a network ID and a Receiver ID. The string is in this format:

    N_E_T_I_D_<network ID>_A_N_I_I_D_<Receiver ID>

    Transmit Code:

    
    'networkID is a constant equal to 1.
    
    moduleID := 12
    
    XB.str(string("N_E_T_I_D_", networkID)) 'Transmit module access string.
    XB.str(string("_A_N_I_I_D_")) 
    XB.dec(moduleID)
    XB.tx($0d)
    
    



    Receive Code:

    animatorIDString := string("N_E_T_I_D_1_A_N_I_I_D_12")
    
    repeat while buffer <> animatorIDString 'When the strings match, the loop should break.
       SER.RXStr(@buffer)
    
    



    When the input string (read in the variable buffer) matched the animatorIDString, the loop should break. It does not. The problem is probably simple, but I have never dealt with sending strings serially over XBEE. The receiver uses the extended full duplex serial for receiving the string. What is up here?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-06-27 22:13
    animatorIDString is the address of the first byte of the string.· buffer is the first element of the buffer array, which would be "N" if the string in buffer starts with the same character as animatorIDString.· What you really want is the following line

    repeat while NOT strcomp(animatorIDString, @buffer)
    


    Dave
  • LightfootLightfoot Posts: 228
    edited 2010-06-27 22:47
    Something is up here.

    This is my new transmitter code:

    temp := string("N_E_T_I_D_1_A_N_I_I_D_12")
    XB.str(@temp)
    
    



    This is is the new receiver code.

    repeat while not strcomp(animatorIDString, @buffer)
      SER.RXStr(@buffer)
    
    



    This code should work, but it does not. I tried messing around with the delimiter characters to no avail. What is missing?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-06-28 01:36
    The string function returns a pointer to the string, so you should send it using xb.str(temp) and not xb.str(@temp).· It this still doesn't work you should post all your code, and we can determine where the problem is.
Sign In or Register to comment.