input and discrete
This commit is contained in:
parent
690f0f3cf5
commit
870f01e076
24
api.py
24
api.py
@ -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)
|
||||
|
46
openapi.yaml
46
openapi.yaml
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user