python-snap7 icon indicating copy to clipboard operation
python-snap7 copied to clipboard

Improve doc for area_read in client

Open bruceunx opened this issue 1 year ago • 2 comments

  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.

bruceunx avatar Mar 26 '24 23:03 bruceunx

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"

lupaulus avatar Mar 29 '24 22:03 lupaulus

we happily accept PRs with improvements.

gijzelaerr avatar May 02 '24 07:05 gijzelaerr

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

gijzelaerr avatar Jul 04 '24 15:07 gijzelaerr