Shop OBEX P1 Docs P2 Docs Learn Events
help passing arrays to modules — Parallax Forums

help passing arrays to modules

Chip CoxChip Cox Posts: 73
edited 2011-03-20 10:18 in Propeller 1
It's always the easy things that give me problems.

I'm trying to pass an byte array of integers to a module
CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

OBJ
  debug : "Parallax Serial Terminal"

DAT

VAR
  byte decarray[4]

pub main
  debug.start(115200)
  waitcnt((clkfreq*4)+cnt)
  debug.home
  debug.clear
  
  decarray[0]:=192
  decarray[1]:=168
  decarray[2]:=2
  decarray[3]:=237

  debug.str(string("first dec array print",13))
  debug.dec(decarray[0])
  debug.str(string("."))
  debug.dec(decarray[1])
  debug.str(string("."))
  debug.dec(decarray[2])
  debug.str(string("."))
  debug.dec(decarray[3])
  debug.str(string(13))

  TestIt(string("no  @ no  byte no  [0] : "),decarray)
  TestIt(string("yes @ no  byte no  [0] : "),@decarray)
  TestIt(string("no  @ yes byte no  [0] : "),@byte[decarray])
  TestIt(string("no  @ no  byte yes [0] : "),decarray[0])
  TestIt(string("no  @ no  byte yes [0] : "),@decarray[0])
  TestIt(string("no  @ yes byte yes [0] : "),@byte[decarray][0])
  TestIt(string("two @ no  byte no  [0] : "),@@decarray)
  
pub TestIt(descr,testarray)
  debug.str(descr)
  debug.dec(testarray[0])
  debug.str(string("."))
  debug.dec(testarray[1])
  debug.str(string("."))
  debug.dec(testarray[2])
  debug.str(string("."))
  debug.dec(testarray[3])
  debug.str(string(13))
  

output looks like this
first dec array print
192.168.2.237
no @ no byte no [0] : 192.103809041.166594724.0
yes @ no byte no [0] : 1584.103809041.166594724.0
no @ yes byte no [0] : 192.103809041.166594724.0
no @ no byte yes [0] : 192.103809041.166594724.0
no @ no byte yes [0] : 1584.103809041.166594724.0
no @ yes byte yes [0] : 192.103809041.166594724.0
two @ no byte no [0] : 208.103809041.166594724.0

I tried passing it by reference every way I could think of. Now I have a headache.

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-03-19 21:10
    You expect a byte array address in your TestIt method, therefore you have to use it as one.
    pub TestIt(descr,testarray)
      debug.str(descr)
      debug.dec([COLOR="red"]byte[testarray][0][/COLOR])
      debug.str(string("."))
      debug.dec([COLOR="red"]byte[testarray][1][/COLOR])
      debug.str(string("."))
      debug.dec([COLOR="red"]byte[testarray][2][/COLOR])
      debug.str(string("."))
      debug.dec([COLOR="red"]byte[testarray][3][/COLOR])
      debug.str(string(13))
    
    Subsequently you should use @decarray or @decarray[0].
  • Chip CoxChip Cox Posts: 73
    edited 2011-03-20 04:47
    Thanks,
    I could have sworn I tried that at one point or another. Guess I was looking at it for to long <grin>.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-03-20 10:18
    Chip,

    FYI, when you're only sending one character to the terminal you can use the char method.

    debug.char(".")

    You can also use the ASCII number for the character. This is equivalent to the above statement.

    debug.char(46)

    Less typing and the program would run a little faster (I doubt it would be noticeable).

    Another FYI while I'm on the topic. The char method goes by a variety of names depending on the serial object. FullDuplexSerial uses "tx." There's others that use "out."

    Happy Spinning.

    Duane
Sign In or Register to comment.