exceptions.py 2.2 KB

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