Shop OBEX P1 Docs P2 Docs Learn Events
Outputting to the same serial port from different objects — Parallax Forums

Outputting to the same serial port from different objects

Cluso99Cluso99 Posts: 18,069
edited 2021-01-30 05:17 in Propeller 2

Sometimes you want to output to the same serial port from different objects within the same cog.

Chip's debug can help here.

This is another way to do it using my mpx_multiportserial object.


So here is a sample "mpx_dualdemo.spin2". It uses the same (unmodified) version of my multiport serial drivers.


Provided you control the interface using a lock, there is no reason that an object in another cog cannot use the same serial port concurrently. I've left this for you as an exercise.


Please report any bugs here.

Enjoy :)

Comments

  • cgraceycgracey Posts: 14,133

    You can pass a method pointer to any object, or just use the inherited SEND method pointer, which has simple syntax for grouping data to send.

  • Cluso99Cluso99 Posts: 18,069

    Chip,

    What I’ve done allows me to use all the methods of the object. So i get txChr, txStr, etc, etc, There are about 20 different methods supported because I have access to every method in my fullduplexserial equivalent.

    So, can what you’re suggesting do this?

    Or, is there a better way?

    Or am I missing something or over complicating it?


    I didn’t want to add another method to the “common object” tho this might have been easier. I would still need to pass a number of pointers to start the object first.

  • @Cluso99 All those methods use at the end the method to put one character into the stream. So, you need only redirect this one method via a method pointer to switch the output elsewhere. But you have to use the same method pointer in each method instead of calling the method directly which put one character into the stream.

  • Cluso99Cluso99 Posts: 18,069

    I'm not quite following this???

    Yes, it deliberately drills down to the bottom level to put a character into or out of the buffer(s).


    BTW there is one thing you may have missed. There is an optional echo between the receiver and transmitter. It's not quite working properly because it does not handle the DEL character correctly.

Sign In or Register to comment.