Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cristi-badila/463a9b0fac7402d32f04c8acab764d7b to your computer and use it in GitHub Desktop.
Save cristi-badila/463a9b0fac7402d32f04c8acab764d7b to your computer and use it in GitHub Desktop.
Sample RtsModbusSerialClient from https://github.com/bashwork/pymodbus/issues/33
class RtsModbusSerialClient(ModbusSerialClient):
def _send(self, request):
''' Sends data on the underlying socket
:param request: The encoded request to send
:return: The number of bytes written
'''
if not self.socket:
raise ConnectionException(self.__str__())
if request:
self.socket.setRTS(True)
result = self.socket.write(request)
self.socket.setRTS(False)
return result
return 0
def _recv(self, size):
''' Reads data from the underlying descriptor
:param size: The number of bytes to read
:return: The bytes read
'''
if not self.socket:
raise ConnectionException(self.__str__())
self.socket.setRTS(False)
result = self.socket.read(size)
self.socket.setRTS(True)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment