Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
825075686a
|
|||
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:
|
||||
|
@ -1,6 +1,6 @@
|
||||
[uwsgi]
|
||||
http = :5000
|
||||
wsgi-file = server.py
|
||||
processes = 4
|
||||
processes = 16
|
||||
stats = :9191
|
||||
|
||||
|
Reference in New Issue
Block a user