示例#1
0
        /// <summary>
        /// Activate/De-activate a specific relay
        /// </summary>
        /// <param name="relay"></param>
        /// <param name="state"></param>
        public async static void Set(RelayNumbers relay, Relaystate state)
        {
            await Task.Run(() =>
            {
                uint numBytes  = 1;
                uint relayAddr = (uint)relay;
                byte[] @out    = { 0x00 };
                byte pins      = 0x00;
                byte output    = 0x00;

                // Get current pin state.
                myFtdiDevice.GetPinStates(ref pins);

                switch (state)
                {
                case Relaystate.ON: output = (byte)(pins | relayAddr); break;

                case Relaystate.OFF: output = (byte)(pins & ~(relayAddr)); break;
                }
                myFtdiDevice.GetPinStates(ref pins);
                Pins = pins;

                @out[0] = output;
                myFtdiDevice.Write(@out, 1, ref numBytes);
            });
        }
示例#2
0
        /// <summary>
        /// Activate/De-activate a specific relay
        /// </summary>
        /// <param name="Rnum"></param>
        /// <param name="state"></param>
        public void RelaySwitch(Relaynum Rnum, Relaystate state)
        {
            uint numBytes = 1;
            int  relay    = 0x00;

            byte[] Out    = { 0x00 };
            byte   pins   = 0x00;
            byte   output = 0x00;

            // Find which relays are ON/OFF
            myFtdiDevice.GetPinStates(ref pins);

            switch (Rnum)
            {
            case Relaynum.ONE:
                relay = 0x01;
                break;

            case Relaynum.TWO:
                relay = 0x02;
                break;

            case Relaynum.THREE:
                relay = 0x04;
                break;

            case Relaynum.FOUR:
                relay = 0x08;
                break;
            }

            switch (state)
            {
            case Relaystate.ON:
                output = (byte)(pins | relay);
                break;

            case Relaystate.OFF:
                output = (byte)(pins & ~(relay));
                break;
            }

            Out[0] = output;
            myFtdiDevice.Write(Out, 1, ref numBytes);
        }
示例#3
0
        /// <summary>
        /// Activate/De-activate a specific relay
        /// </summary>
        /// <param name="Rnum"></param>
        /// <param name="state"></param>
        public void RelaySwitch(Relaynum Rnum, Relaystate state)
        {
            uint numBytes = 1;
            int relay = 0x00;
            byte[] Out = { 0x00 };
            byte pins = 0x00;
            byte output = 0x00;

            // Find which relays are ON/OFF
            myFtdiDevice.GetPinStates(ref pins);

            switch (Rnum)
            {
                case Relaynum.ONE:
                    relay = 0x01;
                    break;
                case Relaynum.TWO:
                    relay = 0x02;
                    break;
                case Relaynum.THREE:
                    relay = 0x04;
                    break;
                case Relaynum.FOUR:
                    relay = 0x08;
                    break;
            }

            switch (state)
            {
                case Relaystate.ON:
                    output = (byte)(pins | relay);
                    break;
                case Relaystate.OFF:
                    output = (byte)(pins & ~(relay));
                    break;
            }

            Out[0] = output;
            myFtdiDevice.Write(Out, 1, ref numBytes);
        }