Not all XBee protocols support pulse-width modulation (PWM) output handling, but the Digi IoT Library for .NET MAUI provides functionality to manage them. When you configure an XBee IO line as PWM output, you must use specific methods to set and read the duty cycle of the PWM. The duty cycle is the proportion of ON time to the regular interval or period of time. A high duty cycle corresponds to high power, because the power is ON for most of the time. The percentage parameter of the set duty cycle method is a double, which allows you to be more precise in the configuration.
Set the duty cycle value
For the set case, use the method SetPWMDutyCycle(IOLine, double).
| Method | Description |
|---|---|
SetPWMDutyCycle(IOLine, double) |
Sets the duty cycle (in %) of the provided IO line. Arguments are an item of the IOLine enumeration class (line to set its duty cycle) and a double with the value of the duty cycle (0 - 100). |
The SetPWMDutyCycle(IOLine, double) method may fail for the following reasons:
-
The IO line argument is unknown or does not have PWM capability or the duty cycle value is out of the 0 - 100 range, throwing an ArgumentException.
-
The device is not connected, throwing an InterfaceNotOpenException.
-
There is a timeout reading the duty cycle value, throwing a TimeoutException.
-
Other errors are caught as XBeeException.
| A PWM line must be configured in IOMode.PWM mode to set the duty cycle value. |
// Instantiate an XBee device object.
XBeeBLEDevice myXBeeBLEDevice = new XBeeBLEDevice("00:00:00:00:00:00", "password");
// Connect the device.
myXBeeBLEDevice.Connect();
// Configure the DIO10_PWM0 line to be PWM.
myXBeeBLEDevice.SetIOConfiguration(IOLine.DIO1_AD1, IOMode.PWM);
// Set a duty cycle of 75% to the DIO10_PWM0 line (PWM output).
myXBeeBLEDevice.SetPWMDutyCycle(IOLine.DIO10_PWM0, 75);
Read the duty cycle value
You can use the GetPWMDutyCycle(IOLine) method of a PWM line to get its current duty cycle percentage.
| Method | Description |
|---|---|
GetPWMDutyCycle(IOLine) |
Gets the duty cycle (in %) corresponding to the provided IO line. Parameter must be an item of the IOLine enumeration class (line to get its duty cycle value). Returned value is a double (0 - 100). |
The GetPWMDutyCycle(IOLine) method may fail for the following reasons:
-
The IO line argument is unknown or does not have PWM capability, throwing an ArgumentException.
-
The device is not connected, throwing an InterfaceNotOpenException.
-
There is a timeout reading the duty cycle value, throwing a TimeoutException.
-
Other errors are caught as XBeeException.
| A PWM line must be configured in IOMode.PWM mode to read its duty cycle value. |
// Instantiate an XBee device object.
XBeeBLEDevice myXBeeBLEDevice = new XBeeBLEDevice("00:00:00:00:00:00", "password");
// Connect the device.
myXBeeBLEDevice.Connect();
// Configure the DIO10_PWM0 line to be PWM.
myXBeeBLEDevice.SetIOConfiguration(IOLine.DIO1_AD1, IOMode.PWM);
// Get the duty cycle of the DIO10_PWM0 line (PWM output).
double dutyCycle = myXBeeBLEDevice.GetPWMDutyCycle(IOLine.DIO10_PWM0);