| Adding the Virtual Circuit to the ooPIC application is done programmatically with lines of code. Our wxample will start with a program that will turn an I/O line on and off with a do/loop construct.
Dim LED As New oDIO1
Sub Main()
LED.IOLine = 7
LED.Direction = cvOutput
Do
LED.State = ooPIC.Hz1
Loop
End Sub |
As previously detailed, the Virtual Circuit will use an oWire Object to provide the same function that the ooPIC application is now doing with code. Starting at the first line of code, insert a blank line and type the following statement:
This instructs the ooPIC to create an instance of an oWire Object with the name "WIRE". The oWire Object is classified as a "Processing Object". This simply means that the Object will manipulate the values of other Objects in some predefined way. The function of an oWire Object is to read a property from one or more Objects, perform a specified logic function, and store the resulting value of that function into yet another Object's property Next, the application's Do…Loop structure needs to be removed because its function is going to be replaced by the Virtual Circuit. Beginning with the Do statement, remove the following 3 lines of code.
Do
LED.State = ooPIC.Hz1
Loop |
Replace them with the following 3 lines of code.
WIRE.Input.Link(ooPIC.Hz1)
WIRE.Output.Link(LED.State)
WIRE.Operate = cvTrue |
The first line, "WIRE.Input.Link(ooPIC.Hz1)", instructs the "WIRE" Object to link its Input property to the ooPIC.Hz1 property. The second line, "WIRE.Output.Link(LED.Value)", instructs the "WIRE" Object to link its Output property to the State property of the "LED" Object. And the third line, "WIRE.Operate = cvTrue", sets the "WIRE" Object's Operate property to 1 (the value of cvTrue) which instructs it to start operating. After the program executes these 3 lines of code, the Virtual Circuit begins to operate in the following manner;
- The value of the ooPIC.Hz1 property will be loaded by the oWire Object.
- The oWire will then use that value in a logical OR operation with its other inputs. In this application, only one input was used, so the result of the logical OR function will always equal the input.
- The LED.Value is set to the result of the logical OR function.
This procedure operates in the background and will continue to operate until the WIRE.Operate property is set back to a value of 0 (cvOff). The following code shows the complete code listing written as instructed in the previous paragraphs.
Dim WIRE As New oWire
Dim LED As New oDIO1
Sub Main()
LED.IOLine = 7
LED.Direction = cvOutput
WIRE.Input.Link(ooPIC.Hz1)
WIRE.Output.Link(LED.State)
WIRE.Operate = cvTrue
End Sub |
|