88 lines
2.9 KiB
GDScript
88 lines
2.9 KiB
GDScript
extends Node
|
|
|
|
## Pymodbus Exceptions. Custom exceptions to be used in the Modbus code.
|
|
|
|
|
|
## Base modbus exception
|
|
class ModbusException:
|
|
var string: String = ''
|
|
## Initialize the exception.
|
|
## [param s] The message to append to the error
|
|
func _init(s: String): string = s
|
|
func _to_string(): return '<ModbusException>: %s' % string
|
|
func isError(): return true
|
|
func raise(): push_error(string)
|
|
|
|
|
|
### Error resulting from data i/o
|
|
class ModbusIOException extends ModbusException:
|
|
var fcode
|
|
var message
|
|
## Initialize the exception
|
|
## [param s] The message to append to the error
|
|
func _init(s: String = '', function_code=null):
|
|
fcode = function_code
|
|
message = '[Input/Output] %s' % s
|
|
ModbusException.new(message).raise()
|
|
|
|
|
|
## Error resulting from invalid parameter
|
|
class ParameterException extends ModbusException:
|
|
## Initialize the exception
|
|
## [param s] The message to append to the error
|
|
func _init(s: String = ''):
|
|
var message = '[Invalid Parameter] %s' % s
|
|
ModbusException.new(message).raise()
|
|
|
|
|
|
## Error resulting from making a request to a slave
|
|
## that does not exist
|
|
class NoSuchSlaveException extends ModbusException:
|
|
## Initialize the exception.
|
|
## [param s] The message to append to the error
|
|
func _init(s: String = ''):
|
|
var message = '[No Such Slave] %s' % s
|
|
ModbusException.new(message).raise()
|
|
|
|
|
|
## Error resulting from not implemented function
|
|
class NotImplementedException extends ModbusException:
|
|
## Initialize the exception
|
|
## [param s]: The message to append to the error
|
|
func _init(s: String = ''):
|
|
var message = '[Not Implemented] %s' % s
|
|
ModbusException.new(message).raise()
|
|
|
|
## Error resulting from a bad connection
|
|
class ConnectionException extends ModbusException:
|
|
## Initialize the exception
|
|
## [param s] The message to append to the error
|
|
func _init(s: String = ''):
|
|
var message: String = '[Connection] %s' % s
|
|
ModbusException.new(message).raise()
|
|
|
|
|
|
## Error resulting from invalid response received or decoded
|
|
class InvalidMessageReceivedException extends ModbusException:
|
|
## Initialize the exception
|
|
## [param s] The message to append to the error
|
|
func _init(s: String = ''):
|
|
var message: String = '[Invalid Message] %s' % s
|
|
ModbusException.new(message).raise()
|
|
|
|
|
|
## Error resulting from failing to register a custom message request/response
|
|
class MessageRegisterException extends ModbusException:
|
|
func _init(s: String = ''):
|
|
var message: String = '[Error registering message] %s' % s
|
|
ModbusException.new(message).raise()
|
|
|
|
|
|
## Error resulting from modbus response timeout
|
|
class TimeOutException extends ModbusException:
|
|
## Initialize the exception
|
|
## [param s] The message to append to the error
|
|
func _init(s: String = ''):
|
|
var message: String = '[Timeout] %s' % s
|
|
ModbusException.new(message).raise()
|