python写个星三角降压启动类模板,功能测试待续。。。。

from dataclasses import dataclass
from snap7 import util
from PySide6.QtCore import QObject,QTimer


@dataclass
class Input:
    isMainRun: bool = None
    isStarRun: bool = None
    isTranRun: bool = None
    fault: bool = None
    interval: int = None
    bytes:bytearray = None

    def __post_init__(self):
        self.isMainRun = bool(self.bytes[self.isMainRun//8]>>(self.isMainRun%8)&1)
        self.isStarRun = bool(self.bytes[self.isStarRun//8]>>(self.isStarRun%8)&1)
        self.isTranRun = bool(self.bytes[self.isTranRun//8]>>(self.isTranRun%8)&1)
        self.fault = bool(self.bytes[self.fault//8]>>(self.fault%8)&1)


class OutPut:
    def __init__(self,mainout: int = None,starout: int = None,tranout: int = None,bytes: bytearray = None):
        self.__mainOut:bool = mainout
        self.__starOut:bool = starout
        self.__tranOut:bool = tranout
        self.__bytes:bytearray = bytes
        self.mainstate = util.get_bool(bytes, mainout // 8, mainout % 8)
        self.starstate = util.get_bool(bytes, starout // 8, starout % 8)
        self.transtate = util.get_bool(bytes, tranout // 8, tranout % 8)


    def start_main(self):util.set_bool(self.__bytes, self.__mainOut // 8, self.__mainOut % 8, True)
    def stop_main(self):util.set_bool(self.__bytes, self.__mainOut // 8, self.__mainOut % 8, False)
    def start_star(self):util.set_bool(self.__bytes, self.__starOut // 8, self.__starOut % 8, True)
    def stop_star(self):util.set_bool(self.__bytes, self.__starOut // 8, self.__starOut % 8, False)
    def start_tran(self):util.set_bool(self.__bytes, self.__tranOut // 8, self.__tranOut % 8, True)
    def stop_tran(self):util.set_bool(self.__bytes, self.__tranOut // 8, self.__tranOut % 8, False)

    def __str__(self):
        return f"mainstate:{self.mainstate};  starstate:{self.starstate};   transtate:{self.transtate}"


#星三角启动模块
class StarDelaStart(QObject):
    def __init__(self,intput:Input=None,output:OutPut=None):
        super().__init__()
        self.input: Input = intput
        self.output: OutPut = output
        self.timer = QTimer(self)
        self.timer.setSingleShot(True)
        self.timer.timeout.connect(self.on_timer)
    def on_timer(self):
        self.output.stop_star()
        self.output.start_tran()
        print("三角已经启动")

    def start(self,state):
        if state:
            if not all([self.input.isTranRun,self.input.isStarRun,self.input.isMainRun]):
                print("星启动")
                self.output.start_star()
                self.output.start_main()
                print("sta",self.output.mainstate,self.output.starstate)


            if self.output.mainstate and self.output.starstate:
        
                if not self.timer.isActive():
                    self.timer.start(self.input.interval)
            
            #故障报警
            if self.input.fault:
                if self.timer.isActive():
                    self.timer.stop()
                self.output.stop_main()
                self.output.stop_tran()
                self.output.stop_star()
        #停止
        if not state:
            self.output.stop_main()
            self.output.stop_tran()
            self.output.stop_star()
            









d = StarDelaStart()
d.input = Input(0,1,2,3,4000,bytearray(2))
d.output = OutPut(5,6,7,bytearray(2))



while True:
    d.start(True)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值