Need help trying to understand passing data between 2 objects
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
datatransfer object
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
Can you explain why?
Thanks.