Menu

RuntimeError: b'CPU : Address out of range' on S7 1200

pypy pypy
2022-07-18
2022-07-18
  • pypy pypy

    pypy pypy - 2022-07-18

    Hey,
    i use Snap7 in one of my scripts and so far my tests were successful. I can build a connection from my python script running on Win10 PC to PLC S7 1200.
    After i built the connection i want my script to read a DB. For that i defined a function:

    def ReadBool(db_number, start_offset, bit_offset):
    reading = plc.db_read(db_number, start_offset, 1)
    bool = snap7.util.get_bool(reading, 0, bit_offset)
    return bool

    When i use that function (e.g. ReadBool(2, 0, 0)) i get following error:

    b'CPU : Address out of range'
    Traceback (most recent call last):
    File "PATH", line 29, in <module>
    ReadBool(2, 0, 0):
    File "PATH", line 14, in ReadBool
    reading = plc.db_read(db_number, start_offset, 1)
    File "PATH\Python310\lib\site-packages\snap7\client.py", line 226, in db_read
    check_error(result, context="client")
    File "PATH\Python310\lib\site-packages\snap7\common.py", line 89, in check_error
    raise RuntimeError(error)
    RuntimeError: b'CPU : Address out of range'</module>

    As i am quite new to python i couldnt resolve the error on my own. Any idea why i get this error? I can connect to PLC and it seems it finds the byte, otherwise it says:
    RuntimeError: b'CPU : Item not available'

     
  • f. b.

    f. b. - 2022-07-18
    def ReadBool(db_number, start_offset, bit_offset):
    reading = plc.db_read(db_number, start_offset, 1)
    bool = snap7.util.get_bool(reading, 0, bit_offset)
    return bool
    

    This doesn't sound like C++ Code, more like python-snap7.
    Post your question on the Discussionboard on github : https://github.com/gijzelaerr/python-snap7/discussions/categories/q-a

     

Log in to post a comment.