Shop OBEX P1 Docs P2 Docs Learn Events
Need help trying to understand passing data between 2 objects — Parallax Forums

Need help trying to understand passing data between 2 objects

Don MDon M Posts: 1,653
edited 2011-02-21 18:17 in Propeller 1
Can someone tell me why this doesn't work? I am trying to learn how to pass data back and forth between 2 objects.

In "Main_data", using PST you enter the letter c followed by 4 digits and press enter. It is then supposed to transfer the 4 digits through a method called "swipe". The second object called "datatransfer" is supposed to receive the data through "swipe" method, transfer the data received from "Main_data" into some variables, set flagp and then wait. Then back in "Main_data" the "getflag" routine is supposed to trigger when getflagp is greater than 1 (flag set) and then transfer the data from "datatransfer" through the method "GetProd" and print it out on PST.

I know this may seem silly but I am trying to understand how this works or actually why it doesn't work.

Thanks. Code attached.

Main_data object
CON

  _clkmode        = xtal1 + pll16x                      ' Feedback and PLL multiplier
  _xinfreq        = 5_000_000                           ' External oscillator = 5 MHz

  MS_001          = 80_000_000 / 1_000

obj

  term  : "fullduplexserialplus"                        ' for terminal output
  mdb   : "datatransfer"

var                                                     
    
  long crdval                                           ' Card Value
  byte cardswiped, buffer[50]
    
pub main |  c, temp

  term.start(31, 30, %0000, 115_200)                    ' start terminal (use PST)

  repeat

    c := term.rxcheck
    if (c => 0)                                         ' anything in m->s buffer?
     case c
      "c" , "C":
          c := term.rxtime(2000)
            crdval := term.GetDec
            cardswiped := 1
            mdb.swipe(crdval, cardswiped)
            cardswiped := 0
   if (mdb.getflagp > 0)
            waitcnt((5 * MS_001) + cnt)
            temp := 0
            mdb.getprod(@buffer)
            temp := 256*buffer[0] + buffer[1] 
            term.dec(temp)
            term.str(string(","))
            term.hex(buffer[2], 2)
            term.hex(buffer[3], 2)
            term.tx(13)   

datatransfer object
var

  long Stack[128], cog
  long crdval
  byte XferBlock[50], flagp, scanflag
  byte chk,itmprh,itmprl,itmnumh,itmnuml
  byte cardswiped

PUB Start

  cog := cognew(mdbengine,@Stack)+1

pub mdbengine |  fh, fl

  cardswiped := 0
       flagp := 0

       repeat  

            if (cardswiped == 1)
                fh := crdval / 256
                fl := crdval // 256
                chk := 0
                itmprh := fh
                itmprl := fl
                'chk := $03 + fh +fl
                'txmdb(($1_00) | chk,MDB_SLAV)           ' checksum
                itmnumh := 00                            ' item number high byte
                itmnuml := 01                            ' item number low byte
                flagp := 1  
                cardswiped := 0                          ' reset card swiped

pub swipe(cv, sw)                                       ' method to bring data into datatransfer

  crdval := cv
  cardswiped := sw

pub GetFlagP

  return(flagp)

pub GetProd(DataAddress)
     
    XferBlock[0] := itmprh  
    XferBlock[1] := itmprl
    XferBlock[2] := itmnumh
    XferBlock[3] := itmnuml   
        
    bytemove(DataAddress,@XferBlock,4)

    flagp := 0

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-02-21 17:08
    Don M wrote: »
    In "Main_data", using PST you enter the letter c followed by 4 digits and press enter.
      repeat
    
        c := term.rxcheck
        if (c => 0)                                         ' anything in m->s buffer?
         case c
          "c" , "C":
              c := term.rxtime(2000)
                crdval := term.GetDec
    
    1. you should start your data transfer object
    2. the code above gets the 'c' then may consume one character (rxtime), then reads the number, meaning if you type too fast you'll lose the first digit
  • Don MDon M Posts: 1,653
    edited 2011-02-21 17:30
    @kuroneko- what do you mean by "start the data transfer object"?
  • kuronekokuroneko Posts: 3,623
    edited 2011-02-21 17:42
    mdb.start, the mdbengine method is not run be default (if that method doesn't run flagp is never set 1). So I figured the start method call is required.
  • Don MDon M Posts: 1,653
    edited 2011-02-21 17:47
    Duh.... I feel stupid. Thanks.
  • Don MDon M Posts: 1,653
    edited 2011-02-21 17:52
    Ok so regarding your first reply item #2- yes if you do type the numbers in fast it does miss the first digit. If I type c1200 and enter real fast it only shows 200 in PST. If I type it in much slower it catches all the digits.

    Can you explain why?

    Thanks.
  • kuronekokuroneko Posts: 3,623
    edited 2011-02-21 17:57
    What is the purpose of the c := term.rxtime(2000) (why is it in there)? If you wait for 2 sec (2000ms) after typing 'c' this method will return -1 and you read the whole number. If the first digit appears in the 2s window it's lost. Just remove the method call.
  • Don MDon M Posts: 1,653
    edited 2011-02-21 18:17
    Thanks. That worked.
Sign In or Register to comment.