Monitoring update: Added support for %MD and %ML

This commit is contained in:
Thiago Alves 2019-08-29 12:04:04 -07:00 committed by GitHub
parent 8cd28fcd23
commit f6b8de465d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 126 additions and 18 deletions

View File

@ -1,4 +1,5 @@
import time, threading
from struct import *
from pymodbus.client.sync import ModbusTcpClient
class debug_var():
@ -72,11 +73,41 @@ def modbus_monitor():
elif (debug_data.location.find('MD')) > 0:
#Reading Double Memory
print('hi')
mb_address = debug_data.location.split('%MD')[1]
result = mb_client.read_holding_registers((int(mb_address)*2) + 2048, 2)
if (debug_data.type == 'SINT') or (debug_data.type == 'INT') or (debug_data.type == 'DINT'):
#signed integer
float_pack = pack('>HH', result.registers[0], result.registers[1])
debug_data.value = unpack('>i', float_pack)[0]
if (debug_data.type == 'USINT') or (debug_data.type == 'UINT') or (debug_data.type == 'UDINT'):
#unsigned integer
float_pack = pack('>HH', result.registers[0], result.registers[1])
debug_data.value = unpack('>I', float_pack)[0]
if (debug_data.type == 'REAL'):
#32-bit float
float_pack = pack('>HH', result.registers[0], result.registers[1])
debug_data.value = unpack('>f', float_pack)[0]
elif (debug_data.location.find('ML')) > 0:
#Reading Long Memory
print('hi')
mb_address = debug_data.location.split('%ML')[1]
result = mb_client.read_holding_registers((int(mb_address)*4) + 4096, 4)
if (debug_data.type == 'SINT') or (debug_data.type == 'INT') or (debug_data.type == 'DINT') or (debug_data.type == 'LINT'):
#signed integer
float_pack = pack('>HHHH', result.registers[0], result.registers[1], result.registers[2], result.registers[3])
debug_data.value = unpack('>q', float_pack)[0]
if (debug_data.type == 'USINT') or (debug_data.type == 'UINT') or (debug_data.type == 'UDINT') or (debug_data.type == 'ULINT'):
#unsigned integer
float_pack = pack('>HHHH', result.registers[0], result.registers[1], result.registers[2], result.registers[3])
debug_data.value = unpack('>Q', float_pack)[0]
if (debug_data.type == 'REAL') or (debug_data.type == 'LREAL'):
#64-bit float
float_pack = pack('>HHHH', result.registers[0], result.registers[1], result.registers[2], result.registers[3])
debug_data.value = unpack('>d', float_pack)[0]
if (monitor_active == True):

View File

@ -748,16 +748,59 @@ monitoring_head = """
font-family: arial, sans-serif;
}
input[type=text], input[type=password], select, textarea {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
.form-inline
{
display: flex;
flex-flow: row wrap;
align-items: center;
}
.form-inline label
{
margin: 5px 10px 5px 0;
width: 130px;
}
.form-inline input
{
vertical-align: middle;
margin: 5px 10px 5px 0;
padding: 10px;
width: calc(100% - 250px);
background-color: #fff;
border: 1px solid #ddd;
}
.form-inline button
{
padding: 10px 20px;
background-color: #E02222;
width: 100px;
border: 1px solid #1F1F1F;
color: white;
cursor: pointer;
font-size: 14px;
font-family: "Roboto", sans-serif;
}
}
.form-inline button:hover
{
background-color: #B51A1A;
}
@media (max-width: 800px)
{
.form-inline input
{
margin: 10px 0;
}
.form-inline
{
flex-direction: column;
align-items: stretch;
}
}
</style>
<body onload='loadData()'>"""
@ -772,6 +815,7 @@ monitoring_tail = """
<script>
var req;
var refresh_rate = 100;
function loadData()
{
@ -802,6 +846,18 @@ monitoring_tail = """
req.send(null);
}
function updateRefreshRate()
{
html_refresh_text = document.getElementById('refresh_rate');
refresh_rate = parseInt(html_refresh_text.value);
if (refresh_rate < 100)
{
refresh_rate = 100
}
html_refresh_text.value = refresh_rate;
}
function processReqChange()
{
//If req shows 'complete'
@ -816,11 +872,10 @@ monitoring_tail = """
mon_table.innerHTML = req.responseText;
//Start a new update timer
timeoutID = setTimeout('loadData()', 100);
timeoutID = setTimeout('loadData()', refresh_rate);
}
}
}
</script>
</html>"""
@ -1999,4 +2054,4 @@ edit_devices_script = """
var aorstart = document.getElementById("aor_start");
var aorsize = document.getElementById("aor_size");
var aowstart = document.getElementById("aow_start");
var aowsize = document.getElementById("aow_size");"""
var aowsize = document.getElementById("aow_size");"""

View File

@ -11,6 +11,7 @@ import pages
import openplc
import monitoring as monitor
import sys
import ctypes
import flask
import flask_login
@ -1311,7 +1312,12 @@ def monitoring():
<div style="w3-container">
<br>
<h2>Monitoring</h2>
<p>The table below displays a list of the OpenPLC points used by the currently running program. By clicking in one of the listed points it is possible to see more information about it and also to force it to be a different value.</p>
<form class="form-inline">
<label for="refresh_rate">Refresh Rate (ms):</label>
<input type="text" id="refresh_rate" value="100" name="refresh_rate">
<button type="button" onclick="updateRefreshRate()">Update</button>
</form>
<br>
<div id='monitor_table'>
<table>
<col width="50"><col width="10"><col width="10"><col width="10"><col width="100">
@ -1330,9 +1336,17 @@ def monitoring():
return_str += '<img src="/static/bool_false.png" alt="bool_false" style="width:40px;height:40px;vertical-align:middle; margin-right:10px">FALSE</td>'
else:
return_str += '<img src="/static/bool_true.png" alt="bool_true" style="width:40px;height:40px;vertical-align:middle; margin-right:10px">TRUE</td>'
else:
elif (debug_data.type == 'UINT'):
percentage = (debug_data.value*100)/65535
return_str += '<div class="w3-grey w3-round" style="height:40px"><div class="w3-container w3-blue w3-round" style="height:40px;width:' + str(int(percentage)) + '%"><p style="margin-top:10px">' + str(debug_data.value) + '</p></div></div></td>'
elif (debug_data.type == 'INT'):
percentage = ((debug_data.value + 32768)*100)/65535
debug_data.value = ctypes.c_short(debug_data.value).value
return_str += '<div class="w3-grey w3-round" style="height:40px"><div class="w3-container w3-blue w3-round" style="height:40px;width:' + str(int(percentage)) + '%"><p style="margin-top:10px">' + str(debug_data.value) + '</p></div></div></td>'
elif (debug_data.type == 'REAL') or (debug_data.type == 'LREAL'):
return_str += "{:10.4f}".format(debug_data.value)
else:
return_str += str(debug_data.value)
return_str += '</tr>'
data_index += 1
return_str += pages.monitoring_tail
@ -1374,9 +1388,17 @@ def monitor_update():
return_str += '<img src="/static/bool_false.png" alt="bool_false" style="width:40px;height:40px;vertical-align:middle; margin-right:10px">FALSE</td>'
else:
return_str += '<img src="/static/bool_true.png" alt="bool_true" style="width:40px;height:40px;vertical-align:middle; margin-right:10px">TRUE</td>'
else:
elif (debug_data.type == 'UINT'):
percentage = (debug_data.value*100)/65535
return_str += '<div class="w3-grey w3-round" style="height:40px"><div class="w3-container w3-blue w3-round" style="height:40px;width:' + str(int(percentage)) + '%"><p style="margin-top:10px">' + str(debug_data.value) + '</p></div></div></td>'
elif (debug_data.type == 'INT'):
percentage = ((debug_data.value + 32768)*100)/65535
debug_data.value = ctypes.c_short(debug_data.value).value
return_str += '<div class="w3-grey w3-round" style="height:40px"><div class="w3-container w3-blue w3-round" style="height:40px;width:' + str(int(percentage)) + '%"><p style="margin-top:10px">' + str(debug_data.value) + '</p></div></div></td>'
elif (debug_data.type == 'REAL') or (debug_data.type == 'LREAL'):
return_str += "{:10.4f}".format(debug_data.value)
else:
return_str += str(debug_data.value)
return_str += '</tr>'
data_index += 1