Shop OBEX P1 Docs P2 Docs Learn Events
FullDuplexSerial Strings Containing Variable — Parallax Forums

FullDuplexSerial Strings Containing Variable

coryco2coryco2 Posts: 107
edited 2013-06-06 07:28 in Propeller 1
I would like to use FullDuplexSerial's Str method to send a string of long-sized values that include both fixed numbers and variables, e.g.

serial.str (string( $01, $02, variable3, $04 ))

but the compiler doesn't like the variable in there, even proceeded by an "@". Why not? Is there any way to make this work?

Comments

  • BeanBean Posts: 8,129
    edited 2013-06-06 07:25
    Strings must be constants.

    You must use "dec" to send variables.

    serial.dec(variable3)

    Bean
  • Mike GreenMike Green Posts: 23,101
    edited 2013-06-06 07:28
    No. STRING() produces constants, so the strings can't have variable information in them. Sure, you could incorporate the address of a variable in a constant string since the address itself is constant, but the .str() code just looks for a zero byte and transmits everything else.

    If you're trying to send people-readable numbers (a sequence of digits), use the .dec() method. If you want to send the content of a long variable as a sequence of 4 bytes, you'll have to use .tx() or write your own routine that then calls .tx() like this:
    PRI sendFour( value) | i
       ' Send a long as 4 bytes lsb..msb
       repeat i from 0 to 3
          serial.tx(value.byte[ i ])
    
Sign In or Register to comment.