Shop OBEX P1 Docs P2 Docs Learn Events
Strings help — Parallax Forums

Strings help

El PaisaEl Paisa Posts: 375
edited 2007-03-08 04:48 in Propeller 1
I hope anyone can help and thanks in advance.

If I have:

DAT
·· msg0···· byte···· "0.bmp",0
·· msg1···· byte···· "1.bmp",0
.
.
.
·· msg16·· byte···· "multi.bmp",0
·· msg17·· byte···· "div.bmp",0

and I need to send to a serial device each dat definition one at the time, which is the proper way?
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-07 18:42
    You could have a table:
    table   word  @msg0, @msg1, ... @msg8
              word  @msg9, @msg10, ... @msg17
    
    


    Then do:
    repeat i from 0 to 17
      ser.str(@@table[noparse][[/noparse] i]))
    
    


    The "@" operator at compile time provides the object relative offset of each address. The "@@" operator turns these into absolute addresses.
  • El PaisaEl Paisa Posts: 375
    edited 2007-03-07 18:47
    Thanks Mike, I did not expect a so fast response.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-07 18:53
    I have also used LOOKUP to index an array of pointers. These can be dissimilar and randomly accessed if nessesary.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Russ FergusonRuss Ferguson Posts: 206
    edited 2007-03-07 21:16
    Paul:

    Please give a code example.

    Thanks
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-07 21:38
    Sure, here is a section of my logic analyser program where I am doing nibble replacement using a hex value (in_value) entered by a·keyboard and converted to a numeric.

          vptr := lookupz(field: @wmask, @wval, @wtime)       'retrieve pointer to variable                                     
          if(position//2 == 0)                                'change high nibble                                               
            BYTE[noparse][[/noparse]vptr][noparse][[/noparse]3-position/2] &= NMSK                  'clear high nibble                                               
            BYTE[noparse][[/noparse]vptr][noparse][[/noparse]3-position/2] |= in_value << 4         'set high nibble value                                           
          else                                                'change high nibble                                              
            BYTE[noparse][[/noparse]vptr][noparse][[/noparse]3-position/2] &= !NMSK                 'clear low nibble                                                
            BYTE[noparse][[/noparse]vptr][noparse][[/noparse]3-position/2] |= in_value              'set low nibble value                                            
    
    

    So this code·arranges a set of variables as a psuedo array regardless of thier names

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • El PaisaEl Paisa Posts: 375
    edited 2007-03-08 03:03
    Hi Paul,

    the problem i found is if i use:

    · repeat i from 1 to 16
    ····· char:=lookup(i:msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9,msg10,msg11,msg12,msg13,msg14,msg15,msg16)
    ····· term.str(@char)
    ····· term.out(13)

    DAT
    · msg1······· byte····· "0.ezp",0
    · msg2······· byte····· "1.zp",0
    · msg3······· byte····· "2.ezp",0
    · msg4······· byte····· "3.zp",0
    · msg5······· byte····· "4.ezp",0
    · msg6······· byte····· "5.zp",0
    · msg7······· byte····· "6.ezp",0
    · msg8······· byte····· "7.zp",0
    · msg9······· byte····· "8.ezp",0
    · msg10······· byte····· "9.ezp",0
    · msg11······· byte····· "plus.ezp",0
    · msg12······· byte····· "minus.ezp",0
    · msg13······· byte····· "multi.ezp",0
    · msg14······· byte····· "div.zp",0
    · msg15······· byte····· "spin.bmp",0
    · msg16······· byte····· "propeller.bmp",0

    It only prints the first character of the string.
    I need to print the whole string ie, "propeller.ezp"
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-03-08 03:37
    Here's just a guess on my part, but @char passes the address of char variable. Using the lookup table, char actually holds the address of the string you want, so try using:
    term.str(char)

    Though I'm not sure why @char even gives the 1st correct character.
    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    StampPlot - GUI and Plotting, and XBee Wireless Adapters
    Southern Illinois University Carbondale, Electronic Systems Technologies
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-03-08 04:03
    Rethinking this, and looking back on what Mike Green had posted, what you probably want is this:

    ···· char:=lookup(i:@msg1,@msg2,@msg3,@msg4,@msg5,@msg6,@msg7,@msg8,@msg9,@msg10,@msg11,@msg12,@msg13,@msg14,@msg15,@msg16)
    ····· term.str(@char)
    So that char DOES hold the address of the message, and that address is sent to term.str.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-08 04:48
    Correct Martin, though Im not sure if term.str(@char) or term.str(char) is needed since char contains an adress. The reason for the result being the first character only being printed is that the value of the string was being assigned to char which is the first character of the string.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
Sign In or Register to comment.