exceptions.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. class ModbusError(Exception):
  4. """Exception raised when the modbus slave returns an error"""
  5. def __init__(self, exception_code, value=""):
  6. """constructor: set the exception code returned by the slave"""
  7. if not value:
  8. value = "Modbus Error: Exception code = %d" % (exception_code)
  9. Exception.__init__(self, value)
  10. self._exception_code = exception_code
  11. def get_exception_code(self):
  12. """return the exception code returned by the slave (see defines)"""
  13. return self._exception_code
  14. class ModbusFunctionNotSupportedError(Exception):
  15. """
  16. Exception raised when calling a modbus function not supported by modbus_tk
  17. """
  18. pass
  19. class DuplicatedKeyError(Exception):
  20. """
  21. Exception raised when trying to add an object with a key that is already
  22. used for another object
  23. """
  24. pass
  25. class MissingKeyError(Exception):
  26. """
  27. Exception raised when trying to get an object with a key that doesn't exist
  28. """
  29. pass
  30. class InvalidModbusBlockError(Exception):
  31. """Exception raised when a modbus block is not valid"""
  32. pass
  33. class InvalidArgumentError(Exception):
  34. """
  35. Exception raised when one argument of a function doesn't meet
  36. what is expected
  37. """
  38. pass
  39. class OverlapModbusBlockError(Exception):
  40. """
  41. Exception raised when adding modbus block on a memory address
  42. range already in use
  43. """
  44. pass
  45. class OutOfModbusBlockError(Exception):
  46. """Exception raised when accessing out of a modbus block"""
  47. pass
  48. class ModbusInvalidResponseError(Exception):
  49. """
  50. Exception raised when the response sent by the slave doesn't fit
  51. with the expected format
  52. """
  53. pass
  54. class ModbusInvalidRequestError(Exception):
  55. """
  56. Exception raised when the request by the master doesn't fit
  57. with the expected format
  58. """
  59. pass