| |||||||
| |||||||||||
| OOP is an acronym for Object-Oriented Programming. It is a term used to identify languages that are oriented towards the use of Objects. Object-Oriented Programming, in reality, is just a concept. It is an effort to make the task of writing computer programs easier by allowing the programmer to write applications that interact with what appears to be physical objects. Technically speaking, the Objects in an OOP language are combinations of code and data that are treated as a single unit. Each Object has a unique name and all references to that object are done by that name. In OOPic, all the hardware I/O and the Virtual Circuits are done by using Objects, even variables are Objects. | |||||||||||
| |||||||||||
An Object-Oriented Programming language is advantageous because humans instinctively know how to interact with physical objects. By arranging a programming language so that a programmer can interact with cyber objects in the same way, the learning curve is reduced significantly. In most computer languages, the processing and program functionality is found in the form of several dozen or so unrelated commands and keywords that need to be memorized. Several of these commands and keywords are proprietary and are not found in any other vendor's languages. This creates a situation where it is difficult to keep up with all the different "flavors" of a language. In OOP languages, all of the processing and functionality has been moved to the Objects. The language itself can then be reduced to just the commands and statements that are necessary to handle the program flow and Object manipulation. This results in a reduced instruction set which in turn results in less to memorize. In older programming languages, the processing was sequential throughout the application. With the processing moved to the Objects, the application becomes multi-tasking with each Object handling its own processing leaving the application to simply managing the Objects. In OOPic, Objects are the fundamental way in which an application interacts with its environment. When an application is being created using OOPic, the programmer only needs to remember a small set of flow-control commands and how to interact with the Objects that his application uses. | |||||||||||
| |||||||||||
Because the Objects in the OOPic environment encapsulate the functionality of the hardware found in the PIC16C74 IC, an application can interact with the hardware quickly. This is in contrast to the alternative, which would be working with a long list of memory locations that represent scattered bits and pieces of the same hardware. An Object also provides multitasking code that interacts with the application program, hardware, and other Objects. This essentially provides the programmer with pre-written code libraries. For example, one could use an oA2D Object to read the voltage present at one of the I/O Lines on the OOPic. By simply creating an oA2D Object and setting its properties, the application would have a value available to it that represents a numeric scale of a voltage. There is no need for the programmer to be worried about how to actually do the analog to digital conversion, because the Object’s multi-tasking code takes care of that. Because Objects are multi-tasking, an OOPic application can interact with several pieces of hardware at the same time. This means that your applications don't have to stop doing one thing just to go do something else. By linking Objects together, an application can create a Virtual Circuit. A Virtual Circuit is a circuit in an OOPic that appears to be a discrete, physical electronic circuit but is actually the Objects within the OOPic emulating the functionality of the circuit. Virtual Circuits are created by progmatically linking together a set of Objects in the same methodology as one would physically link together a set of electronic components. Once created, each individual part of the virtual circuit can be manipulated or evaluated by the program providing total computerized control of the entire circuit. The following table describes the types of Objects you can use in OOPic languages.
| |||||||||||
| |||||||||||
A single statement in the application's code creates an Object . In OOPic Basic syntax, the programmer would use the Dim statement in his application to do this. The Dim statement expects the programmer to specify a unique name for the new Object and what kind of Object it should be. Then, when the application is run and it encounters this statement in code, an instance of that type of Object will be created. The following example demonstrates the statement used to create an instance of an Object where the Object’s name would be "XYZ" and the Object’s type would be oByte. OOPic has several different types of Objects that an application can create. Each one of these different types has what is called an Object class. An Object class defines how each Object works. To understand the relationship between an Object and its class, think of an automobile and it’s blueprints. The blueprints would be the class, because it defines the characteristics of each car - for instance, size, shape and how the car works. This blueprint is then used to create one or more automobiles and the automobiles that are created, would be the Objects. Each Object that is created from a class is considered to be an instance of that class. When an Object is created, it is an identical copy of its class. Once it exists as an individual Object, it can be customized by changing its properties. For example, if you create 3 Objects using the same class, each one of the 3 new Objects is an identical instance of that class. Each of the 3 new Objects shares a common set of characteristics and capabilities (properties, methods, and events), defined by the class. However, each one must be created with a different name and once created, each Object's properties and methods can be separately controlled. All of the Dim statements are required to be at the beginning of the application's program. When the OOPic is initially powered up, or after the OOPic is reset, the Dim statements will be the first items encountered, thus all of the application's Objects will be created and their values initialized before any other code is executed. | |||||||||||
| |||||||||||
In the OOPic Basic syntax programming language, an application must declare its intent to create an instance of an Object by using the Dim command. This statement allocates memory out of the free RAM area to hold the instance of the Object. The programmer gives the new Object a name that the application program will use to identify it with. Any attempt made in the application program to refer to an Object that has not yet been created will result in a compile time error and the compilation will not complete. The following example demonstrates the statement used to create an instance of an Object where the Object’s name would be "TheNumberThatWeWant" and the Object’s type would be oByte. Object NamesEach Object within an application program must have a unique name so that the application program can refer to it. Object Names can be anything so long as they follow standard naming conventions. The following lists the rules of the standard naming convention:
The name of the Object is not stored in RAM and therefore can be any length (up to 32 characters) with out affecting the amount of RAM that gets allocated for the Object's instance. Object Names are case insensitive. I.E. the names: "ThingOne" and "thingone" are recognized as the same Object. Creating Arrays of ObjectsYou can declare and use arrays of Objects by specifying a subscript value in the Dim statement. In the following example two arrays of Objects are being created, the first is an array of 3 oByte Objects and the second is an array of 6 oDio1 Objects. These Objects are now accessed by including the subscript number. In the following example, All the values in BA(1) through BA(6) are added together in Z. Creating Objects from Classes with a variable sizeThe class definition of the three Objects oBuffer, oGate and oFanout have variable sizes. In the case of the oBuffer Object, the class size specifies how many bytes long the buffer will be. In the case of the oGate Object, the class size specifies how many inputs the gate function will have. In the case of the oFanout Object, the class size specifies how many outputs the fan-out function will have. Refer to the OOPic technical guide for a list of Object classes. | |||||||||||
| |||||||||||
| OOPic Objects supports properties, methods, and events. You can change an Object’s characteristics by changing its properties. In addition to Properties, Objects have methods. Methods are a part of Objects just as properties are. Generally, methods are actions that are perform on the Object, while properties are the attributes you set or retrieve. Objects also have events. Events are triggered when some aspect of the Object is changed and program code is executed in response to this change. Once an instance of an Object has been created, all references to that instance are done by specifying its name followed by a period and then the property or method that you want to reference. | |||||||||||
| |||||||||||
An Object’s properties are the values that it holds. These properties can be numeric values for storage or specifying what to do or even for indicating that something was done.Setting Property ValuesYou would set the value of a property when you want to change the behavior of an Object. For example, you change the Direction property of a oDio1 Object to specify whether you want the I/O Line to be an input or an output. To set the value of an Object's property, specify the Object's name followed by a period and then the property to set. The Following shows the syntax of setting an Object's property to a value:
The following example demonstrates a property being set: In this example, an Object named ThingA is told that its IOLine property is to be set to 1 and its Direction property is to be set to 1, (cvInput). cvInput is a constant that equals 1. Therefore, after this example is executed, the Direction property of the Object with the name "ThingA" is equal to 1. When the Direction property of an oDio1 Object is 1, the Value property of that Object is updated with the electrical state of the I/O Line 1. Some Objects have properties that are read only. These Objects generally have done some calculations to derive at the value set in the property and writing to them would only erase these values. Getting Property ValuesReading the value of a property is done when the application program needs to find the state of an Object. For example, a program can determine whether or not a voltage is present at an I/O Line by reading the Value property of a oDio1 Object which points to that I/O Line. To get the value of an Object's property, specify the Object's name followed by a period and then the property to get. The Following shows the syntax of getting an Object's property value:
In the following example the value of one oDio1 is read, and a second oDio1 is set to its value. A property value can also be used in a complex expressions. In the following code example, MyNumber is set to either 0 or 5 depending on whether or not there was a voltage present on the I/O Line at the time the statement is executed. Using Default PropertiesMany Objects have default properties. Default properties can be used to simplify the application’s code, because the code does not need to refer explicitly to the default property when setting or retrieving the value. The default property can be set when the Object is dimensioned. For an Object where Value is the default property, the following 2 code fragments are equivalent:
And
Variable and Hardware type Objects will always use Value as the default property. Not all Objects have a default property, in these cases, specifying the properties will always be required. In the following 2 code fragments, the value of the variable Q is incremented by one.
And Objects that are used in a Virtual Circuit and are connected to other Objects will use the default properties of the Objects they are connected to, except in the case of explicitly pointing to an Object’s flag properties. Refer to the OOPic technical guide for a list of Object properties. | |||||||||||
| |||||||||||
A method is an action that an Object can perform. When invoked, they instruct the Object to do a specified function. Using Methods in CodeYou would use a method when you want the Object to perform a specified function. For example, an Object will increase its Value property by 1 when the Inc method is invoked. To invoke an Object's method, specify the Object's name followed by a period and then the method to invoke. The Following shows the syntax of invoking an Object's method.
The following example demonstrates a method being invoked.: In this example, an Object named ThingA is told that to set its Value property to 1. The Clear method is then invoked which sets the Object's Value property to 0. Refer to the OOPic technical guide for a list of Object methods. | |||||||||||
| |||||||||||
An Event is any action that has happened within an Object. Often, an application program will need to perform a procedure when a particular Event has occurred. The oEvent ObjectThe oEvent Object is a special OOPic Object that will execute a specified sub procedure when it's Operate property is set to 1. The oEvent Object's Operate property can be linked to a Virtual Circuit allowing any event in the OOPic to trigger events. | |||||||||||
| |||||||||||
Connections between OOPic Objects give the programmer the ability to build a Virtual Circuit within the OOPic. Several of the Objects defined in the OOPic languages are capable of manipulating the properties of other Objects. This gives OOPic applications the power of a Virtual Circuit. Virtual Circuits can exchange data and do calculations in the background while the application program is focussing on what to do with, and how to react to the state of the Virtual Circuit. For example, in the application note "Driving a stepper motor" a Virtual Circuit is defined that will position a stepper motor at an absolute location. A single variable contains the value of that location and when changed, the stepper motor will turn to the new location. The only code that the application program has to do to turn the stepper motor to a particular location, is assign one variable the value of the new location. The following example demonstrates an assignment like this:
The building blocks of Virtual Circuits are the Processing Objects. These Objects retrieve their input values and store their output values in the properties of the Objects that they are linked to. Objects are linked to other Object through pointers. Pointers are a data type that simply tells one Object where to find the other Object. Two types of pointers exist;
A Pointer to a target Object tells the linked Object where the target Object is. A pointer of this type expects to be set to the Object itself. An Object link using this type of pointer will always set or return the target Object’s Value property. A Pointer to a target Object’s Flag property tells the linked Object where the Flag property is. A pointer of this type expects to be set to an Object’s Flag property. An Object link using this type of pointer will always set or return the target Object’s Flag property that it was pointed to. A Link is made between Objects when the Processing Object’s pointers are linked to the target Object or its Flag properties. In the following example, two inputs of a oGate Object are connected to two oDio1 Objects. Pointer types and the Object’s property types must always match. In the previous example, the pointer types are matched. The input properties of an oGate Object must always be connected to Flag properties and the Value property of a oDio1 Object is a Flag type property. | |||||||||||
| |||||||||||
The OOPic programming language has the ability to communicate and exchange data with the Objects within an entirely different OOPic. This is helpful when you dedicate one OOPic to do a particular function and want to control its activities from another OOPic or other computer. The OOPic uses the Philips I2C two wire network to transfer information about the values within the Objects to other computers hooked into the I2C network. Up to 127 different components can be collectively connected to this network by attaching 2 wires and a ground reference. No specialized cables or components are required to use the I2C network. For further information on the Philips I2C network, see the link to the Philips web sight at http://www.oopic.com | |||||||||||