| Adding the Event Driven routines to the ooPIC application is done programmatically with lines of code. Because this application is a modification of the "First Virtual Circuit" application, found in Chapter 7, the final code listing for the ooPIC application in Chapter 7, as shown below, will need to be modified.
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 |
As previously detailed, this application will use an oEvent Object to provide more complex processing. 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 oEvent Object with the name "BLINK". The function of an oEvent Object is to call a subprocedure when its Operate property is set to 1. Next, the Virtual Circuit needs to be changed. In the Chapter 7 application, the "WIRE" Object's output was linked to the oDio1 Object's State property. This needs to be changed so that it is linked to the oEvent Object's Operate property.

Locate the line that reads "WIRE.Output.Link(LED.Value)", and change it to read as show:
WIRE.Output.Link(BLINK.Operate) |
This instructs the "WIRE" Object to link its Output property to the Operate property of the "BLINK" Object. After the program executes this line of code, the Virtual Circuit begins to operate in the following manner; and will continue to operate until WIRE.Operate is set back to a value of 0;
- 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 BLINK.Operate property is set to the result of the logical OR function.
- Each time the BLINK.Operate property changes from 0 to 1, the "BLINK" Object's Subprocedure is executed.
The following code shows the complete code listing written as instructed in the previous paragraphs. Note that this will not comiler yet as it still needs the Event routine.
Dim BLINK As New oEvent
Dim WIRE As New oWire
Dim LED As New oDIO1
Sub Main()
LED.IOLine = 31
LED.Direction = cvOutput
WIRE.Input.Link(ooPIC.Hz1)
WIRE.Output.Link(BLINK.Operate)
WIRE.Operate = cvTrue
End Sub |
|