Skip to content

Commit

Permalink
Add rockwell IO read
Browse files Browse the repository at this point in the history
  • Loading branch information
su600 committed Apr 15, 2020
1 parent 7ff1b2f commit 4a9bfb8
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 90 deletions.
157 changes: 90 additions & 67 deletions .idea/workspace.xml

Large diffs are not rendered by default.

32 changes: 24 additions & 8 deletions blueprints/rockwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,18 @@ def readten(tags_list):
ttt=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(aa)
for a in aa:
tagname.settingsend(a.TagName)
tagvalue.settingsend(a.Value)
tagname.append(a.TagName)
# 对于 IO 特殊处理 转换为0000/0000/0000/0000形式 todo IO长度不一定 暂定按16个 且形式不确定
if a.TagName == "Local:1:I.Data" or a.TagName == "Local:1:O.Data" :
if a.Value < 0:
a.Value = 65536 + a.Value
b = ('{:016b}'.format(a.Value))[::-1] #转二进制并 高位补零 IO逆序输出
b=list(b)
b.insert(4, '/')
b.insert(9, '/')
b.insert(14, '/')
a.Value = ''.join(b)
tagvalue.append(a.Value)
# 输出到前端页面
rockwelldata=dict(zip(tagname,tagvalue))
print(rockwelldata)
Expand All @@ -99,9 +109,15 @@ def rockwellreadexcel(file):
# data2 = pd.read_excel(file, usecols=[0], header=None) ##第一列 无表头 输出为DataFrame格式 带索引
data2 = pd.read_excel(file) ##输出为DataFrame格式 后续剔除未知类型
# data2=data2.dropna() ##剔除异常的nan
data2 = data2[data2['TagType'].isin(["BOOL"])] ##可以读取的类型 ["BOOL", "TIMER", "REAL"]
##剔除程序名和已知类型之外的数据
data2 = data2[data2['TagType'].isin(["BOOL", "REAL", "AB:Embedded_DiscreteIO:O:0","AB:Embedded_DiscreteIO:I:0"])]
##可以读取的类型 ["BOOL", "TIMER", "REAL","AB:Embedded_DiscreteIO:O:0","AB:Embedded_DiscreteIO:I:0"]
##剔除程序名,IO,和已知类型之外的数据
data2 = data2['TagName']
# print(data2)
# 添加IO变量
data2.replace("Local:1:I", "Local:1:I.Data", inplace=True)
data2.replace("Local:1:O", "Local:1:O.Data", inplace=True)

print(data2)
global taglist
taglist = data2.to_numpy().tolist() # 转数组 转列表
Expand All @@ -117,8 +133,8 @@ def rockwellscan():
devicename = []
devices = comm.Discover()
for device in devices.Value:
deviceip.settingsend(device.IPAddress)
devicename.settingsend(device.ProductName + ' ' + device.IPAddress)
deviceip.append(device.IPAddress)
devicename.append(device.ProductName + ' ' + device.IPAddress)
global rockwell_device_list
rockwell_device_list = dict(zip(devicename, deviceip)) # 创建设备字典 写入全局变量
scanresult="扫描到"+str(len(rockwell_device_list))+"台设备"
Expand Down Expand Up @@ -219,8 +235,8 @@ def rockwell_get_all_vars(): #
tagtype=[]
head=["TagName","TagType"]
for t in tags.Value:
tagname.settingsend(t.TagName)
tagtype.settingsend(t.DataType)
tagname.append(t.TagName)
tagtype.append(t.DataType)
taglist = pd.DataFrame({'tagname': tagname, 'tagtype': tagtype}) #采用Pandas格式化
# print(taglist)
tt = datetime.datetime.now().strftime('%Y-%m-%d %H-%M-%S') #时间标识符
Expand Down
65 changes: 59 additions & 6 deletions excelsubmit.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,66 @@
from flask import Flask, render_template,jsonify,request
from flask import Flask, render_template,jsonify,request,redirect
import time
import threading
import inspect
import ctypes

app = Flask(__name__)

@app.route("/demo", methods=["POST"])
#
# def _async_raise(tid, exctype):
# """raises the exception, performs cleanup if needed"""
# tid = ctypes.c_long(tid)
# if not inspect.isclass(exctype):
# exctype = type(exctype)
# res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
# if res == 0:
# raise ValueError("invalid thread id")
# elif res != 1:
# # """if it returns a number greater than one, you're in trouble,
# # and you should call it again with exc=NULL to revert the effect"""
# ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None)
# raise SystemError("PyThreadState_SetAsyncExc failed")
#
#
# def stop_thread(thread):
# _async_raise(thread.ident, SystemExit)
# @app.route("/", methods=["GET","POST"])
# def hh():
# if request.method == "POST":
# print("sssssssssssss")
# return redirect("a")
# else:
# while 1:
# pass
# return render_template("th.html")

@app.route("", methods=["GET","POST"])
def demo():
nick_name = request.form.get("nick_name")
print(nick_name)
return "ok"
def fun2():
i=0
while 1:
i+=1
time.sleep(1)
print(i)

def fun1():
# a=1
if request.method == "POST":
print("sssssssssssss")


t1 = threading.Thread(target=fun1, args=())
t2 = threading.Thread(target=fun2, args=())
t2.setDaemon(True)
t1.start()
t2.start()
# if request.method=="POST":
# stop_thread(myThread)
return render_template("th.html")

@app.route("/b", methods=["GET","POST"])
def a():
return "Stop"

if __name__ == "__main__":
app.run()
app.run()
2 changes: 1 addition & 1 deletion templates/rockwell.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

<div class="container-fluid" style="">
<label for="file">导入变量表</label>
<p>变量表格式 对于数组如何处理列出每个元素太浪费了 读取效率低下 Pylogix 0.6.2批量读取的数量上限之前是20个</p>
<!-- <p>变量表格式 对于数组如何处理列出每个元素太浪费了 读取效率低下 Pylogix 0.6.2批量读取的数量上限之前是20个</p> -->

<form method="POST" action="" enctype=multipart/form-data>
<div class="row">
Expand Down
25 changes: 25 additions & 0 deletions templates/th.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<html lang="en">
<head>
<title>Title</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>

<form class="form-group" style="margin: 50px;" method="POST">
<button type="submit" class="btn btn-primary">Submit</button>
</form>

<body>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions test/daeonnn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import threading
import time


def run():
time.sleep(2)
print('当前线程的名字是: ', threading.current_thread().name)
time.sleep(2)


if __name__ == '__main__':

start_time = time.time()

print('这是主线程:', threading.current_thread().name)
thread_list = []
for i in range(5):
t = threading.Thread(target=run)
thread_list.append(t)

for t in thread_list:
t.setDaemon(True)
t.start()

print('主线程结束了!', threading.current_thread().name)
print('一共用时:', time.time() - start_time)
16 changes: 16 additions & 0 deletions test/dataf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pandas as pd
import numpy as np

file="D:\Taglist 2020-03-27 15-59-12.xlsx"
data2 = pd.read_excel(file) ##输出为DataFrame格式 后续剔除未知类型
# data2=data2.dropna() ##剔除异常的nan
data2 = data2[data2['TagType'].isin(
["BOOL", "REAL","AB:Embedded_DiscreteIO:O:0","AB:Embedded_DiscreteIO:I:0"])] ##可以读取的类型 ["BOOL", "TIMER", "REAL","AB:Embedded_DiscreteIO:O:0","AB:Embedded_DiscreteIO:I:0"]
##剔除程序名和已知类型之外的数据
data2 = data2['TagName']
print(data2)

data2.replace("Local:1:I","Local:1:I.Data",inplace=True)
data2.replace("Local:1:O","Local:1:O.Data",inplace=True)

print(data2)
26 changes: 18 additions & 8 deletions test/th.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@
import time
import threading


def fun():
print("start fun")
time.sleep(2)
print("end fun")
for i in range(5):
# print("start fun")
time.sleep(1)
print("fun1")

def fun2():
while 1:
time.sleep(1)
print("end fun2")

def main():
print("main thread")
# print("main thread")
t1 = threading.Thread(target=fun,args=())
t1.setDaemon(True)
t2 = threading.Thread(target=fun2, args=())
# t1.setDaemon(False)
t2.setDaemon(True)
t1.start()
time.sleep(1)
print("main thread end")
t2.start()
# time.sleep(2)
# t1.join()
# t2.join()
# print("main thread end")

if __name__ == '__main__':
main()

0 comments on commit 4a9bfb8

Please sign in to comment.