Ejemplo n.º 1
0
        /// <summary>
        /// Toggles digital output value for a specific channel.
        /// </summary>
        /// <param name="channel">Channel index 1 - n.</param>
        /// <returns></returns>
        public bool ToggleChannel(int channel)
        {
            bool validChannel = ValidateChannel(channel);

            if (validChannel)
            {
                // get slave variable in order to set bit offset
                SlaveVariable slaveVariable = _slavePdos[channel - 1].Variables.First();
                _memoryMapping[0] ^= 1 << slaveVariable.BitOffset;
            }

            return(validChannel);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns digital value for a specific channel.
        /// </summary>
        /// <param name="channel">Channel index 1 - n.</param>
        /// <returns>Channel state, true: High, false: Low./returns>
        public bool GetChannel(int channel)
        {
            bool channelSet = false;

            if (ValidateChannel(channel))
            {
                // get slave variable in order to set bit offset
                SlaveVariable slaveVariable = _slavePdos[channel - 1].Variables.First();
                int           bitOffset     = slaveVariable.BitOffset;

                int channelInput = _memoryMapping[0] & (1 << bitOffset);
                channelSet = BitConverter.ToBoolean(channelInput.ToByteArray(), 0);
            }

            return(channelSet);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets digital output value for a specific channel.
        /// </summary>
        /// <param name="channel">Channel index 1 - n.</param>
        /// <param name="value">Value of channel output, true: High, false: Low.</param>
        /// <returns></returns>
        public bool SetChannel(int channel, bool value)
        {
            bool validChannel = ValidateChannel(channel);

            if (validChannel)
            {
                // get slave variable in order to set bit offset
                SlaveVariable slaveVariable = _slavePdos[channel - 1].Variables.First();
                int           bitOffset     = slaveVariable.BitOffset;

                if (value)
                {
                    // set channel bit
                    _memoryMapping[0] |= 1 << bitOffset;
                }
                else
                {
                    // clear channel bit
                    _memoryMapping[0] &= ~(1 << bitOffset);
                }
            }

            return(validChannel);
        }