gijzelaerr / python-snap7

A Python wrapper for the snap7 PLC communication library
http://python-snap7.readthedocs.org/
MIT License
650 stars 245 forks source link

PLC crashed when executing the "get_cpu_info" function #467

Closed ltwcare closed 12 months ago

ltwcare commented 1 year ago

I am using version 1.3 of python-snap7 to read data from an S7-300 PLC. Reading out the data works perfectly, both on inputs, flags and data blocks. However, as soon as I execute the function 'get_cpu_info()', the PLC crashes and all LEDs starts to flash. To bring the PLC 'back to life', it must be completely powered down.

Python version: 3.10.6 Python Snap7: v1.3

Reproducible on the following PLCs

Message buffer PLC after restart

Number | Time | Date | Event 1 | 12:46:10:971 pm | 20.09.2023 | Mode transition from STARTUP to RUN 2 | 12:46:10:967 pm | 20.09.2023 | Request for manual warm restart 3 | 12:46:10:763 pm | 20.09.2023 | Mode transition from STOP to STARTUP 4 | 12:45:58:008 pm | 20.09.2023 | Memory reset executed 5 | 12:45:50:993 pm | 20.09.2023 | STOP caused by CPU memory management 6 | 12:45:50:993 pm | 20.09.2023 | Power on backed up 7 | 12:45:50:993 pm | 20.09.2023 | Illegal module: replace module and reset memory 8 | 12:42:29:983 pm | 20.09.2023 | DEFECTIVE: internal system error 9 | 11:45:21:496 am | 20.09.2023 | Mode transition from STARTUP to RUN 10 | 11:45:21:492 am | 20.09.2023 | Request for manual warm restart

code snippet

        try:
            for j in range(self.nr_clients):
                self.client[j].set_connection_type(0xFD)
                self.client[j].connect(address=self.config.s7_ip, rack=self.config.s7_rack, slot=self.config.s7_slot)
                await asyncio.sleep(1)

            test = self.client[0].get_cpu_info()    # EXECUTE ==> CRASH!
            self.connection_finished = True
        except Exception as ex:
            self.logger.error(f'Client: Error while open the S7 connection to {self.config.s7_ip} ID: {j}! [{ex}]')
nikteliy commented 1 year ago

Hi @ltwcare Requests to the PLC are generated by the snap7 library. So, perhaps it's better to ask this question there