Beispiel #1
0
    def __del__(self):

        # kill the HMI (opened with Process)
        if (self.__process is not None):
            self.__process.join()

        # kill the HTTP server (opened with Popen)
        self.stop_http_server()

        logger.debug('Killed HMI%d and its webserver' % self.__id)
Beispiel #2
0
    def action(self):
        """Defines the action of the HMI:

        - reads the tags using the cpppo helper function
        - add them to different lists
        - appends the time value to another list
        - calls the mplot function
        """

        for index in self.__tags:
            tag = read_cpppo(self.__ipaddr, index,
                             'examples/swat/hmi_cpppo.cache')
            logger.debug('HMI%d read %s: %s' % (self.__id, index, tag))
            tag = float(tag)
            self.__values[index].append(tag)

        self.__values['time'].append(time() - self.__start_time)
        logger.debug("HMI%d - self.__values['time']: %f" %
                     (self.__id, self.__values['time'][-1]))

        self.mplot()
Beispiel #3
0
    """Init cpppo enip server.

    Execute an infinite routine loop:
        - read sensors values
    """

    # init the ENIP server
    tags = []
    tags.extend(P1_PLC1_TAGS)
    init_cpppo_server(tags)
    write_cpppo(L1_PLCS_IP['plc1'], 'HMI_MV101-Status', '2')
    write_cpppo(L1_PLCS_IP['plc1'], 'HMI_P101-Status', '1')

    time.sleep(3)

    logger.debug("Enter PLC1a main loop")

    start_time = time.time()

    while (time.time() - start_time < TIMEOUT):

        # Read and update HMI_tag
        lit101_str = read_single_statedb('1', 'AI_LIT_101_LEVEL')[3]
        write_cpppo(L1_PLCS_IP['plc1'], 'HMI_LIT101-Pv', lit101_str)
        val = read_cpppo(L1_PLCS_IP['plc1'], 'HMI_LIT101-Pv', PLC1_CPPPO_CACHE)
        logger.debug("PLC1 - read_cpppo HMI_LIT101-Pv: %s" % val)

        lit101 = float(lit101_str)

        # lit101
        if lit101 >= LIT_101['HH']:
Beispiel #4
0
    """Init cpppo enip server.

    Execute an infinite routine loop:
        - read sensors values
    """

    # init the ENIP server
    tags = []
    tags.extend(P1_PLC1_TAGS)
    init_cpppo_server(tags)
    write_cpppo(L1_PLCS_IP['plc1'], 'HMI_MV101-Status', '2')
    write_cpppo(L1_PLCS_IP['plc1'], 'HMI_P101-Status', '1')

    time.sleep(3)

    logger.debug("Enter PLC1a main loop")

    start_time = time.time()

    while(time.time() - start_time < TIMEOUT):

        # Read and update HMI_tag
        lit101_str = read_single_statedb('1', 'AI_LIT_101_LEVEL')[3]
        write_cpppo(L1_PLCS_IP['plc1'], 'HMI_LIT101-Pv', lit101_str)
        val = read_cpppo(L1_PLCS_IP['plc1'], 'HMI_LIT101-Pv', PLC1_CPPPO_CACHE)
        logger.debug("PLC1 - read_cpppo HMI_LIT101-Pv: %s" % val)

        lit101 = float(lit101_str)

        # lit101
        if lit101 >= LIT_101['HH']:
Beispiel #5
0
    tags = []
    tags.extend(P1_PLC3_TAGS)
    # tags.extend(P2_PLC3_TAGS)
    time.sleep(2)
    init_cpppo_server(tags)

    # wait for the other plcs
    time.sleep(1)

    # write_cpppo(L1_PLCS_IP['plc3'], 'AI_LIT_301_LEVEL', '3')
    # val = read_cpppo(
    #     L1_PLCS_IP['plc3'], 'AI_LIT_301_LEVEL',
    #     'examples/swat/plc3_cpppo.cache')
    # logger.debug("read_cpppo: %s" % val)

    logger.info("PLC3 - enters main loop")

    start_time = time.time()

    while(time.time() - start_time < TIMEOUT):
        # cmd = read_single_statedb('AI_FIT_101_FLOW', '1')

        lit301pv = read_single_statedb('3', 'AI_LIT_301_LEVEL')[3]

        write_cpppo(L1_PLCS_IP['plc3'], 'HMI_LIT301-Pv', lit301pv)
        val = read_cpppo(L1_PLCS_IP['plc3'], 'HMI_LIT301-Pv', PLC3_CPPPO_CACHE)
        logger.debug("PLC3 - read_cpppo HMI_LIT301-Pv: %s" % val)

        time.sleep(T_PLC_R)
    logger.info("PLC3 - exits main loop")
Beispiel #6
0
    # wait for the other plcs
    time.sleep(2)

    # write_cpppo(L1_PLCS_IP['plc2'], 'DO_MV_201_CLOSE', '2')

    val = read_cpppo(L1_PLCS_IP['plc2'], 'DO_MV_201_CLOSE',
                     'examples/swat/plc2_cpppo.cache')
    # logger.debug("read_cpppo: %s" % val)

    # synch with plc2, plc3
    # time.sleep(1)

    # TODO: look a Stridhar graph
    logger.info("PLC2 - enters main loop")
    start_time = time.time()

    write_cpppo(L1_PLCS_IP['plc2'], 'HMI_MV201-Status', '2')

    while (time.time() - start_time < TIMEOUT):
        # cmd = read_single_statedb('AI_FIT_101_FLOW', '1')

        fit201pv = read_single_statedb('2', 'AI_FIT_201_FLOW')[3]

        write_cpppo(L1_PLCS_IP['plc2'], 'HMI_FIT201-Pv', fit201pv)
        val = read_cpppo(L1_PLCS_IP['plc2'], 'HMI_FIT201-Pv', PLC2_CPPPO_CACHE)
        logger.debug("PLC2 - read_cpppo HMI_FIT201-Pv: %s" % val)

        time.sleep(T_PLC_R)
    logger.info("PLC2 - exits main loop")
Beispiel #7
0
    # wait for the other plcs
    time.sleep(2)

    # write_cpppo(L1_PLCS_IP['plc2'], 'DO_MV_201_CLOSE', '2')

    val = read_cpppo(
        L1_PLCS_IP['plc2'], 'DO_MV_201_CLOSE',
        'examples/swat/plc2_cpppo.cache')
    # logger.debug("read_cpppo: %s" % val)

    # synch with plc2, plc3
    # time.sleep(1)

    # TODO: look a Stridhar graph
    logger.info("PLC2 - enters main loop")
    start_time = time.time()

    write_cpppo(L1_PLCS_IP['plc2'], 'HMI_MV201-Status', '2')

    while(time.time() - start_time < TIMEOUT):
        # cmd = read_single_statedb('AI_FIT_101_FLOW', '1')

        fit201pv = read_single_statedb('2', 'AI_FIT_201_FLOW')[3]

        write_cpppo(L1_PLCS_IP['plc2'], 'HMI_FIT201-Pv', fit201pv)
        val = read_cpppo(L1_PLCS_IP['plc2'], 'HMI_FIT201-Pv', PLC2_CPPPO_CACHE)
        logger.debug("PLC2 - read_cpppo HMI_FIT201-Pv: %s" % val)

        time.sleep(T_PLC_R)
    logger.info("PLC2 - exits main loop")
Beispiel #8
0
    # wait for the other plcs
    time.sleep(3)

    logger.info("PLC1 - enters main loop")

    start_time = time.time()

    while(time.time() - start_time < TIMEOUT):

        # Read and update HMI_tag
        lit101_str = read_single_statedb('1', 'AI_LIT_101_LEVEL')[3]

        write_cpppo(L1_PLCS_IP['plc1'], 'HMI_LIT101-Pv', lit101_str)
        val = read_cpppo(L1_PLCS_IP['plc1'], 'HMI_LIT101-Pv', PLC1_CPPPO_CACHE)
        logger.debug("PLC1 - read_cpppo HMI_LIT101-Pv: %s" % val)

        lit101 = float(lit101_str)

        # lit101
        if lit101 >= LIT_101['HH']:
            logger.warning("PLC1 - lit101 over HH: %.2f >= %.2f" % (
                lit101, LIT_101['HH']))

        elif lit101 <= LIT_101['LL']:
            logger.warning("PLC1 - lit101 under LL: %.2f <= %.2f" % (
                lit101, LIT_101['LL']))
            # CLOSE p101
            update_statedb('0', 'DO_P_101_START')
            write_cpppo(L1_PLCS_IP['plc1'], 'HMI_P101-Status', '1')
            val = read_cpppo(