/// <summary> /// Gets the digital value of the provided IO line. /// </summary> /// <param name="ioLine">The IO line to get its digital value.</param> /// <returns>The IOValue of the specified <paramref name="ioLine"/></returns> /// <example>To verify if this sample contains a digital value for the specified <paramref name="ioLine"/>, use the method <see cref="hasDigitalValue"/>. /// <code>if (ioSample.hasDigitalValue(IOLine.DIO0_AD0)) { /// IOValue value = ioSample.getDigitalValue(IOLine.DIO0_AD0); /// ... /// } else { /// ... /// } /// } /// </code></example> /// <seealso cref="GetDigitalValues"/> /// <seealso cref="HasDigitalValues"/> /// <seealso cref="IOLine"/> /// <seealso cref="IOValue"/> public IOValue GetDigitalValue(IOLine ioLine) { if (!digitalValuesMap.ContainsKey(ioLine)) { return(IOValue.UNKNOWN); } return(digitalValuesMap[ioLine]); }
/// <summary> /// Gets the <see cref="IOMode"/> corresponding to the provided mode Id and IO line. /// </summary> /// <param name="dumb"></param> /// <param name="modeID">The ID of the <see cref="IOMode"/> to retrieve.</param> /// <param name="ioline">The IO line to retrieve its <see cref="IOMode"/></param> /// <returns>The <see cref="IOMode"/> corresponding to the provided mode ID and IO line.</returns> public static IOMode GetIOMode(this IOMode dumb, int modeID, IOLine ioline) { if (modeID == lookupTable[IOMode.ADC].Id) { return(ioline != IOLine.UNKNOWN && ioline.HasPWMCapability() ? IOMode.PWM : IOMode.ADC); } return(lookupTable.Where(io => io.Value.Id == modeID).Select(io => io.Key).FirstOrDefault()); }
/// <summary> /// Gets the analog value of the specified <paramref name="ioLine"/>. /// </summary> /// <example>To verify if this sample contains an analog value for the specified /// <paramref name="ioLine"/>, use the method <see cref="HasAnalogValue(IOLine)"/>. /// <c>if (ioSample.HasAnalogValue(IOLine.DIO0_AD0)) { /// var value = ioSample.GetAnalogValue(IOLine.DIO0_AD0); /// ... /// } else { /// ... /// } /// }</c></example> /// <param name="ioLine">The IO line to get its analog value.</param> /// <returns>The analog value of the given IO line.</returns> /// <seealso cref="AnalogValues"/> /// <seealso cref="HasAnalogValue"/> /// <seealso cref="HasAnalogValues"/> /// <seealso cref="IOLine"/> public int GetAnalogValue(IOLine ioLine) { if (!AnalogValues.ContainsKey(ioLine)) { return(int.MaxValue); } return(AnalogValues[ioLine]); }
/// <summary> /// Gets the analog value of the specified <paramref name="ioLine"/>. /// </summary> /// <example>To verify if this sample contains an analog value for the specified <paramref name="ioLine"/>, use the method <see cref="HasAnalogValue"/>. /// <code>if (ioSample.hasAnalogValue(IOLine.DIO0_AD0)) { /// var value = ioSample.GetAnalogValue(IOLine.DIO0_AD0); /// ... /// } else { /// ... /// } /// }</code></example> /// <param name="ioLine">The IO line to get its analog value.</param> /// <returns>The analog value of the given IO line.</returns> /// <seealso cref="AnalogValues"/> /// <seealso cref="HasAnalogValue"/> /// <seealso cref="HasAnalogValues"/> /// <seealso cref="IOLine"/> public int GetAnalogValue(IOLine ioLine) { if (!analogValuesMap.ContainsKey(ioLine)) { return(int.MaxValue); } return(analogValuesMap[ioLine]); }
public BBOutput(IOLine theIOLine) { m_Line = theIOLine; Name = m_Line.IONumber.ToString(); // TEMP UIToggleEvent.Description = "UI Toggle for IO " + Name; var Defaults = CreateDefaultSubscriptionProperties(); var NewSubscription = new BBSubscription { Guid = System.Guid.NewGuid().ToString(), Id = UIToggleEvent.Id }; NewSubscription.Update(Defaults); NewSubscription.EventConsumer = new BBEventConsumer(Defaults); Subscriptions.Add(NewSubscription); }
void Inputs_IOLineChange(IOLine line, EDDevice device, IOChangeTypes changeType) { switch (line.IONumber) { case 0: if (changeType == IOChangeTypes.RisingEdge) { if (m_device.Outputs[0].Value == 1) // magnetic latch is ON { GlobalVars.DoorStatus = DOOR_STATUS.LOCKED; } else { GlobalVars.DoorStatus = DOOR_STATUS.CLOSED; } } else if (changeType == IOChangeTypes.FallingEdge) { GlobalVars.DoorStatus = DOOR_STATUS.OPEN; } OnDoorStatusEvent(new DoorStatusEventArgs(GlobalVars.DoorStatus)); break; case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break; case 7: break; } OnIOEvent(new IOEventArgs(IO_TYPE.INPUT, line.IONumber, line.Value == 1 ? true : false)); }
/// <summary> /// Indicates whether the IO line has PWM capability. /// </summary> public static bool HasPWMCapability(this IOLine source) { return(lookup[source].HasPWMCapability); }
/// <summary> /// Gets the configuration AT command associated to the IO line. /// </summary> public static string GetConfigurationATCommand(this IOLine source) { return(lookup[source].ATCommand); }
/// <summary> /// Gets the name of the IO line. /// </summary> public static string GetName(this IOLine source) { return(lookup[source].Name); }
/// <summary> /// Gets the <see cref="IOLine"/> associated to the given index. /// </summary> /// <param name="dumb">A dumb value to access the method.</param> /// <param name="index">The index corresponding to the <see cref="IOLine"/> to retrieve.</param> /// <returns></returns> public static IOLine GetDIO(this IOLine dumb, int index) { return(lookup.Where(l => l.Value.Index == index).Select(l => l.Key).FirstOrDefault()); }
/// <summary> /// Indicates whether the IO sample contains a digital value for the specified <paramref name="ioLine"/> /// </summary> /// <param name="ioLine">The IO line to check if has a digital value.</param> /// <returns>true if the specified <paramref name="ioLine"/> has a digital value, false otherwises.</returns> public bool HasDigitalValue(IOLine ioLine) { return digitalValuesMap.ContainsKey(ioLine); }
/// <summary> /// Indicates whether or not the specified <paramref name="ioLine"/> has an analog value. /// </summary> /// <param name="ioLine">The IO line to check if has an analog value.</param> /// <returns>true if the specified <paramref name="ioLine"/> has an analog value, false otherwise.</returns> /// <seealso cref="GetAnalogValue"/> /// <seealso cref="AnalogValues"/> /// <seealso cref="HasAnalogValues"/> /// <seealso cref="IOLine"/> public bool HasAnalogValue(IOLine ioLine) { return analogValuesMap.ContainsKey(ioLine); }
/** * 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; }
/// <summary> /// Gets the analog value of the specified <paramref name="ioLine"/>. /// </summary> /// <example>To verify if this sample contains an analog value for the specified <paramref name="ioLine"/>, use the method <see cref="HasAnalogValue"/>. /// <code>if (ioSample.hasAnalogValue(IOLine.DIO0_AD0)) { /// var value = ioSample.GetAnalogValue(IOLine.DIO0_AD0); /// ... /// } else { /// ... /// } /// }</code></example> /// <param name="ioLine">The IO line to get its analog value.</param> /// <returns>The analog value of the given IO line.</returns> /// <seealso cref="AnalogValues"/> /// <seealso cref="HasAnalogValue"/> /// <seealso cref="HasAnalogValues"/> /// <seealso cref="IOLine"/> public int GetAnalogValue(IOLine ioLine) { if (!analogValuesMap.ContainsKey(ioLine)) return int.MaxValue; return analogValuesMap[ioLine]; }
/** * Returns the configuration mode of the provided IO line of this XBee * device. * * @param ioLine The IO line to get its configuration. * * @return The IO mode (configuration) of the provided IO line. * * @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 * configuration command. * @throws XBeeException if there is any other XBee related exception. * * @see #setIOConfiguration(IOLine, IOMode) * @see com.digi.xbee.api.io.IOLine * @see com.digi.xbee.api.io.IOMode */ public IOMode GetIOConfiguration(IOLine ioLine)/*throws TimeoutException, XBeeException */{ // Check IO line. if (ioLine == null) throw new ArgumentNullException("DIO pin cannot be null."); // Check connection. if (!connectionInterface.SerialPort.IsOpen) throw new InterfaceNotOpenException(); // Check if the received configuration mode is valid. int ioModeValue = GetParameter(ioLine.GetConfigurationATCommand())[0]; IOMode dioMode = IOMode.UNKOWN.GetIOMode(ioModeValue, ioLine); if (dioMode == null) throw new OperationNotSupportedException("Received configuration mode '" + HexUtils.IntegerToHexString(ioModeValue, 1) + "' is not valid."); // Return the configuration mode. return dioMode; }
/// <summary> /// Indicates whether or not the specified <paramref name="ioLine"/> has an analog value. /// </summary> /// <param name="ioLine">The IO line to check if has an analog value.</param> /// <returns>true if the specified <paramref name="ioLine"/> has an analog value, false otherwise.</returns> /// <seealso cref="GetAnalogValue"/> /// <seealso cref="AnalogValues"/> /// <seealso cref="HasAnalogValues"/> /// <seealso cref="IOLine"/> public bool HasAnalogValue(IOLine ioLine) { return(analogValuesMap.ContainsKey(ioLine)); }
/** * Sets the digital value (high or low) to the provided IO line of this * XBee device. * * @param ioLine The IO line to set its value. * @param ioValue The IOValue to set to the IO line ({@code HIGH} or * {@code LOW}). * * @throws InterfaceNotOpenException if this device connection is not open. * @throws ArgumentNullException if {@code ioLine == null} or * if {@code ioValue == null}. * @throws TimeoutException if there is a timeout sending the set DIO * command. * @throws XBeeException if there is any other XBee related exception. * * @see #getIOConfiguration(IOLine) * @see #setIOConfiguration(IOLine, IOMode) * @see com.digi.xbee.api.io.IOLine * @see com.digi.xbee.api.io.IOValue * @see com.digi.xbee.api.io.IOMode#DIGITAL_OUT_HIGH * @see com.digi.xbee.api.io.IOMode#DIGITAL_OUT_LOW */ public void setDIOValue(IOLine ioLine, IOValue ioValue)/*throws TimeoutException, XBeeException */{ // Check IO line. if (ioLine == null) throw new ArgumentNullException("IO line cannot be null."); // Check IO value. if (ioValue == null) throw new ArgumentNullException("IO value cannot be null."); // Check connection. if (!connectionInterface.SerialPort.IsOpen) throw new InterfaceNotOpenException(); SetParameter(ioLine.GetConfigurationATCommand(), new byte[] { (byte)ioValue.GetID() }); }
/// <summary> /// Indicates whether the IO sample contains a digital value for the specified <paramref name="ioLine"/> /// </summary> /// <param name="ioLine">The IO line to check if has a digital value.</param> /// <returns>true if the specified <paramref name="ioLine"/> has a digital value, false otherwises.</returns> public bool HasDigitalValue(IOLine ioLine) { return(digitalValuesMap.ContainsKey(ioLine)); }
/** * 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)); }
/// <summary> /// Gets the PWM AT command associated to the IO line. /// </summary> public static string GetPWMDutyCycleATCommand(this IOLine source) { return(lookup[source].ATPWMCommand); }
/// <summary> /// Gets the digital value of the provided IO line. /// </summary> /// <param name="ioLine">The IO line to get its digital value.</param> /// <returns>The IOValue of the specified <paramref name="ioLine"/></returns> /// <example>To verify if this sample contains a digital value for the specified <paramref name="ioLine"/>, use the method <see cref="hasDigitalValue"/>. /// <code>if (ioSample.hasDigitalValue(IOLine.DIO0_AD0)) { /// IOValue value = ioSample.getDigitalValue(IOLine.DIO0_AD0); /// ... /// } else { /// ... /// } /// } /// </code></example> /// <seealso cref="GetDigitalValues"/> /// <seealso cref="HasDigitalValues"/> /// <seealso cref="IOLine"/> /// <seealso cref="IOValue"/> public IOValue GetDigitalValue(IOLine ioLine) { if (!digitalValuesMap.ContainsKey(ioLine)) return IOValue.UNKNOWN; return digitalValuesMap[ioLine]; }
/// <summary> /// Gets the <see cref="IOMode"/> corresponding to the provided mode Id and IO line. /// </summary> /// <param name="dumb"></param> /// <param name="modeID">The ID of the <see cref="IOMode"/> to retrieve.</param> /// <param name="ioline">The IO line to retrieve its <see cref="IOMode"/></param> /// <returns>The <see cref="IOMode"/> corresponding to the provided mode ID and IO line.</returns> public static IOMode GetIOMode(this IOMode dumb, int modeID, IOLine ioline) { if (modeID == lookupTable[IOMode.ADC].Id) { return ioline != IOLine.UNKNOWN && ioline.HasPWMCapability() ? IOMode.PWM : IOMode.ADC; } return lookupTable.Where(io => io.Value.Id == modeID).Select(io => io.Key).FirstOrDefault(); }
/** * Returns the analog value of the provided IO line of this XBee device. * * <p>The provided <b>IO line must be previously configured as ADC</b>. To * do so, use {@code setIOConfiguration} and {@code IOMode.ADC}.</p> * * @param ioLine The IO line to get its analog value. * * @return The analog value corresponding to the provided IO line. * * @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 IO values * command. * @throws XBeeException if there is any other XBee related exception. * * @see #getIOConfiguration(IOLine) * @see #setIOConfiguration(IOLine, IOMode) * @see com.digi.xbee.api.io.IOLine * @see com.digi.xbee.api.io.IOMode#ADC */ public int GetADCValue(IOLine ioLine)/*throws TimeoutException, XBeeException */{ // Check IO line. if (ioLine == null) throw new ArgumentNullException("IO line cannot be null."); // Obtain an IO Sample from the XBee device. IOSample ioSample = readIOSample(); // Check if the IO sample contains the expected IO line and value. if (!ioSample.HasAnalogValues || !ioSample.AnalogValues.ContainsKey(ioLine)) throw new OperationNotSupportedException("Answer does not contain analog data for " + ioLine.GetName() + "."); // Return the analog value. return ioSample.AnalogValues[ioLine]; }
void Outputs_IOLineChange(IOLine line, EDDevice device, IOChangeTypes changeType) { OnIOEvent(new IOEventArgs(IO_TYPE.OUTPUT, line.IONumber, line.Value == 1 ? true : false)); }
public void OnIOLineFallingEdgeChangedEvent(IOLine line, EDDevice device, IOChangeTypes changeType) { m_Cached = new Payload(Id, new PayloadSubject[] { new PayloadSubject("value", FallingEdgeValue) }); Invoke(m_Cached); }