Overview: Before working with Inputs and Outputs, instantiate an IOServiceClient in the base class, add it to the .AddClients(x,x,x) parameters, and pass it to any classes/methods that may need it. Syntax examples are based on an instantiated IOServiceClient object named "myIOServiceClient". This information is an explanation of C# hardware analog and digital IO calls on the OpenPV® S50 & S70. It is only intended to provide examples of the syntax used to access IO ports on OpenPV® targets. The calls shown in this article have been left in their entire object/method chain for clarity and to avoid issues of missing context. In practice, any frequently accessed components should be stored in intermediate objects. |
Digital Output Count :
The count of Digital Inputs is obtained by using:
myIOServiceClient.RequestDigitalOutputs().DigitalOutputs.Count
Example output for this call is:
2
Digital Output Switching:
The Digital Out 1 and 2 wires allow a voltage supplied load to sink to ground when the respective pin state is assigned to High (1) and then set.
Changing the state is a two part process -
The Digital Out 0 index pin is ASSIGNED High by using:
myIOServiceClient.RequestDigitalOutputs().DigitalOutputs[0].State = Services.IO.PinState.High
After the pin state is assigned to the Digital Output, the digital output must be SET using:
myIOServiceClient.SetDigitalOut(myIOServiceClient.RequestDigitalOutputs().DigitalOutputs[0])
The current assignment of the Digital Out index 0 can be determined using:
myIOServiceClient.RequestDigitalOutputs().DigitalOutputs[0].State
Verification of Digital Output Set Success:
Reading the DigitalOutputs[x].State only gives the assigned value, if the SetDigitalOut method failed, the assigned value and actual circuit state could be different. To help avoid issues, SetDigitalOut returns a SetOutputResponse object with an ErrorDescription field that can be used to verify no errors occurred. An example of how this might be executed is:
SetOutputResponse digitalResponse1 = myIOServiceClient.SetDigitalOut(myIOServiceClient.RequestDigitalOutputs().DigitalOutputs[0]);
if (String.IsNullOrEmpty(digitalResponse1.ErrorDescription))
{ Console.WriteLine($"Setting Digital Out 1 Success"); }
else
{ Console.WriteLine($"Setting Digital Out 1 Failed. Error: {digitalResponse1.ErrorDescription}"); }
Additional Digital Output Information:
Open Drain FET output pulled high to Vbatt through a 10K pullup resistor.
Designed to switch the negative side of a signal
.....
Comments
0 comments
Please sign in to leave a comment.