/// <summary> /// Gets the state of the specified channel. /// </summary> /// <param name="vars">The state of the device.</param> /// <param name="channel">Specifies what channel to fetch.</param> /// <returns>The state of the specified channel.</returns> public static SmcChannelVariables getChannel(this SmcVariables vars, SmcChannel channel) { switch (channel) { case SmcChannel.Analog1: return(vars.analog1); case SmcChannel.Analog2: return(vars.analog2); case SmcChannel.Rc1: return(vars.rc1); case SmcChannel.Rc2: return(vars.rc2); default: throw new Exception("Unknown Channel: " + channel.ToString()); } }
/// <summary> /// Returns true if the specified channel is a limit or kill switch and /// it is currently active. This information comes from the limitStatus /// register. /// </summary> public static bool switchActive(this SmcVariables vars, SmcChannel channel) { switch (channel) { case SmcChannel.Analog1: return((vars.limitStatus & SmcLimitStatus.Analog1) != 0); case SmcChannel.Analog2: return((vars.limitStatus & SmcLimitStatus.Analog2) != 0); case SmcChannel.Rc1: return((vars.limitStatus & SmcLimitStatus.Rc1) != 0); case SmcChannel.Rc2: return((vars.limitStatus & SmcLimitStatus.Rc2) != 0); default: throw new Exception("Unknown Channel: " + channel.ToString()); } }
/// <summary> /// Gets the current state of the device. /// </summary> public unsafe SmcVariables getSmcVariables() { SmcVariables vars = new SmcVariables(); try { // Note: In later versions of this software, this function should have // arguments that allow you to specify which of these flags to set. // For now, just set all of them, meaning that this request will clear // error occurred flags and clear the current chopping occurrence count. UInt16 flags = 3; controlTransfer(0xC0, (byte)SmcRequest.GetVariables, flags, 0, &vars, (UInt16)sizeof(SmcVariables)); } catch (Exception exception) { throw new Exception("There was an error reading variables from the device.", exception); } return(vars); }