mirror of
https://github.com/thiagoralves/OpenPLC_v3.git
synced 2026-08-20 23:59:16 +08:00
Added ability to write to coils on monitoring
This commit is contained in:
@@ -122,6 +122,17 @@ def modbus_monitor():
|
||||
|
||||
if (monitor_active == True):
|
||||
threading.Timer(0.5, modbus_monitor).start()
|
||||
|
||||
def write_value(point_address, point_value):
|
||||
global mb_client
|
||||
|
||||
# COILS
|
||||
if (point_address.find('QX')) > 0:
|
||||
mb_address = point_address.split('%QX')[1].split('.')
|
||||
if (len(mb_address) < 2):
|
||||
result = mb_client.write_coil(int(mb_address[0])*8, int(point_value))
|
||||
else:
|
||||
result = mb_client.write_coil(int(mb_address[0])*8 + int(mb_address[1]), int(point_value))
|
||||
|
||||
def start_monitor(modbus_port_cfg):
|
||||
global monitor_active
|
||||
|
||||
+27
-5
@@ -741,10 +741,6 @@ monitoring_head = """
|
||||
background-color: #eeeeee;
|
||||
}
|
||||
|
||||
tr:hover {
|
||||
cursor: hand;background-color: slategray;
|
||||
}
|
||||
|
||||
label {
|
||||
font-family: arial, sans-serif;
|
||||
}
|
||||
@@ -802,6 +798,32 @@ monitoring_head = """
|
||||
align-items: stretch;
|
||||
}
|
||||
}
|
||||
|
||||
.write-button
|
||||
{
|
||||
display: inline-block;
|
||||
width: 50px;
|
||||
height: 30px;
|
||||
margin-right: 5px;
|
||||
padding: 0;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
border: 1px solid #000000;
|
||||
}
|
||||
.write-button:last-child
|
||||
{
|
||||
margin-right: 0;
|
||||
}
|
||||
.write-button.true
|
||||
{
|
||||
background-color: #2366fc;
|
||||
color: #ffffff;
|
||||
}
|
||||
.write-button.false
|
||||
{
|
||||
background-color: #ffffff;
|
||||
color: #000000;
|
||||
}
|
||||
</style>
|
||||
<body onload='loadData()'>"""
|
||||
|
||||
@@ -814,7 +836,7 @@ monitoring_tail = """
|
||||
|
||||
<script>
|
||||
var req;
|
||||
var refresh_rate = 100;
|
||||
var refresh_rate = 500;
|
||||
|
||||
function loadData()
|
||||
{
|
||||
|
||||
+24
-7
@@ -1414,7 +1414,7 @@ def monitoring():
|
||||
<h2>Monitoring</h2>
|
||||
<form class="form-inline">
|
||||
<label for="refresh_rate">Refresh Rate (ms):</label>
|
||||
<input type="text" id="refresh_rate" value="100" name="refresh_rate">
|
||||
<input type="text" id="refresh_rate" value="500" name="refresh_rate">
|
||||
<button type="button" onclick="updateRefreshRate()">Update</button>
|
||||
</form>
|
||||
<br>
|
||||
@@ -1422,7 +1422,7 @@ def monitoring():
|
||||
<table>
|
||||
<col width="50"><col width="10"><col width="10"><col width="10"><col width="100">
|
||||
<tr style='background-color: white'>
|
||||
<th>Point Name</th><th>Type</th><th>Location</th><th>Forced</th><th>Value</th>
|
||||
<th>Point Name</th><th>Type</th><th>Location</th><th>Write</th><th>Value</th>
|
||||
</tr>"""
|
||||
|
||||
if (openplc_runtime.status() == "Running"):
|
||||
@@ -1457,8 +1457,12 @@ def monitoring():
|
||||
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) + '\'">'
|
||||
return_str += '<td>' + debug_data.name + '</td><td>' + debug_data.type + '</td><td>' + debug_data.location + '</td><td>' + debug_data.forced + '</td><td valign="middle">'
|
||||
return_str += '<tr style="height:60px">' # onclick="document.location=\'point-info?table_id=' + str(data_index) + '\'">'
|
||||
return_str += '<td>' + debug_data.name + '</td><td>' + debug_data.type + '</td><td>' + debug_data.location + '</td><td>'
|
||||
if (debug_data.location.find('QX') != -1):
|
||||
return_str += '<button class="write-button true" onclick="fetch(\'/point-write?value=1&address=' + str(debug_data.location) + '\')">true</button>'
|
||||
return_str += '<button class="write-button false" onclick="fetch(\'/point-write?value=0&address=' + str(debug_data.location) + '\')">false</button>'
|
||||
return_str += '</td><td valign="middle">'
|
||||
if (debug_data.type == 'BOOL'):
|
||||
if (debug_data.value == 0):
|
||||
return_str += '<img src="/static/bool_false.png" alt="bool_false" style="width:40px;height:40px;vertical-align:middle; margin-right:10px">FALSE</td>'
|
||||
@@ -1520,7 +1524,7 @@ def monitor_update():
|
||||
<table>
|
||||
<col width="50"><col width="10"><col width="10"><col width="10"><col width="100">
|
||||
<tr style='background-color: white'>
|
||||
<th>Point Name</th><th>Type</th><th>Location</th><th>Forced</th><th>Value</th>
|
||||
<th>Point Name</th><th>Type</th><th>Location</th><th>Write</th><th>Value</th>
|
||||
</tr>"""
|
||||
|
||||
#if (openplc_runtime.status() == "Running"):
|
||||
@@ -1529,8 +1533,12 @@ def monitor_update():
|
||||
monitor.start_monitor(int(mb_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) + '\'">'
|
||||
return_str += '<td>' + debug_data.name + '</td><td>' + debug_data.type + '</td><td>' + debug_data.location + '</td><td>' + debug_data.forced + '</td><td valign="middle">'
|
||||
return_str += '<tr style="height:60px">' # onclick="document.location=\'point-info?table_id=' + str(data_index) + '\'">'
|
||||
return_str += '<td>' + debug_data.name + '</td><td>' + debug_data.type + '</td><td>' + debug_data.location + '</td><td>'
|
||||
if (debug_data.location.find('QX') != -1):
|
||||
return_str += '<button class="write-button true" onclick="fetch(\'/point-write?value=1&address=' + str(debug_data.location) + '\')">true</button>'
|
||||
return_str += '<button class="write-button false" onclick="fetch(\'/point-write?value=0&address=' + str(debug_data.location) + '\')">false</button>'
|
||||
return_str += '</td><td valign="middle">'
|
||||
if (debug_data.type == 'BOOL'):
|
||||
if (debug_data.value == 0):
|
||||
return_str += '<img src="/static/bool_false.png" alt="bool_false" style="width:40px;height:40px;vertical-align:middle; margin-right:10px">FALSE</td>'
|
||||
@@ -1555,6 +1563,15 @@ def monitor_update():
|
||||
|
||||
return return_str
|
||||
|
||||
@app.route('/point-write', methods=['GET', 'POST'])
|
||||
def point_write():
|
||||
if (flask_login.current_user.is_authenticated == False):
|
||||
return flask.redirect(flask.url_for('login'))
|
||||
else:
|
||||
point_value = flask.request.args.get('value')
|
||||
point_address = flask.request.args.get('address')
|
||||
monitor.write_value(point_address, int(point_value))
|
||||
return ''
|
||||
|
||||
@app.route('/point-info', methods=['GET', 'POST'])
|
||||
def point_info():
|
||||
|
||||
Reference in New Issue
Block a user