Shop OBEX P1 Docs P2 Docs Learn Events
Multi port serial object in multiple cogs question — Parallax Forums

Multi port serial object in multiple cogs question

JonathanJonathan Posts: 1,023
edited 2011-01-01 11:20 in Propeller 1
Hi all,

I'm using the multi cog serial object. It seems I can start the object in one cog and use some of the ports in another cog. It works, but I am wondering if I am asking for trouble. Should this be OK, or am I setting myself up for problems down the road?

Thanks!

Jonathan

Comments

  • andrewsiandrewsi Posts: 59
    edited 2010-12-30 13:07
    I believe that if you're using the FullDuplexSerial or Parallax Serial Terminal objects, you can start multiple instances of the drivers as separate objects, just initialize each one to use the correct output pins so they don't stomp on each other. I've done this successfully myself to have multiple ports running simultaneously.
    e.g.
    OBJ
    Port1 : "Parallax Serial Terminal"
    Port2 : "Parallax Serial Terminal"
     
    PUB Main
    Port1.StartRxTx(31,30,0,19200)
    Port2.StartRxTx(2,1,0,19200) ' Pins 1 and 2 for another port
    

    ...should be fine, I think.
  • JonathanJonathan Posts: 1,023
    edited 2010-12-30 15:53
    Andrew,

    Nope, not quite what I mean. I am using the "psFullDuplexSerial4c" object. It can handle up to 4 serial ports at a time. I am starting the object from one cog, but using some of the ports in other cogs. It works, but I'm wondering if it is a bad idea waiting to bite me.

    Thanks!

    Jonathan
  • andrewsiandrewsi Posts: 59
    edited 2010-12-30 16:08
    Can't find that object in the OBEX, but I don't see any particular reason to think that you'd have a problem - once the cog is launched, it doesn't retain any idea of who launched it - as long as the methods that access the port (or the shared memory, or whatever), are known to the other cogs that are calling it, I don't foresee trouble. The driver probably doesn't have a clue if it's the original cog sending it work, or some other new cog.

    You can run into trouble with multiple cogs if you try to access the same serial port simultaneously, resulting in interleaved buffer insertions and therefore mangled messages on the port. That can be solved with a semaphore (lock bit), but if you never have multiple cogs trying to access the same port at the same time, this'll never be an issue.
  • TimmooreTimmoore Posts: 1,031
    edited 2010-12-30 23:41
    The 4 port serial object is designed to work across multiple cogs. I use it a lot for writing to the debug port from any cog. The only limitation is if you have multiple cogs writing to the same port, the characters will be interleaved, if you need the chars ordered in some manner it will not do it for you. I do have a version that allows you to lock a port to a cog while you are outputing related chars and then release the port for other cogs, the limitation is that if you try to write to the port from another cog, the cog will pause until the other cog releases the port.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-12-31 00:57
    I like Timmoore's 4 port serial object. Lots of ports in one cog so that leaves cogs spare for other things. I've been using it for over a year - it works great!
  • JonathanJonathan Posts: 1,023
    edited 2010-12-31 09:10
    Great! Thanks for the help folks. while it was working, I just wanted to make sure I wasn't creating a "gotcha".

    Jonathan
  • kwinnkwinn Posts: 8,697
    edited 2010-12-31 13:02
    I also like Timmoore's 4 port serial object. It is all I use now even if I only need one port. Thank you ever so much for all the work you put into it Tim. It is also good to know that it can be used by multiple cogs. Thanks again Tim, much appreciated.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-01-01 11:20
    I'd like to second (or third?) Dr_Acula and kwinn's praise of Tim's object. The version I'm using is called "pcFullDuplexSerial4FC." I'm guessing Jonathan's "psFullDuplexSerial4c" has a couple typos. This object has freed up a bunch of sorely need cogs.

    Duane
Sign In or Register to comment.