input and discrete

This commit is contained in:
Wolfgang Hottgenroth 2021-08-20 13:17:02 +02:00
parent 690f0f3cf5
commit 870f01e076
Signed by: wn
GPG Key ID: E49AF3B9EF6DD469
2 changed files with 70 additions and 0 deletions

24
api.py
View File

@ -85,3 +85,27 @@ def writeCoil(client, address, **args):
raise werkzeug.exceptions.BadRequest("{}: {}".format(e.__class__.__name__, str(e)))
finally:
close(client)
def readDiscreteRegister(client, address):
try:
conn = connect(client)
res = conn.read_discrete_inputs(address)
if isinstance(res, ModbusIOException):
raise ConnectionException()
return int(res.bits[0])
except Exception as e:
raise werkzeug.exceptions.BadRequest("{}: {}".format(e.__class__.__name__, str(e)))
finally:
close(client)
def readInputRegister(client, address):
try:
conn = connect(client)
res = conn.read_input_registers(address)
if isinstance(res, ModbusIOException):
raise ConnectionException()
return res.registers
except Exception as e:
raise werkzeug.exceptions.BadRequest("{}: {}".format(e.__class__.__name__, str(e)))
finally:
close(client)

View File

@ -80,6 +80,52 @@ paths:
'application/json':
schema:
type: number
/action/discrete/{client}/{address}:
get:
tags: [ "Action" ]
summary: Return a discrete input of client
operationId: api.readDiscreteRegister
parameters:
- name: client
in: path
required: true
schema:
type: string
- name: address
in: path
required: true
schema:
type: integer
responses:
'200':
description: Status of the discrete input register
content:
'application/json':
schema:
type: integer
/action/input/{client}/{address}:
get:
tags: [ "Action" ]
summary: Return an input of client
operationId: api.readInputRegister
parameters:
- name: client
in: path
required: true
schema:
type: string
- name: address
in: path
required: true
schema:
type: integer
responses:
'200':
description: Status of the input register
content:
'application/json':
schema:
type: integer
components: