Пример #1
0
        // Selections for the Switch actuator:
        // element 0 -> Means "disconnected" or "open circuit" (init = 0) and is
        //              associated with the "min" message.
        // element 1 -> Means "connect" or "close the circuit", (init = 1) and is
        //              associated with the "max" message.

        /// <summary>
        /// Initializes the actuator </summary>
        /// <param name="Init"> The initialization string.
        /// </param>
        /// <exception cref="OneWireException">
        ///  </exception>
        public virtual void initActuator()
        {
            SwitchContainer switchcontainer = DeviceContainer as SwitchContainer;

            // initialize the ActuatorSelections Vector
            ActuatorSelections.Add(Min); // for switch, use min and max
            ActuatorSelections.Add(Max);
            // Now, initialize the switch to the desired condition.
            // This condition is in the <init> tag and, of course, the
            // <channel> tag is also needed to know which channel to
            // to open or close.
            int channelValue;
            int switchStateIntValue = 0;
            int initValue           = Int32.Parse(Init);

            channelValue = Channel;

            byte[] state        = switchcontainer.readDevice();
            bool   switch_state = switchcontainer.getLatchState(channelValue, state);

            if (switch_state)
            {
                switchStateIntValue = 1;
            }
            else
            {
                switchStateIntValue = 0;
            }
            if (initValue != switchStateIntValue)
            {
                // set the switch's state to the value specified in XML file
                switchcontainer.setLatchState(channelValue, !switch_state, false, state);
                switchcontainer.writeDevice(state);
            }
        }
Пример #2
0
        // Selections for the D2A actuator:
        // element 0 ->   Means change to the first wiper position.
        //
        // element 1 ->   Means change to the second wiper position.
        //
        //    .
        //    .
        //    .
        // last element 255? -> Means change to the last wiper position.

        /// <summary>
        /// Initializes the actuator </summary>
        /// <param name="Init"> The initialization string.
        /// </param>
        /// <exception cref="OneWireException">
        ///  </exception>
        public virtual void initActuator()
        {
            PotentiometerContainer pc = (PotentiometerContainer)DeviceContainer;
            int    numOfWiperSettings;
            int    resistance;
            double offset = 0.6; // this seems about right...
            double wiperResistance;
            string selectionString;

            // initialize the ActuatorSelections Vector
            // must first read the device
            byte[] state = pc.readDevice();
            // set current wiper number from xml tag "channel"
            pc.setCurrentWiperNumber(Channel, state);
            // now, write to device to set the wiper number
            pc.writeDevice(state);
            // now, extract some values to initialize the ActuatorSelections
            // get the number of wiper positions
            numOfWiperSettings = pc.numberOfWiperSettings(state);
            // get the resistance value in k-Ohms
            resistance = pc.potentiometerResistance(state);
            // calculate wiper resistance
            wiperResistance = (double)((double)(resistance - offset) / (double)numOfWiperSettings);
            // add the values to the ActuatorSelections Vector
            selectionString = resistance + " k-Ohms"; // make sure the first
            ActuatorSelections.Add(selectionString);  // element is the entire resistance
            for (int i = (numOfWiperSettings - 2); i > -1; i--)
            {
                double newWiperResistance = (double)(wiperResistance * (double)i);
                // round the values before putting them in drop-down list
                int roundedWiperResistance = (int)((newWiperResistance + offset) * 10000);
                selectionString = (double)((double)roundedWiperResistance / 10000.0) + " k-Ohms";
                ActuatorSelections.Add(selectionString);
            }
        }