谁知道怎么用PLC编写中央空调控制程序

谁知道怎么用PLC编写中央空调控制程序,第1张

要用模拟量模块,对信号进行采集,一般式4-20MA

或0-5v的信号,把信号采集后进行陪大模拟量运算就OK了,具体的要根据PLC品牌来选择相应的指令,然兄岩后根据你温度传感器,压力传感变送器量羡乱御程进行运算。把运算结果传送到你的显示器就ok

写好了,两个类分别为:

 public enum Mode

    {

        Heating,

        Cooling

    }

    public enum UpDown

    {

        Up,

        Down

    }

    public class AirConditioner

    {

        private bool powerOn

        private Mode currentMode

        private int currentTemp

        public AirConditioner()

        {

            this.powerOn = false

            this.currentMode = Mode.Cooling

            this.currentTemp = 16

        }

        public void SwichPower()

        {

            this.powerOn = !powerOn

        }

        internal void SetMode(Mode mode)

        {

            this.currentMode = mode

        }

        internal void SetTemp(UpDown upDown)

        {

            switch (upDown)

            {

                case UpDown.Up:

                    if (this.currentTemp <= 30)

                    {

                        this.currentTemp++

                    }

                    break

                case UpDown.Down:

                    if (this.currentTemp >= 16)

                    {

                        this.currentTemp--

            衡历        }

                    break

            }

        }

        public 咐肆搜override string ToString()

        {

            return string.Format("Current Status:\r\nPower: {0}\r\nMode: {1}\r\nTemp: {2}", this.powerOn ? "On" : "Off", this.currentMode, this.currentTemp)

        }

    } public class RemoteController

    {

        private AirConditioner conditioner

        public RemoteController()

        {

            this.conditioner = new AirConditioner()

        }

        public void SwitchPower()

        {

            this.conditioner.SwichPower()

            Console.WriteLine(this.conditioner)

        }

        public void SetMode(Mode mode)

        {

        雹闹    this.conditioner.SetMode(mode)

            Console.WriteLine(this.conditioner)

        }

        public void SetTemp(UpDown upDown)

        {

            this.conditioner.SetTemp(upDown)

            Console.WriteLine(this.conditioner)

        }

    }

值得注意的是,“通过直接 *** 作空调不能进行调节温度、改变模式(制热、制冷)。”这一条说明这些方法应该不允许被声明为public,但是又要能够被遥控器访问,所以应该声明为internal

测试代码:

 static void Main(string[] args)

        {

            var controller = new RemoteController()

            Console.WriteLine("Turn on the conditioner...\r\n")

            controller.SwitchPower()

            Console.WriteLine("================================================================")

            Console.WriteLine("Turn off the conditioner...\r\n")

            controller.SwitchPower()

            Console.WriteLine("================================================================")

            Console.WriteLine("Set the mode as \"cooling\"...\r\n")

            controller.SetMode(Mode.Cooling)

            Console.WriteLine("================================================================")

            Console.WriteLine("Set the mode as \"Heating\"...\r\n")

            controller.SetMode(Mode.Heating)

            Console.WriteLine("================================================================")

            Console.WriteLine("Turn up temp...\r\n")

            controller.SetTemp(UpDown.Up)

            Console.WriteLine("================================================================")

            Console.WriteLine("Turn down temp...\r\n")

            controller.SetTemp(UpDown.Down)

        }

运行结果:

源码在附件中,如有疑问,欢迎追问。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/yw/12355375.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存