mirror of
https://github.com/JoelBender/modpypes
synced 2025-10-19 22:08:20 +08:00
Python3 syntax update
This commit is contained in:
parent
2237cd06ed
commit
8bb6f2473b
|
|
@ -72,10 +72,10 @@ class _Struct:
|
||||||
registerLength = None
|
registerLength = None
|
||||||
|
|
||||||
def pack(self, value):
|
def pack(self, value):
|
||||||
raise NotImplementedError
|
raise NotImplementedError("pack is not implemented in %s" % (self.__class__.__name__,))
|
||||||
|
|
||||||
def unpack(self, registers):
|
def unpack(self, registers):
|
||||||
raise NotImplementedError
|
raise NotImplementedError("unpack is not implemented in %s" % (self.__class__.__name__,))
|
||||||
|
|
||||||
@class_debugging
|
@class_debugging
|
||||||
class Byte(_Struct):
|
class Byte(_Struct):
|
||||||
|
|
@ -209,7 +209,7 @@ class ROCReal(_Struct):
|
||||||
|
|
||||||
def pack(self, value):
|
def pack(self, value):
|
||||||
if _debug: ROCReal._debug("pack %r", value)
|
if _debug: ROCReal._debug("pack %r", value)
|
||||||
raise NotImplementedError("packing is not supported")
|
raise NotImplementedError("packing ROCReal is not supported")
|
||||||
|
|
||||||
def unpack(self, registers):
|
def unpack(self, registers):
|
||||||
if _debug: ROCReal._debug("unpack %r", registers)
|
if _debug: ROCReal._debug("unpack %r", registers)
|
||||||
|
|
|
||||||
|
|
@ -60,14 +60,14 @@ class ConsoleServer(ConsoleCmd, Client):
|
||||||
try:
|
try:
|
||||||
fn = getattr(self, "do_" + req.__class__.__name__)
|
fn = getattr(self, "do_" + req.__class__.__name__)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise ModbusException, ExceptionResponse.ILLEGAL_FUNCTION
|
raise ModbusException(ExceptionResponse.ILLEGAL_FUNCTION)
|
||||||
|
|
||||||
# try to execute it
|
# try to execute it
|
||||||
resp = fn(req)
|
resp = fn(req)
|
||||||
|
|
||||||
except ModbusException, e:
|
except ModbusException as err:
|
||||||
# create an exception response
|
# create an exception response
|
||||||
resp = ExceptionResponse(req.mpduFunctionCode, e.errCode)
|
resp = ExceptionResponse(req.mpduFunctionCode, err.errCode)
|
||||||
|
|
||||||
# match the transaction information
|
# match the transaction information
|
||||||
resp.pduDestination = req.pduSource
|
resp.pduDestination = req.pduSource
|
||||||
|
|
@ -100,7 +100,7 @@ class ConsoleServer(ConsoleCmd, Client):
|
||||||
def do_ReadCoilsRequest(self, req):
|
def do_ReadCoilsRequest(self, req):
|
||||||
ConsoleServer._debug('do_ReadCoilsRequest %r', req)
|
ConsoleServer._debug('do_ReadCoilsRequest %r', req)
|
||||||
if (req.address + req.count) > len(self.coils):
|
if (req.address + req.count) > len(self.coils):
|
||||||
raise ModbusException, ExceptionResponse.ILLEGAL_DATA_ADDRESS
|
raise ModbusException(ExceptionResponse.ILLEGAL_DATA_ADDRESS)
|
||||||
|
|
||||||
self.pull_coils(req.address, req.count)
|
self.pull_coils(req.address, req.count)
|
||||||
|
|
||||||
|
|
@ -109,7 +109,7 @@ class ConsoleServer(ConsoleCmd, Client):
|
||||||
def do_WriteSingleCoilRequest(self, req):
|
def do_WriteSingleCoilRequest(self, req):
|
||||||
ConsoleServer._debug('do_WriteSingleCoilRequest %r', req)
|
ConsoleServer._debug('do_WriteSingleCoilRequest %r', req)
|
||||||
if req.address > len(self.coils):
|
if req.address > len(self.coils):
|
||||||
raise ModbusException, ExceptionResponse.ILLEGAL_DATA_ADDRESS
|
raise ModbusException(ExceptionResponse.ILLEGAL_DATA_ADDRESS)
|
||||||
|
|
||||||
# check the value and save it
|
# check the value and save it
|
||||||
if (req.value == 0x00):
|
if (req.value == 0x00):
|
||||||
|
|
@ -117,7 +117,7 @@ class ConsoleServer(ConsoleCmd, Client):
|
||||||
elif (req.value == 0xFF):
|
elif (req.value == 0xFF):
|
||||||
self.coils[req.address] = 1
|
self.coils[req.address] = 1
|
||||||
else:
|
else:
|
||||||
raise ModbusException, ExceptionResponse.ILLEGAL_DATA_VALUE
|
raise ModbusException(ExceptionResponse.ILLEGAL_DATA_VALUE)
|
||||||
|
|
||||||
self.push_coils(req.address, 1)
|
self.push_coils(req.address, 1)
|
||||||
|
|
||||||
|
|
@ -129,7 +129,7 @@ class ConsoleServer(ConsoleCmd, Client):
|
||||||
def do_ReadDescreteInputsRequest(self, req):
|
def do_ReadDescreteInputsRequest(self, req):
|
||||||
ConsoleServer._debug('do_ReadDescreteInputsRequest %r', req)
|
ConsoleServer._debug('do_ReadDescreteInputsRequest %r', req)
|
||||||
if (req.address + req.count) > len(self.coils):
|
if (req.address + req.count) > len(self.coils):
|
||||||
raise ModbusException, ExceptionResponse.ILLEGAL_DATA_ADDRESS
|
raise ModbusException(ExceptionResponse.ILLEGAL_DATA_ADDRESS)
|
||||||
|
|
||||||
self.pull_coils(req.address, req.count)
|
self.pull_coils(req.address, req.count)
|
||||||
|
|
||||||
|
|
@ -140,7 +140,7 @@ class ConsoleServer(ConsoleCmd, Client):
|
||||||
def do_ReadMultipleRegistersRequest(self, req):
|
def do_ReadMultipleRegistersRequest(self, req):
|
||||||
ConsoleServer._debug('do_ReadMultipleRegistersRequest %r', req)
|
ConsoleServer._debug('do_ReadMultipleRegistersRequest %r', req)
|
||||||
if (req.address + req.count) > len(self.registers):
|
if (req.address + req.count) > len(self.registers):
|
||||||
raise ModbusException, ExceptionResponse.ILLEGAL_DATA_ADDRESS
|
raise ModbusException(ExceptionResponse.ILLEGAL_DATA_ADDRESS)
|
||||||
|
|
||||||
self.pull_registers(req.address, req.count)
|
self.pull_registers(req.address, req.count)
|
||||||
|
|
||||||
|
|
@ -149,7 +149,7 @@ class ConsoleServer(ConsoleCmd, Client):
|
||||||
def do_WriteSingleRegisterRequest(self, req):
|
def do_WriteSingleRegisterRequest(self, req):
|
||||||
ConsoleServer._debug('do_WriteSingleRegisterRequest %r', req)
|
ConsoleServer._debug('do_WriteSingleRegisterRequest %r', req)
|
||||||
if req.address > len(self.registers):
|
if req.address > len(self.registers):
|
||||||
raise ModbusException, ExceptionResponse.ILLEGAL_DATA_ADDRESS
|
raise ModbusException(ExceptionResponse.ILLEGAL_DATA_ADDRESS)
|
||||||
|
|
||||||
# save the value
|
# save the value
|
||||||
self.registers[req.address] = req.value
|
self.registers[req.address] = req.value
|
||||||
|
|
@ -162,7 +162,7 @@ class ConsoleServer(ConsoleCmd, Client):
|
||||||
def do_WriteMultipleRegistersRequest(self, req):
|
def do_WriteMultipleRegistersRequest(self, req):
|
||||||
ConsoleServer._debug('do_WriteMultipleRegistersRequest %r', req)
|
ConsoleServer._debug('do_WriteMultipleRegistersRequest %r', req)
|
||||||
if (req.address + req.count) > len(self.registers):
|
if (req.address + req.count) > len(self.registers):
|
||||||
raise ModbusException, ExceptionResponse.ILLEGAL_DATA_ADDRESS
|
raise ModbusException(ExceptionResponse.ILLEGAL_DATA_ADDRESS)
|
||||||
|
|
||||||
# save the values
|
# save the values
|
||||||
for i in range(req.count):
|
for i in range(req.count):
|
||||||
|
|
@ -177,7 +177,7 @@ class ConsoleServer(ConsoleCmd, Client):
|
||||||
def do_ReadInputRegistersRequest(self, req):
|
def do_ReadInputRegistersRequest(self, req):
|
||||||
ConsoleServer._debug('do_ReadInputRegistersRequest %r', req)
|
ConsoleServer._debug('do_ReadInputRegistersRequest %r', req)
|
||||||
if (req.address + req.count) > len(self.registers):
|
if (req.address + req.count) > len(self.registers):
|
||||||
raise ModbusException, ExceptionResponse.ILLEGAL_DATA_ADDRESS
|
raise ModbusException(ExceptionResponse.ILLEGAL_DATA_ADDRESS)
|
||||||
|
|
||||||
self.pull_registers(req.address, req.count)
|
self.pull_registers(req.address, req.count)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user