canvel num when write bits

This commit is contained in:
pikastech 2022-09-19 14:35:05 +08:00
parent 69236b37e5
commit 608e2c7065
2 changed files with 8 additions and 8 deletions

View File

@ -3,16 +3,16 @@ import _modbus
class ModBus(_modbus._ModBus): class ModBus(_modbus._ModBus):
def serializeWriteBits(self, addr: int, nb: int, src: list) -> bytes: def serializeWriteBits(self, addr: int, src: list) -> bytes:
lenth = super().serializeWriteBits(addr, nb, bytes(src)) lenth = super().serializeWriteBits(addr, len(list), bytes(src))
return self.sendBuff[0:lenth] return self.sendBuff[0:lenth]
def serializeWriteRegisters(self, addr: int, nb: int, src: list) -> bytes: def serializeWriteRegisters(self, addr: int, src: list) -> bytes:
_src = bytes(2 * len(src)) _src = bytes(2 * len(src))
for i in range(len(src)): for i in range(len(src)):
_src[2 * i] = src[i] % 256 _src[2 * i] = src[i] % 256
_src[2 * i + 1] = src[i] // 256 _src[2 * i + 1] = src[i] // 256
lenth = super().serializeWriteRegisters(addr, nb, _src) lenth = super().serializeWriteRegisters(addr, len(src), _src)
return self.sendBuff[0:lenth] return self.sendBuff[0:lenth]
def serializeReadBits(self, addr: int, nb: int) -> bytes: def serializeReadBits(self, addr: int, nb: int) -> bytes:

View File

@ -3,16 +3,16 @@ import _modbus
class ModBus(_modbus._ModBus): class ModBus(_modbus._ModBus):
def serializeWriteBits(self, addr: int, nb: int, src: list) -> bytes: def serializeWriteBits(self, addr: int, src: list) -> bytes:
lenth = super().serializeWriteBits(addr, nb, bytes(src)) lenth = super().serializeWriteBits(addr, len(list), bytes(src))
return self.sendBuff[0:lenth] return self.sendBuff[0:lenth]
def serializeWriteRegisters(self, addr: int, nb: int, src: list) -> bytes: def serializeWriteRegisters(self, addr: int, src: list) -> bytes:
_src = bytes(2 * len(src)) _src = bytes(2 * len(src))
for i in range(len(src)): for i in range(len(src)):
_src[2 * i] = src[i] % 256 _src[2 * i] = src[i] % 256
_src[2 * i + 1] = src[i] // 256 _src[2 * i + 1] = src[i] // 256
lenth = super().serializeWriteRegisters(addr, nb, _src) lenth = super().serializeWriteRegisters(addr, len(src), _src)
return self.sendBuff[0:lenth] return self.sendBuff[0:lenth]
def serializeReadBits(self, addr: int, nb: int) -> bytes: def serializeReadBits(self, addr: int, nb: int) -> bytes: