diff --git a/revpimodio2/__init__.py b/revpimodio2/__init__.py index 708b616..f1c3100 100644 --- a/revpimodio2/__init__.py +++ b/revpimodio2/__init__.py @@ -21,7 +21,7 @@ __author__ = "Sven Sager " __copyright__ = "Copyright (C) 2018 Sven Sager" __license__ = "LGPLv3" __name__ = "revpimodio2" -__version__ = "2.5.0" +__version__ = "2.5.1" # Global package values OFF = 0 diff --git a/revpimodio2/netio.py b/revpimodio2/netio.py index c982544..3f1ca63 100644 --- a/revpimodio2/netio.py +++ b/revpimodio2/netio.py @@ -463,6 +463,42 @@ class NetFH(Thread): return bytes(self.__buff_recv) + def readinto(self, buffer: bytearray) -> int: + """ + Read data from network into a buffer. + + :param buffer: Use Buffer to write bytes into + :return: Amount of read bytes + """ + if self.__config_changed: + raise ConfigChanged("configuration on revolution pi was changed") + if self.__sockend.is_set(): + raise ValueError("read of closed file") + + length = len(buffer) + with self.__socklock: + # b CM ii ii 00000000 b = 16 + self._slavesock.sendall(pack( + "=c2sHH8xc", + HEADER_START, b'DA', self.__position, length, HEADER_STOP + )) + + self.__position += length + + buffer.clear() + while length > 0: + count = self._slavesock.recv_into( + self.__buff_block, + min(length, self.__buff_size), + ) + if count == 0: + self.__sockerr.set() + raise IOError("read error on network") + buffer += self.__buff_block[:count] + length -= count + + return len(buffer) + def readpictory(self) -> bytes: """ Ruft die piCtory Konfiguration ab. diff --git a/setup.py b/setup.py index 89e4ece..e5938c4 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ setup( license="LGPLv3", name="revpimodio2", - version="2.5.0", + version="2.5.1", packages=["revpimodio2"], python_requires="~=3.2",