QuickStart 4: Common Methods Found in Objects

The software nature of objects allows programmers to tailor each method to meet the unique requirements of the variety of components and devices compatible with the Propeller.   While there is freedom to name the methods of these objects with any label the programmer chooses, there are in fact some common names which can be found from object to object when a function performs a common task.  This QuickStart provides an overview of these common methods.

An object’s prefix name is flexible, and is defined at the time the object is called in the OBJ block of the main program.  The examples here use the name “myobject.”
 

START

The start method is found in most objects as it is used to launch the object into one of the Propeller chip’s additional cogs.  It also commonly passes I/O or configuration information to the object as well.

myobject.start(9600)
myobject.start(12)
myobject.start(my_variable,my_variable2)

 

STOP

The stop method is the opposite of start. It stops the object and frees the cog.

INIT

The init method is used to set up variables for objects which don’t use their own cog.  It is used in place of start in these situations.  (A few objects require a call to init before calling start.)"
 

STR

The str method can be found in various display and communications objects. It is commonly used for displaying text or the contents of a variable or variable array.

myobject.str(string(“Display a line of text”))
myobject.str(string(“Display a line of text with a carriage return”,13))
myobject.str(my_multibyte_variable)
myobject.str(@my_variable_array)
myobject.str(@my_variable_array[X])

 

DEC

The dec method can be found in various display and communication objects. It is commonly used for displaying the decimal value of a variable.

myobject.dec(my_variable)

 

HEX

The hex method can be found in various display and communication objects. It is commonly used for displaying the hexadecimal value of a variable. The secondary data (2 in the example) defines the number places to calculate.

myobject.hex(my_variable,2)

 

BIN

The bin method can be found in various display and communication objects.  It is commonly used for displaying the binary value of a variable. The secondary data (8 in the example) defines the number of digits to calculate.

myobject.bin(my_variable,8)

 

Note that dec, bin, and hex are simply different ways of displaying the same information.
 

OUT (or TX)

The .out (sometimes called, .tx) method can be found in various display and communication objects.  It is commonly used for displaying the variable.  In the case of a video driver, the display will act on the contents of the variable instead of displaying the character itself.   For example: .out($08) would display a backspace, instead of displaying the bevel right corners character.
 

NEWLINE

The newline method can be found in various display and communication objects.  It is used to send a carriage return to the device.   The newline method performs the same function as out(13) or out($0D).

The available methods in an object are easy to determine using the Propeller Tool.  When an object is loaded, clicking on the “Summary” radio button beneath the tabs will display all of the object’s method names.  This can also be accomplished in BST by right-clicking on the object code, and selecting “Fold All Blocks” from the menu.