Fix monitoring issues

- Improved located variables parsing to avoid parsing commented lines in code
 - Fixed server 502 error when modbus service is not running or running on a port different than 502
This commit is contained in:
Thiago Alves 2020-03-06 09:52:08 -05:00 committed by GitHub
parent 2d535b8dca
commit f7e9b79fea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 27 deletions

View File

@ -20,7 +20,7 @@ def parse_st(st_file):
st_program = open(filepath, 'r')
for line in st_program.readlines():
if line.find(' AT ') > 0:
if line.find(' AT ') > 0 and line.find('%') > 0 and line.find('(*') < 0 and line.find('*)') < 0:
debug_data = debug_var()
tmp = line.strip().split(' ')
debug_data.name = tmp[0]
@ -123,13 +123,13 @@ def modbus_monitor():
if (monitor_active == True):
threading.Timer(0.5, modbus_monitor).start()
def start_monitor():
def start_monitor(modbus_port_cfg):
global monitor_active
global mb_client
if (monitor_active != True):
monitor_active = True
mb_client = ModbusTcpClient('127.0.0.1')
mb_client = ModbusTcpClient('127.0.0.1', port=modbus_port_cfg)
modbus_monitor()

View File

@ -1413,7 +1413,35 @@ def monitoring():
</tr>"""
if (openplc_runtime.status() == "Running"):
monitor.start_monitor()
#Check Modbus Server status
modbus_enabled = False
modbus_port_cfg = 502
database = "openplc.db"
conn = create_connection(database)
if (conn != None):
try:
print("Openning database")
cur = conn.cursor()
cur.execute("SELECT * FROM Settings")
rows = cur.fetchall()
cur.close()
conn.close()
for row in rows:
if (row[0] == "Modbus_port"):
if (row[1] != "disabled"):
modbus_enabled = True
modbus_port_cfg = int(row[1])
else:
modbus_enabled = False
except Error as e:
return "error connecting to the database" + str(e)
else:
return "Error opening DB"
if modbus_enabled == True:
monitor.start_monitor(modbus_port_cfg)
data_index = 0
for debug_data in monitor.debug_vars:
return_str += '<tr style="height:60px" onclick="document.location=\'point-info?table_id=' + str(data_index) + '\'">'
@ -1438,6 +1466,21 @@ def monitoring():
data_index += 1
return_str += pages.monitoring_tail
#Modbus Server is not enabled
else:
return_str += """
</table>
<br>
<br>
<h2>You must enable Modbus Server on Settings to be able to monitor your program!</h2>
</div>
</div>
</div>
</div>
</body>
</html>"""
#Runtime is not running
else:
return_str += """
</table>