Shop OBEX P1 Docs P2 Docs Learn Events
multiple serial objects — Parallax Forums

multiple serial objects

FORDFORD Posts: 221
edited 2012-12-09 18:32 in Propeller 1
Hi,

I wish to use the parallax serial terminal (PST), and run it from 2 separate cogs at 2 different baud rates (on different i/o pins obviously).

I have 2 cogs running.

Can i run the PST object simultaneously in 2 cogs, using different baud rates ?

Meaning - will it run as a unique object in each cog ?

I'm guessing that it will, then I can just start the object in each cog at the desired rate.

Any help appreciated sincerely...

Cheers,
Chris

Comments

  • SRLMSRLM Posts: 5,045
    edited 2012-12-09 00:09
    Yes. It's just an enhanced version of FDS.
  • FORDFORD Posts: 221
    edited 2012-12-09 00:23
    Sorry SRLM,

    I have no idea what you mean...

    Does the serial object get loaded into each individual cog, if the code for that cog references the object ?

    Sorry if its a dumb question...
  • Cluso99Cluso99 Posts: 18,069
    edited 2012-12-09 01:06
    IIRC you can do this...
    object
       fdx1 = "FullDuplexSerial"
       fdx2 = "FullDuplexSerial"
    
    Now you can just start each one as normal. The compiler will actually determine that FullDuplexSerial is the same for both object fdx1 and fdx2 and therefore only compile in one instance of the binary.

    In some cases, you actually require two objects to be compiled because of the way the objects work. In this case, you can copy the source (object) file with a new name i.e. copy FullDuplexSerial.spin to FullDuplexSerial2.spin and then define in your code as follows...
    object
       fdx1 = "FullDuplexSerial"
       fdx2 = "FullDuplexSerial2"
    



    There is also a 4port serial driver in the obex too.
  • SRLMSRLM Posts: 5,045
    edited 2012-12-09 01:08
    Can i run the PST object simultaneously in 2 cogs, using different baud rates ? Yes
    Meaning - will it run as a unique object in each cog ? Yes
    Does the serial object get loaded into each individual cog, if the code for that cog references the object? Backwards. The object references the "cog code".

    All you need to do is to create your object for the second serial port, and start it up.
    OBJ
    ser[2] : "ParallaxSerialTerminal"
    PUB Main
       ser[0].startRxTx(31,30,0,115200);
       ser[1].startRxTx(rx,tx,0,baud);
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-12-09 05:28
    Chris,

    Both SRLM and Cluso99 showed you how to use multiple instances of a serial driver.

    Cluso99 also mentioned a four port driver. I think Tracy Allen's four port object is currently the best. He fixed some of the framing and flow control issues of earlier versions.

    Multiple instances can be used of most objects. There are a few objects which use variables in the "DAT" section that don't work well when running multiple instances but these are kind of rare.

    A four port serial object is just a little harder to use (barely) than single port objects, but it saves on cogs. IMO, it's well worth the effort of learning to use one.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2012-12-09 10:55
    When you create two instances of PST, there will be one shared copy of the spin methods, but it will use an additional COG for a second copy of the pasm code. A each additional instance takes a new cog.

    The four port object uses one pasm cog to service up to four serial ports. It's HUB footprint is somewhat larger, so if you have cogs to spare it may be better to do two instances of PST. The four port object also supports flow control if you need it, and it rejects bytes that cause framing errors. (Thanks again for the plug, Duane!)

    A note about what cluso99 said about creating multiple instances of spin objects. It is not sufficient to simply rename the file. The compiler is smart enough to recognize that they are the same. You have to change at least one byte in the code, for example one extra DAT variable. Normally you will want only one instance of PST spin methods.
  • Cluso99Cluso99 Posts: 18,069
    edited 2012-12-09 11:37
    A note about what cluso99 said about creating multiple instances of spin objects. It is not sufficient to simply rename the file. The compiler is smart enough to recognize that they are the same. You have to change at least one byte in the code, for example one extra DAT variable. Normally you will want only one instance of PST spin methods.
    Thanks Tracy - I mised this point.
  • FORDFORD Posts: 221
    edited 2012-12-09 18:32
    Thanks to all for the replies, it has helped me enormously...

    Regards,
    Chris
Sign In or Register to comment.