gijzelaerr / python-snap7

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

Improve doc for area_read in client #493

Closed bruceunx closed 2 weeks ago

bruceunx commented 3 months ago
  def read_area(self, area: Areas, dbnumber: int, start: int, size: int) -> bytearray:
        """Reads a data area from a PLC
        With it you can read DB, Inputs, Outputs, Merkers, Timers and Counters.

        Args:
            area: area to be read from.
            dbnumber: number of the db to be read from. In case of Inputs, Marks or Outputs, this should be equal to 0.
            start: byte index to start reading.
            size: number of bytes to read.

        Returns:
            Buffer with the data read.

        Raises:
            :obj:`ValueError`: if the area is not defined in the `Areas`

        Example:
            >>> import snap7
            >>> client = snap7.client.Client()
            >>> client.connect("192.168.0.1", 0, 0)
            >>> buffer = client.read_area(Areas.DB, 1, 10, 4)  # Reads the DB number 1 from the byte 10 to the byte 14.
            >>> buffer
            bytearray(b'\\x00\\x00')
        """

dbnumber: number of the db to be read from. In case of Inputs, Marks or Outputs, this should be equal to 0.

from snap7 reference

DB Number if Area = S7AreaDB, otherwise is ignored.

I think maybe use dbnumber: number of the db to be read from when area type is DB, otherwise is ignored to consist with snap7 and less confused.

lupaulus commented 3 months ago

I Agree, the documentation need better reference related to the snap7 library

The set "calls this should be equal to 0", have not the same signification then "otherwise is ignored"

gijzelaerr commented 2 months ago

we happily accept PRs with improvements.

gijzelaerr commented 2 weeks ago

implemented in https://github.com/gijzelaerr/python-snap7/pull/524