Shop OBEX P1 Docs P2 Docs Learn Events
How do you print from 2 objects? — Parallax Forums

How do you print from 2 objects?

Dave HeinDave Hein Posts: 6,347
edited 2010-03-21 02:50 in Propeller 1
I have two objects -- test1.spin and test2.spin.· I want to call the FullDuplexSerial str method from each object.· The two files are shown below.· The print from the top object is displayed, but the print from the second object does not come out.· How do I get this to work?

Dave

'=======================================
' test1.spin
CON
· _clkmode = xtal1 + pll16x
· _xinfreq = 5_000_000
OBJ
· fds : "FullDuplexSerial"
· test2 : "test2"
PUB main
· fds.start(31, 30, 0, 57600)
· fds.rx
· fds.str(string("Test1", 13))
· test2.test2


'=======================================
' test2.spin
OBJ
· fds : "FullDuplexSerial"

PUB test2
· fds.str(string("Test 2", 13))
·

Comments

  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-03-20 02:19
    The fds object is not called in test 2.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't click on this.....

    Use the Propeller icon!! Propeller.gif
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-03-20 02:27
    I don't know what your saying.· How do you call an object?· Are you referring to the start method in FDS.· That will start up another cog, which is not what I want to do.

    Edit: I'm guessing that the problem is that FDS declares it's variable in a VAR section, and the two objects don't share the same variable space. I'll try a modified version of FDS with the variables in a DAT section to see if that fixes the problem.

    Post Edited (Dave Hein) : 3/20/2010 3:42:05 AM GMT
  • jazzedjazzed Posts: 11,803
    edited 2010-03-20 05:32
    Dave Hein said...

    Edit: I'm guessing that the problem is that FDS declares it's variable in a VAR section, and the two objects don't share the same variable space. I'll try a modified version of FDS with the variables in a DAT section to see if that fixes the problem.
    Yep that's right. I use the var to dat modification all the time. Just start it in one object and use it everywhere. As long as each object points to the same source it will work. There was a solution with wrapper methods, but I can't find it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Short answers?
    Not available since you deserve more information than you requested.

    May the road rise to meet you; may the sun shine on your back.
    May you create something useful, instead of just another hack.
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-03-20 14:46
    I moved the variables to a DAT section, and it works fine now.· I am finishing up the first version of the CLIB object, and I was planning on using FullDuplexSerial for serial I/O.· However, because of the VAR issue I'll need to include a modified version of FDS with the CLIB object.· Since I have to modify it I may include other features, such as user defined buffer sizes and malloc'ed buffers at startup.
  • mparkmpark Posts: 1,306
    edited 2010-03-20 16:16
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-03-20 18:07
    mpark,

    The Serial Mirror looks good.· I'll probably extend it so that the buffer sizes can be defined at run time and maybe add additional instances, which can be accessed by a handle.

    Dave
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-03-20 18:41
    Hello Dave,

    if you call methods of FDS from two different cogs you have to take care that the calls do not cross each other
    this would mix up the buffercontent and you just send a mixery of bytes

    best regards

    Stefan
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-03-21 02:50
    Actually, the orignal problem was calling methods in FDS from two different objects in the same cog.· I have played around with printing from different cogs in the past.· I used a lock to prevent the cogs from corrupting the read and writer buffer indexes.· However, the outputs from the different cogs do get jumbled together on the screen.· A solution for this would be to write to the buffer in units of complete lines instead of single characters.

    Dave
Sign In or Register to comment.