View Full Version : Using method in Cog from another

05-15-2008, 07:21 PM
Hello everyone,

I am doing my first project with a the Propeller, though having a number of years of coding experience, so not new to programming, just the Propeller ways and architecture.

In any case, what I am doing is something like this:

Primary COG:· Startup and Screen/TV control for status, etc
···················Also starts up COG 2 and 3 and 4

Cog 2: FullDuplexSerialExtended

Cog 3:·TV_Terminal

Cog 4: Parser (my code)

In any case, the COG 4's purpose is to parse the incoming data (RS232), into a buffered set of messages for processing and displaying.· It needs to access the FullDuplexSerialExteneded - rxcheck, and rx methods.· But being this was created in the PRIMARY COG, I cant seem to reference it to read bytes to parse.· When I try adding the FULLDUPLEXSERIALEXTENDED in the OBJ section of my parser, the whole application fails to compile as I have exceed MAX NUMBER OF LONGS, I assume this is from having the same object instantiated twice consuming too much memory.

How does one reference the methods of an object instianted in another COG?


Mike Green
05-15-2008, 09:11 PM
You need to back up a bit first to understand what's going on.

1) There's a difference between cogs and objects. You can have a program consisting of several objects all of which use a single cog for execution. On the other hand, you can have a program with only one object (the main one) that uses all the cogs, running either the same methods or different groups of methods using different cogs.

2) FullDuplexSerialExtended has two parts. One, written in assembly language that does all the serial I/O and runs in its own cog, and another, written in Spin, that interfaces to this cog and also does the formatting stuff. This Spin portion runs in whatever cog calls it.

3) Similarly, TV_Terminal consists of two parts. One, written in assembly language, does the generation of the video signal from a text buffer and runs in its own cog. The other part, written in Spin, runs in whatever cog does the calling to the public methods and basically deposits characters in the text buffer for display.

4) It sounds like your primary cog needs to start the parser which in turn should be the object (and cog) to start FullDuplexSerialExtended. Your primary cog should not include FullDuplexSerialExtended as an object.

5) It's possible to have an object that can be included in more than one other object. Typically these have no VAR section, but store all their data in a DAT section which is shared among all instances. These have to be constructed carefully if its possible for them to be executed by more than one cog. One example in the Propeller Object Exchange is obex.parallax.com/objects/243/ (http://obex.parallax.com/objects/243/).