/** * Gets the PWM duty cycle (in %) corresponding to the provided IO line of * this XBee device. * * <p>The provided <b>IO line must be</b>:</p> * * <ul> * <li><b>PWM capable</b> ({@link IOLine#hasPWMCapability()}).</li> * <li>Previously <b>configured as PWM Output</b> (use * {@code setIOConfiguration} and {@code IOMode.PWM}).</li> * </ul> * * @param ioLine The IO line to get its PWM duty cycle. * * @return The PWM duty cycle value corresponding to the provided IO line * (0% - 100%). * * @throws ArgumentException if {@code ioLine.hasPWMCapability() == false}. * @throws InterfaceNotOpenException if this device connection is not open. * @throws ArgumentNullException if {@code ioLine == null}. * @throws TimeoutException if there is a timeout sending the get PWM duty * cycle command. * @throws XBeeException if there is any other XBee related exception. * * @see #getIOConfiguration(IOLine) * @see #setIOConfiguration(IOLine, IOMode) * @see #setPWMDutyCycle(IOLine, double) * @see com.digi.xbee.api.io.IOLine * @see com.digi.xbee.api.io.IOMode#PWM */ public double GetPWMDutyCycle(IOLine ioLine)/*throws TimeoutException, XBeeException */{ // Check IO line. if (ioLine == null) throw new ArgumentNullException("IO line cannot be null."); // Check if the IO line has PWM capability. if (!ioLine.HasPWMCapability()) throw new ArgumentException("Provided IO line does not have PWM capability."); // Check connection. if (!connectionInterface.SerialPort.IsOpen) throw new InterfaceNotOpenException(); byte[] value = GetParameter(ioLine.GetPWMDutyCycleATCommand()); // Return the PWM duty cycle value. int readValue = ByteUtils.ByteArrayToInt(value); return Math.Round((readValue * 100.0 / 1023.0) * 100.0) / 100.0; }
/** * Sets the duty cycle (in %) of the provided IO line of this XBee device. * * <p>The provided <b>IO line must be</b>:</p> * * <ul> * <li><b>PWM capable</b> ({@link IOLine#hasPWMCapability()}).</li> * <li>Previously <b>configured as PWM Output</b> (use * {@code setIOConfiguration} and {@code IOMode.PWM}).</li> * </ul> * * @param ioLine The IO line to set its duty cycle value. * @param dutyCycle The duty cycle of the PWM. * * @throws ArgumentException if {@code ioLine.hasPWMCapability() == false} or * if {@code value < 0} or * if {@code value > 1023}. * @throws InterfaceNotOpenException if this device connection is not open. * @throws ArgumentNullException if {@code ioLine == null}. * @throws TimeoutException if there is a timeout sending the set PWM duty * cycle command. * @throws XBeeException if there is any other XBee related exception. * * @see #getIOConfiguration(IOLine) * @see #getIOConfiguration(IOLine) * @see #setIOConfiguration(IOLine, IOMode) * @see #getPWMDutyCycle(IOLine) * @see com.digi.xbee.api.io.IOLine * @see com.digi.xbee.api.io.IOMode#PWM */ public void setPWMDutyCycle(IOLine ioLine, double dutyCycle)/*throws TimeoutException, XBeeException */{ // Check IO line. if (ioLine == null) throw new ArgumentNullException("IO line cannot be null."); // Check if the IO line has PWM capability. if (!ioLine.HasPWMCapability()) throw new ArgumentException("Provided IO line does not have PWM capability."); // Check duty cycle limits. if (dutyCycle < 0 || dutyCycle > 100) throw new ArgumentException("Duty Cycle must be between 0% and 100%."); // Check connection. if (!connectionInterface.SerialPort.IsOpen) throw new InterfaceNotOpenException(); // Convert the value. int finaldutyCycle = (int)(dutyCycle * 1023.0 / 100.0); SetParameter(ioLine.GetPWMDutyCycleATCommand(), ByteUtils.IntToByteArray(finaldutyCycle)); }