Shop OBEX P1 Docs P2 Docs Learn Events
Getting mutiple results from multiple objects — Parallax Forums

Getting mutiple results from multiple objects

charleyshfcharleyshf Posts: 165
edited 2011-12-01 07:15 in Propeller 1
Good morning,

I've been trying to figure out something for a few days now when using mutiple objects. Say in one object :
test.spin:
PUB thisone
      resultvar[0] := 100               'Y result
      resultvar[1] := 200               'U result
      resultvar[2] := 235               'V result
 return
and in another object I want to get those results for each resultvar and use them

test2.spin
PUB Start
    PST.DEC(test.thisone)
return

If I use 'return resultvar[0]' in test.spin I get the result, but how do I get it to return each result 0,1,2 ?

Thanks

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-11-30 06:01
    Pass the address of resultvar and use the declared type byte, word, or long to read memory. Please see the Propeller manual under Spin reference; Long, Word, or Byte section.
      long[@resultvar][index]
    

    You really should post all your code we can't see resultvar's declared type or if it is a VAR or DAT.
  • charleyshfcharleyshf Posts: 165
    edited 2011-11-30 06:56
    Thank you, here is the complete code for both objects:

    TEST.SPIN
    CON
    _clkmode = xtal1 + pll16x 
    _xinfreq = 5_000_000
    
    
    VAR 
    long      resultvar[3]
    
    PUB Start
           resultvar[0] := 100
           resultvar[1] := 200
           resultvar[2] := 135 
     return resultvar[0]
    


    TEST2.SPIN
    CON
            _clkmode = xtal1 + pll16x                                               
            _xinfreq = 5_000_000
    VAR
      long  something[3]
       
    OBJ
        PST:         "Parallax Serial Terminal"
        tryit:         "TEST"
    
      
    PUB Start   | i
        PST.Start(115_200)
        Pause(2_000)
        PST.Dec (tryit.Start)    'this is where I and trying to get all 3 resultvar results
    return
    
  • Mike GMike G Posts: 2,702
    edited 2011-11-30 17:46
    Your original test.spin returned the value located in resultvar[0] you must pass back the starting address of resultvar[0]. I also included a getter method in test.spin that returns array values by index. Hopefully, between the two methods you'll get the idea. Make sure you read the LONG, WORD, and BYTE references in the Propeller manual.

    test.spin
    VAR 
      long      resultvar[3]
    
    PUB Start
      resultvar[0] := 100
      resultvar[1] := 200
      resultvar[2] := 135 
      return @resultvar
    
    
    PUB GetResultVar(idx)
      return resultvar[idx]
    

    Test2.spin
    CON
            _clkmode = xtal1 + pll16x                                               
            _xinfreq = 5_000_000
    VAR
      long  something[3]
       
    OBJ
        PST:         "Parallax Serial Terminal"
        tryit:       "TEST"
    
      
    PUB Start   | i, array
        PST.Start(115_200)
        Pause(500)
        array := tryit.Start    'this is where I and trying to get all 3 resultvar results
    
        pst.str(string("array[0] = "))
        pst.dec(long[array][0])
        pst.char(13)
    
        pst.str(string("array[1] = "))
        pst.dec(long[array][1])
        pst.char(13)
    
        pst.str(string("array[2] = "))
        pst.dec(long[array][2])
        pst.char(13)
    
        pst.str(string(13,"------------------------",13))
        pst.char(13)
        pst.str(string("GetResultVar(0) = "))
        pst.dec(tryit.GetResultVar(0))
        pst.char(13)
    
        pst.str(string("GetResultVar(1) = "))
        pst.dec(tryit.GetResultVar(1))
        pst.char(13)
    
        pst.str(string("GetResultVar(2) = "))
        pst.dec(tryit.GetResultVar(2))
        pst.char(13)
    
    
    PRI Pause(Duration)  
      waitcnt(((clkfreq / 1_000 * Duration - 3932) #> 381) + cnt)
      return
      
    return
    
  • charleyshfcharleyshf Posts: 165
    edited 2011-12-01 07:15
    Thank you so much for the examples!!

    I spent the better part of the day yesterday going through the prop manual working with longs/words/bytes and honestly at times it got more confusing as I went along, there was a section that said something to the effect that global vars were only able to be used in the object it was written in and I took that the wrong way.... I also went through the forums and found some posts that were along the lines of what I was trying to do, but they were mostly about launching methods into other cogs(which I though about, but I don't want to add to my confusion!) Thank you again!
Sign In or Register to comment.