Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
董杰
/
induction_shelf
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 4477659f
由
刘韬
编写于
2022-04-14 14:47:00 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1
1 个父辈
7a240e95
隐藏空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
177 行增加
和
86 行删除
.gitignore
induction_shelf.zip
smartshelf/app/__init__.py
smartshelf/app/induction_admin.py
smartshelf/app/induction_config.py
smartshelf/app/induction_post.py
smartshelf/app/state/state.txt
smartshelf/app/templates/induction_admin.html
smartshelf/app/templates/induction_test.html
smartshelf/app/templates/templates.zip
smartshelf/app/utils/serial_communication.py
smartshelf/app/utils/server_communication.py
smartshelf/config.py
smartshelf/logs/smart.log
.gitignore
查看文件 @
4477659
...
...
@@ -108,3 +108,4 @@ venv.bak/
# add
.idea/
smartshelf/app/__pycache__/induction_post.cpython-39.pyc
smartshelf/logs/smart.log
induction_shelf.zip
0 → 100644
查看文件 @
4477659
此文件太大,无法显示。
smartshelf/app/__init__.py
查看文件 @
4477659
...
...
@@ -9,8 +9,6 @@ from logging.handlers import RotatingFileHandler,TimedRotatingFileHandler
global
Serl
Serl
=
None
global
aaa
aaa
=
"123"
def
setup_log
():
# 设置日志的记录等级
logging
.
basicConfig
(
level
=
Config
.
LOG_LEVEL
)
# 调试debug级
...
...
@@ -25,12 +23,19 @@ def setup_log():
logging
.
getLogger
()
.
addHandler
(
file_log_handler
)
def
add_header
(
response
):
response
.
cache_control
.
no_store
=
True
response
.
cache_control
.
no_cache
=
True
#if 'Cache-Control' not in response.headers:
# response.headers['Cache-Control'] = 'no-cache'
return
response
setup_log
()
app
=
Flask
(
__name__
)
#CORS(app, resources=r'/*')
babel
=
Babel
(
app
)
app
.
config
.
from_object
(
Config
)
app
.
after_request
(
add_header
)
LANGUAGES
=
{
"zh"
:
"Chinese"
,
"en"
:
"English"
,
...
...
@@ -44,9 +49,9 @@ def s():
data
=
{
'key1'
:
'value1'
,
'key2'
:
'value2'
}
time
.
sleep
(
2
)
requests
.
post
(
"http://127.0.0.1:5000/stoppost"
,
data
)
if
testCidExists
():
time
.
sleep
(
2
)
requests
.
post
(
"http://127.0.0.1:5000/startpost"
,
data
)
#
if testCidExists():
time
.
sleep
(
2
)
requests
.
post
(
"http://127.0.0.1:5000/startpost"
,
data
)
t
=
threading
.
Thread
(
target
=
s
)
t
.
start
()
...
...
smartshelf/app/induction_admin.py
查看文件 @
4477659
...
...
@@ -162,7 +162,7 @@ def writeserial():
command
=
data
[
'command'
]
+
'
\r\n
'
#ser = SerialCommunication()
ser
.
send_data
(
command
)
time
.
sleep
(
0.
1
)
time
.
sleep
(
0.
3
)
msg
=
ser
.
read_alldata
()
if
msg
is
not
None
:
return
json
.
dumps
({
'msg'
:
"{}"
.
format
(
bytes
.
decode
(
msg
))})
...
...
@@ -179,6 +179,18 @@ def readserial():
return
json
.
dumps
({
'msg'
:
"{}"
.
format
(
bytes
.
decode
(
msg
))})
return
json
.
dumps
({
'msg'
:
''
})
@app.route
(
'/sitereport'
,
methods
=
[
'POST'
])
def
sitereport
():
current_state
=
read_state
()
if
current_state
==
'on'
:
return
json
.
dumps
({
'msg'
:
"请先停止系统"
})
ser
.
read_alldata
()
ser
.
send_data
(
"report"
)
time
.
sleep
(
1.5
)
msg
=
ser
.
read_alldata
()
return
json
.
dumps
({
'msg'
:
bytes
.
decode
(
msg
)})
#16mm 放8mm料盘;25mm放16mm料盘;35放24mm料盘;45放32mm料盘;54门放44mm料盘
#plateh={'1':8,'2':16,'3':24,'4':32,'5':44}
plateh
=
{
'20'
:
8
,
'14'
:
16
,
'10'
:
24
,
'8'
:
32
,
'5'
:
44
}
...
...
@@ -237,7 +249,7 @@ def buildstore():
url
=
ip_config
[
'ip'
]
+
'/service/store/uploadStoragePos'
data
=
{
"cid"
:
cid
,
'deviceType'
:
'NLP'
,
'posList'
:
body
}
print
(
contents
)
;
print
(
contents
)
#response = requests.post(url, data = json.dumps(body),headers = headers,timeout=2)
response
=
requests
.
post
(
url
,
data
=
json
.
dumps
(
data
),
headers
=
headers
,
timeout
=
10
)
response
=
response
.
json
()
...
...
smartshelf/app/induction_config.py
查看文件 @
4477659
...
...
@@ -26,7 +26,7 @@ try:
current
=
[
row
for
row
in
reader
]
ip_config
[
'ip'
]
=
current
[
0
][
0
]
ip_config
[
'cid'
]
=
current
[
0
][
1
]
logging
.
warning
(
"
ip&cid...:{}"
.
format
(
ip_config
))
logging
.
warning
(
"
config:{}, ip&cid...:{}"
.
format
(
uploads_path
,
ip_config
))
except
Exception
as
e
:
logging
.
warning
(
"ip,cid未配置"
)
...
...
smartshelf/app/induction_post.py
查看文件 @
4477659
...
...
@@ -45,7 +45,8 @@ def startpost():
is_start
=
True
ser
=
SerialCommunication
()
reset_tower
()
tower_state
=
get_towerstate
()
tower_state
=
get_towerstate
()
indresetled
()
threads
=
[]
threads
.
append
(
threading
.
Thread
(
target
=
serverboard
))
threads
.
append
(
threading
.
Thread
(
target
=
show_blink
))
...
...
@@ -650,7 +651,7 @@ def update_tower(blink_status,ng_status):
if
blink_status
[
'side'
]
.
lower
()
==
'a'
:
thisYellowTWLed
=
YellowTWLed
.
partition
(
'@'
)[
0
]
elif
blink_status
[
'side'
]
.
lower
()
==
'b'
:
thisYellowTWLed
=
YellowTWLed
.
partition
(
'@'
)[
0
]
thisYellowTWLed
=
YellowTWLed
.
partition
(
'@'
)[
1
]
if
blink_status
[
'status'
]:
if
tower_state
[
thisYellowTWLed
][
'status'
]
==
'off'
:
...
...
smartshelf/app/state/state.txt
查看文件 @
4477659
off
\ No newline at end of file
on
\ No newline at end of file
smartshelf/app/templates/induction_admin.html
查看文件 @
4477659
...
...
@@ -129,6 +129,9 @@
<input id="threshold">
</div> -->
<div
class=
"col-sm-2"
>
<input
type=
"button"
value=
"Site Report"
class=
"btn btn-warning"
onclick=
"Site_Report()"
/>
</div>
<div
class=
"col-sm-2"
>
<input
type=
"button"
value=
"传感器地址"
class=
"btn btn-warning"
onclick=
"adminaddr_test()"
/>
</div>
<div
class=
"col-sm-2"
>
...
...
@@ -291,6 +294,23 @@
})
}
}
function
Site_Report
()
{
$
.
ajax
({
url
:
"/sitereport"
,
type
:
"post"
,
// data:JSON.stringify(data),
contentType
:
"application/json"
,
dataType
:
'json'
,
success
:
function
(
data
)
{
// $("#testinfo").html(data.msg)
alert
(
data
.
msg
);
},
error
:
function
(
e
)
{
alert
(
"error"
);
}
})
}
function
buildstore
()
{
if
(
confirm
(
"请谨慎操作"
))
{
$
.
ajax
({
...
...
smartshelf/app/templates/induction_test.html
查看文件 @
4477659
...
...
@@ -394,7 +394,7 @@
if
(
shelfstate
==
'运行中'
)
{
alert
(
"料架运行中,请关闭后再进行测试"
)
}
else
{
var
data
=
{
"workchannel"
:
'16'
,
"workchannel"
:
document
.
getElementById
(
"workchannel"
).
value
,
"command"
:
'workoff'
}
$
.
ajax
({
url
:
"/indworkingoff"
,
...
...
smartshelf/app/templates/templates.zip
deleted
100644 → 0
查看文件 @
7a240e9
此文件类型无法预览
smartshelf/app/utils/serial_communication.py
查看文件 @
4477659
...
...
@@ -5,15 +5,18 @@
@ date: 2021.5.10
'''
import
imp
import
time
import
serial
#import serial.tools.list_ports
import
logging
from
config
import
Config
import
app.utils.g
as
gg
#serl = None
class
SerialCommunication
():
def
__init__
(
self
):
print
(
gg
.
Serl
)
#
print(gg.Serl)
#global serl
# serial_cf = ReadConfig()
# self.port = serial_cf.get_serial("DEFAULT_COM")
...
...
@@ -21,42 +24,75 @@ class SerialCommunication():
# self.timeout = float(serial_cf.get_serial("DEFAULT_TIMEOUT"))
# self.port = read_com()
# self.uploads_path = Config.UPLOAD_FOLDER
with
open
(
Config
.
IP_PATH
+
"/serialcom.txt"
,
"r"
)
as
f
:
serialcom
=
f
.
read
()
with
open
(
Config
.
IP_PATH
+
"/serialcom.txt"
,
"r"
)
as
f
:
serialcom
=
f
.
read
()
self
.
port
=
serialcom
.
strip
(
"
\n
"
)
self
.
bps
=
115200
self
.
timeout
=
1
if
gg
.
Serl
is
None
:
try
:
# 打开串口,并得到串口对象
gg
.
Serl
=
serial
.
Serial
(
port
=
self
.
port
,
baudrate
=
self
.
bps
,
timeout
=
self
.
timeout
)
# 判断是否打开成功
# if (self.main_engine.is_open):
print
(
"串口已打开1"
)
if
self
.
port
.
lower
()
.
endswith
(
"n"
):
self
.
TryConnectSerial
()
else
:
gg
.
Serl
=
serial
.
Serial
(
port
=
self
.
port
,
baudrate
=
self
.
bps
,
timeout
=
self
.
timeout
)
gg
.
Serl
.
open
()
log
(
"串口已打开1"
)
except
Exception
as
e
:
print
(
"---异常---:"
,
e
)
self
.
main_engine
=
gg
.
Serl
log
(
"---异常---:"
,
e
)
self
.
main_engine
=
gg
.
Serl
def
TryConnectSerial
(
self
):
if
not
self
.
port
.
lower
()
.
endswith
(
"n"
):
return
try
:
self
.
main_engine
.
close
()
except
:
log
(
"main_engine 关闭失败"
)
if
not
self
.
findSerial
(
self
.
port
.
strip
(
'n'
)
.
strip
(
'N'
)):
log
(
"无法定位串口,系统重启."
)
import
os
os
.
system
(
'sudo reboot'
)
def
findSerial
(
self
,
portpre
):
trytimes
=
0
while
trytimes
<
120
/
5
:
for
i
in
range
(
0
,
5
):
try
:
currentport
=
portpre
+
str
(
i
)
log
(
"尝试打开串口:{}"
.
format
(
currentport
))
gg
.
Serl
=
serial
.
Serial
(
port
=
currentport
,
baudrate
=
self
.
bps
,
timeout
=
self
.
timeout
)
gg
.
Serl
.
open
()
# 判断是否打开成功
gg
.
Serl
.
write
(
bytes
(
"A1
\n
"
.
encode
(
'utf-8'
)))
log
(
"成功打开串口:{}"
.
format
(
currentport
))
return
True
except
Exception
as
e
:
log
(
"串口打开失败:"
,
currentport
,
e
)
trytimes
+=
1
time
.
sleep
(
5
)
log
(
"串口打开失败,第{}次重试"
.
format
(
trytimes
))
return
False
# 打印设备基本信息
def
print_name
(
self
):
print
(
self
.
main_engine
.
name
)
#
设备名字
print
(
self
.
main_engine
.
port
)
#
读或者写端口
print
(
self
.
main_engine
.
baudrate
)
#
波特率
print
(
self
.
main_engine
.
bytesize
)
#
字节大小
print
(
self
.
main_engine
.
parity
)
#
校验位
print
(
self
.
main_engine
.
stopbits
)
#
停止位
print
(
self
.
main_engine
.
timeout
)
#
读超时设置
print
(
self
.
main_engine
.
writeTimeout
)
#
写超时
print
(
self
.
main_engine
.
xonxoff
)
#
软件流控
print
(
self
.
main_engine
.
rtscts
)
#
软件流控
print
(
self
.
main_engine
.
dsrdtr
)
#
硬件流控
print
(
self
.
main_engine
.
interCharTimeout
)
#
字符间隔超时
#打开串口
print
(
self
.
main_engine
.
name
)
#
设备名字
print
(
self
.
main_engine
.
port
)
#
读或者写端口
print
(
self
.
main_engine
.
baudrate
)
#
波特率
print
(
self
.
main_engine
.
bytesize
)
#
字节大小
print
(
self
.
main_engine
.
parity
)
#
校验位
print
(
self
.
main_engine
.
stopbits
)
#
停止位
print
(
self
.
main_engine
.
timeout
)
#
读超时设置
print
(
self
.
main_engine
.
writeTimeout
)
#
写超时
print
(
self
.
main_engine
.
xonxoff
)
#
软件流控
print
(
self
.
main_engine
.
rtscts
)
#
软件流控
print
(
self
.
main_engine
.
dsrdtr
)
#
硬件流控
print
(
self
.
main_engine
.
interCharTimeout
)
#
字符间隔超时
#
打开串口
def
Open_Engine
(
self
):
self
.
main_engine
.
open
()
#关闭串口
#
关闭串口
def
Close_Engine
(
self
):
self
.
main_engine
.
close
()
print
(
self
.
main_engine
.
is_open
)
# 检验串口是否打开
...
...
@@ -78,50 +114,58 @@ class SerialCommunication():
error_msg
=
'发生错误,{}'
.
format
(
e
)
return
error_msg
#接收指定大小的数据
#从串口读size个字节。如果指定超时,则可能在超时后返回较少的字节;如果没有指定超时,则会一直等到收完指定的字节数。
def
read_Size
(
self
,
size
):
# 接收指定大小的数据
# 从串口读size个字节。如果指定超时,则可能在超时后返回较少的字节;如果没有指定超时,则会一直等到收完指定的字节数。
def
read_Size
(
self
,
size
):
return
self
.
main_engine
.
read
(
size
=
size
)
#接收一行数据
#
接收一行数据
# 使用readline()时应该注意:打开串口时应该指定超时,否则如果串口没有收到新行,则会一直等待。
# 如果没有超时,readline会报异常。
def
read_Line
(
self
):
line
=
self
.
main_engine
.
readline
()
.
decode
(
'utf-8'
)
.
rstrip
()
return
line
# 未使用
def
read_Lines
(
self
):
line
=
self
.
main_engine
.
readlines
()
return
line
def
read_alldata
(
self
):
if
self
.
main_engine
.
in_waiting
:
return
self
.
main_engine
.
read_all
()
try
:
if
self
.
main_engine
.
in_waiting
:
return
self
.
main_engine
.
read_all
()
except
Exception
as
e
:
log
(
'串口读取数据错误,{}'
.
format
(
e
))
self
.
TryConnectSerial
()
return
bytes
(
""
)
# 未使用
def
read_hex_data
(
self
):
if
self
.
main_engine
.
in_waiting
:
data
=
self
.
main_engine
.
read_all
()
# data= str(binascii.b2a_hex(t.read(num)))[2:-1] #十六进制显示方法2
#发数据
def
send_data
(
self
,
data
):
#self.main_engine.flushInput()
#self.main_engine.flushOutput()
#
发数据
def
send_data
(
self
,
data
):
#
self.main_engine.flushInput()
#
self.main_engine.flushOutput()
# text = '{"ADDR":"99","colorset:[[1,255,0,0],[2,0,255,255],[5,132,142,110]]}\n{"ADDR":"1","color":[[1,10,20,30],[2,31,37,49],[5,1,3,5,7,9,11,14,18]]}\n{"ADDR":"3","color":[[1,10,20,30],[2,31,37,49],[5,1,3,5,7,9,11,14,18]]}\n'
print
(
'send_data:'
+
data
)
data
=
bytes
(
data
.
encode
(
'utf-8'
))
self
.
main_engine
.
write
(
data
)
try
:
print
(
'send_data:'
+
data
)
data
=
bytes
(
data
.
encode
(
'utf-8'
))
self
.
main_engine
.
write
(
data
)
except
Exception
as
e
:
log
(
'串口发送数据错误,{}'
.
format
(
e
))
self
.
TryConnectSerial
()
# 十六进制数据发送
def
send_hex_data
(
self
,
data
):
# 未使用
def
send_hex_data
(
self
,
data
):
data
=
bytes
(
data
.
encode
(
'utf-8'
))
# 先将输入的字符串转化成字节码
hexstring
=
data
.
hex
()
self
.
main_engine
.
write
(
hexstring
)
#更多示例
#
更多示例
# self.main_engine.write(chr(0x06).encode("utf-8")) # 十六制发送一个数据
# print(self.main_engine.read().hex()) # # 十六进制的读取读一个字节
# print(self.main_engine.read())#读一个字节
...
...
@@ -131,8 +175,9 @@ class SerialCommunication():
# print(self.main_engine.in_waiting)#获取输入缓冲区的剩余字节数
# print(self.main_engine.out_waiting)#获取输出缓冲区的字节数
# print(self.main_engine.readall())#读取全部字符。
#
def
Recive_data
(
self
,
way
):
# 未使用
def
Recive_data
(
self
,
way
):
# 循环接收数据,此为死循环,可用线程实现
print
(
"开始接收数据:"
)
while
True
:
...
...
@@ -142,15 +187,20 @@ class SerialCommunication():
if
(
way
==
0
):
for
i
in
range
(
self
.
main_engine
.
in_waiting
):
print
(
"接收ascii数据:"
+
str
(
self
.
Read_Size
(
1
)))
data1
=
self
.
Read_Size
(
1
)
.
hex
()
#转为十六进制
data2
=
int
(
data1
,
16
)
#转为十进制print("收到数据十六进制:"+data1+" 收到数据十进制:"+str(data2))
data1
=
self
.
Read_Size
(
1
)
.
hex
()
# 转为十六进制
# 转为十进制print("收到数据十六进制:"+data1+" 收到数据十进制:"+str(data2))
data2
=
int
(
data1
,
16
)
if
(
way
==
1
):
#整体接收
#
整体接收
# data = self.main_engine.read(self.main_engine.in_waiting).decode("utf-8")#方式一
data
=
self
.
main_engine
.
read_all
()
#
方式二print("接收ascii数据:", data)
data
=
self
.
main_engine
.
read_all
()
#
方式二print("接收ascii数据:", data)
except
Exception
as
e
:
print
(
"异常报错:"
,
e
)
print
(
"异常报错:"
,
e
)
def
log
(
*
values
:
object
):
print
(
values
)
logging
.
warning
(
values
)
# if __name__ == '__main__':
# myser = Communication("/dev/ttyUSB0",115200,1)
# myser.print_name()
...
...
smartshelf/app/utils/server_communication.py
查看文件 @
4477659
'''
@ author: jie
@ tools: pycharm
@ tools: pycharm
@ content: 服务器通讯实现类
@ date: 2021.6.3
'''
...
...
@@ -9,27 +9,28 @@ import logging
from
config
import
Config
import
requests
class
ServerCommunication
():
def
__init__
(
self
):
def
__init__
(
self
):
self
.
ip_path
=
Config
.
IP_PATH
self
.
ip_config
=
{}
try
:
with
open
(
self
.
ip_path
+
'ipconfig.csv'
,
'r'
)
as
f
:
reader
=
csv
.
reader
(
f
)
current
=
[
row
for
row
in
reader
]
self
.
ip_config
[
'ip'
]
=
current
[
0
][
0
]
self
.
ip_config
[
'cid'
]
=
current
[
0
][
1
]
logging
.
warning
(
"ip&cid...:{}"
.
format
(
self
.
ip_config
))
except
Exception
as
e
:
logging
.
warning
(
"ip,cid配置失败:{}"
.
format
(
e
))
try
:
with
open
(
self
.
ip_path
+
'ipconfig.csv'
,
'r'
)
as
f
:
reader
=
csv
.
reader
(
f
)
current
=
[
row
for
row
in
reader
]
self
.
ip_config
[
'ip'
]
=
current
[
0
][
0
]
self
.
ip_config
[
'cid'
]
=
current
[
0
][
1
]
logging
.
warning
(
"ip&cid...:{}"
.
format
(
self
.
ip_config
))
except
Exception
as
e
:
logging
.
warning
(
"ip,cid配置失败:{}"
.
format
(
e
))
def
server_post
(
body
):
ip_config
=
self
.
ip_config
url
=
ip_config
[
'ip'
]
cid
=
ip_config
[
'cid'
]
headers
=
{
'content-type'
:
"application/json"
}
try
:
response
=
requests
.
post
(
url
,
data
=
json
.
dumps
(
data
),
headers
=
headers
,
timeout
=
2
)
json_data
=
response
.
json
()
except
Exception
as
e
:
logging
.
warning
(
"服务器通信失败:{}"
.
format
(
e
))
def
server_post
(
self
,
body
):
ip_config
=
self
.
ip_config
url
=
ip_config
[
'ip'
]
cid
=
ip_config
[
'cid'
]
headers
=
{
'content-type'
:
"application/json"
}
try
:
response
=
requests
.
post
(
url
,
data
=
json
.
dumps
(
data
),
headers
=
headers
,
timeout
=
2
)
json_data
=
response
.
json
()
except
Exception
as
e
:
logging
.
warning
(
"服务器通信失败:{}"
.
format
(
e
))
smartshelf/config.py
查看文件 @
4477659
import
os
import
logging
from
datetime
import
timedelta
# 实例化configParser对象
# from dotenv import load_dotenv
...
...
@@ -10,6 +10,7 @@ basedir = os.path.abspath(os.path.dirname(__file__))
class
Config
(
object
):
#SEND_FILE_MAX_AGE_DEFAULT = timedelta(seconds=-1)
SECRET_KEY
=
os
.
environ
.
get
(
'SECRET_KEY'
)
or
'you-will-never-guess'
SQLALCHEMY_DATABASE_URI
=
os
.
environ
.
get
(
'DATABASE_URL'
)
or
\
'sqlite:///'
+
os
.
path
.
join
(
basedir
,
'app.db'
)
...
...
smartshelf/logs/smart.log
查看文件 @
4477659
此文件的差异太大,无法显示。
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论