Shop OBEX P1 Docs P2 Docs Learn Events
Send ascii string as parameter? — Parallax Forums

Send ascii string as parameter?

T ChapT Chap Posts: 4,223
edited 2008-11-28 21:12 in Propeller 1
If there a way short of using dat to send a string as parameter?

Example is:

PUB X
OpenFile("myfile20")


PUB OpenFile(filename)
ser.str(filename)


The filename may change, so some ability to construct it from scratch is the idea, otherwise fixed dat values as strings would work.

MY guess is that you'd convert the ascii values to hex values, plug them in an array, let the routine find delimiter and send the array:

Array[noparse][[/noparse] 0] := 'ascii m
Array[noparse][[/noparse] 1] := 'ascii y
Array[noparse][[/noparse] 2] := 'ascii f
Array[noparse][[/noparse] 3] := 'ascii i
Array[noparse][[/noparse] 4] := 'ascii l
Array[noparse][[/noparse] 5] := 'ascii e
Array[noparse][[/noparse] 6] := 'ascii 2
Array[noparse][[/noparse] 7] := 'ascii 0
Array[noparse][[/noparse] 8] := 'ascii CR

PUB X
OpenFile(@array)


Thanks for any tips.

Post Edited (TChapman) : 11/27/2008 9:25:41 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-27 20:49
    First of all, you'd need to write 'OpenFile(string("myfile20"))' to use the constant string.

    If you want the string to be in a VAR area, you'd declare 'var byte name[noparse][[/noparse]9]' and use 'OpenFile(@name)'

    If you want the string to be in a DAT area and be initialized to some value, you'd have
    DAT
    name   byte   "myfile20",0
    


    and then you'd write 'OpenFile(@name)'

    If you want to initialize a VAR area to some constant value, you could use 'bytemove(@name,string("myfile20"),9)'
    Note that the length is one greater than the number of characters in the string to include the terminating zero byte.
  • T ChapT Chap Posts: 4,223
    edited 2008-11-27 21:11
    That is awesome Mike, thank you for those details. Hope you are having a nice Thanksgiving.
  • T ChapT Chap Posts: 4,223
    edited 2008-11-28 21:12
    Those worked out great above Mike.

    Maybe I was tired, but I spent two hours last night trying to send a variable array as a parameter.

    It is easy to just use the variable on the ther end itself, but in cases of reusing the method, it would be great to know how to do this:

    Not using objects, all within one program(cog).

    This was not working to send array as parameter:



    
    VAR
       byte  array[noparse][[/noparse]128]
       long   count    
    
    PUB Method1
           count := $10
           size := count
           Method2(size, array)    'also tried  using @array   
    
    PUB Method2(count, address)  |   index
       index := 0
       repeat  count
          ser.tx(address[noparse][[/noparse]index])    'doesn't work right
            'ser.tx(array[noparse][[/noparse]index])     'this works
          index++
    
    



    What am I missing here?


    Edit:

    Scanning the manual, I see one possible solution, but I suspect there is a simpler way.

    bytemove(@Buff2, @Buff1, 100)    'Copy Buff1 to Buff2
    



    Use bytemove to copy the variable you want to "send", but in this case you don't send anything, just park a temp variable in the receiver, and move the contents to that variable when needed.

    Or write to to DAT location as an alternative:

    LONG[noparse][[/noparse]@MyList][noparse][[/noparse]0] := 2_000_000_000    'Write 2 billion to first word 
                                           'of MyList 
    
    



    Update2:

    OK, this solves it:


    PUB Method1
           count := $10
           size := count
           Method2(size, @array)    'also tried  using @array   
    
    PUB Method2(count, address)  |   index
       index := 0
       repeat  count
          ser.tx(byte[noparse][[/noparse]address][noparse][[/noparse]index])     '<<this works 
    
          index++
    



    I see that you must pass a reference to the var.

    Post Edited (TChapman) : 11/28/2008 10:00:22 PM GMT
Sign In or Register to comment.