Ejemplo n.º 1
0
        private void Button_write_select(string Name, IPLC_interface pLC_Interface, Button_base Button)//按照按钮模式写入
        {
            //string[] Data = Button_Class(Button);
            switch (Name)
            {
            case "Set_as_on":    //设置常ON
                if (Button.Command)
                {
                    pLC_Interface.PLC_write_M_bit(Button.PLC_Contact, Button.PLC_Address, Button_state.ON);   //写入常ON
                }
                else
                {
                    pLC_Interface.PLC_write_M_bit(Button.PLC_Contact, Button.PLC_Address, Button_state.ON);    //写入常ON
                }
                break;

            case "Set_as_off":    //设置常OFF
                if (Button.Command)
                {
                    pLC_Interface.PLC_write_M_bit(Button.PLC_Contact, Button.PLC_Address, Button_state.Off);    //写入常Off
                }
                else
                {
                    pLC_Interface.PLC_write_M_bit(Button.PLC_Contact, Button.PLC_Address, Button_state.Off);    //写入常Off
                }
                break;

            case "selector_witch":
                if (Button.Command)
                {
                    List <bool> data = pLC_Interface.PLC_read_M_bit(Button.PLC_Contact, Button.PLC_Address);                                     //先读取要写入的状态
                    pLC_Interface.PLC_write_M_bit(Button.PLC_Contact, Button.PLC_Address, data[0] == true ? Button_state.Off : Button_state.ON); //根据要写入的状态进行取反
                }
                else
                {
                    List <bool> data = pLC_Interface.PLC_read_M_bit(Button.PLC_Contact, Button.PLC_Address);                                     //先读取要写入的状态
                    pLC_Interface.PLC_write_M_bit(Button.PLC_Contact, Button.PLC_Address, data[0] == true ? Button_state.Off : Button_state.ON); //根据要写入的状态进行取反
                }
                break;

            case "Regression":
                if (Button.Command)
                {
                    pLC_Interface.PLC_write_M_bit(Button.PLC_Contact, Button.PLC_Address, Button_state.ON);    //先写入ON--后用事件复位-off
                }
                else
                {
                    pLC_Interface.PLC_write_M_bit(Button.PLC_Contact, Button.PLC_Address, Button_state.ON); //先写入ON--后用事件复位-off
                }
                state = true;                                                                               //标志位
                break;

            case "复归型_Off":
                if (Button.Command)
                {
                    pLC_Interface.PLC_write_M_bit(Button.PLC_Contact, Button.PLC_Address, Button_state.Off);    //先写入ON--后用事件复位-off
                }
                else
                {
                    pLC_Interface.PLC_write_M_bit(Button.PLC_Contact, Button.PLC_Address, Button_state.Off); //先写入ON--后用事件复位-off
                }
                state = false;                                                                               //标志位
                break;
            }
        }