Commit a3bcaa22 刘韬

开机自启动

1 个父辈 d577295e
正在显示 40 个修改的文件 包含 115 行增加45 行删除
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/*
*__pycache__/*
__pycache__/ __pycache__/
*.py[cod] *.py[cod]
*$py.class *$py.class
...@@ -104,4 +106,5 @@ venv.bak/ ...@@ -104,4 +106,5 @@ venv.bak/
.mypy_cache/ .mypy_cache/
# add # add
.idea/
\ No newline at end of file \ No newline at end of file
.idea/
smartshelf/app/__pycache__/induction_post.cpython-39.pyc
...@@ -4,13 +4,14 @@ ...@@ -4,13 +4,14 @@
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "Python: Flask", "name": "Python: Flask",
"type": "python", "type": "python",
"request": "launch", "request": "launch",
"module": "flask", "module": "flask",
"env": { "env": {
"FLASK_APP": "app", "FLASK_APP": "smartshelf/app",
"FLASK_ENV": "development" "FLASK_ENV": "development"
}, },
"args": [ "args": [
......
cd smartshelf
flask run -p 5000 -h 0.0.0.0
\ No newline at end of file \ No newline at end of file
cd smartshelf/app
flask run -p 5000 -h 0.0.0.0
pause
\ No newline at end of file \ No newline at end of file
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "app",
"FLASK_ENV": "development"
},
"args": [
"run",
"--host=0.0.0.0",
"--no-debugger",
"--no-reload"
],
"jinja": true
}
]
}
\ No newline at end of file \ No newline at end of file
import requests
import threading
from flask import Flask from flask import Flask
from flask_babel import Babel from flask_babel import Babel
from config import Config from config import Config
import logging import logging
from logging.handlers import RotatingFileHandler,TimedRotatingFileHandler from logging.handlers import RotatingFileHandler,TimedRotatingFileHandler
# from flask_socketio import SocketIO # from flask_socketio import SocketIO
def setup_log(): def setup_log():
...@@ -18,6 +21,8 @@ def setup_log(): ...@@ -18,6 +21,8 @@ def setup_log():
# 为全局的日志工具对象(flask app使用的)添加日志记录器 # 为全局的日志工具对象(flask app使用的)添加日志记录器
logging.getLogger().addHandler(file_log_handler) logging.getLogger().addHandler(file_log_handler)
Serl=None
setup_log() setup_log()
app = Flask(__name__) app = Flask(__name__)
babel = Babel(app) babel = Babel(app)
...@@ -29,6 +34,15 @@ LANGUAGES = { ...@@ -29,6 +34,15 @@ LANGUAGES = {
"ja": "Japanese" "ja": "Japanese"
} }
from app import induction_post,induction_test,induction_admin,induction_config,autoback,qr_code,scan_collection from app import induction_post,induction_test,induction_admin,induction_config,autoback,qr_code,scan_collection
import time
def s():
data = {'key1':'value1','key2':'value2'}
time.sleep(2)
requests.post("http://127.0.0.1:5000/stoppost",data)
time.sleep(2)
requests.post("http://127.0.0.1:5000/startpost",data)
t =threading.Thread(target=s)
t.start()
# return app # return app
\ No newline at end of file \ No newline at end of file
...@@ -32,8 +32,8 @@ ss16mm[] = {1,---100} ...@@ -32,8 +32,8 @@ ss16mm[] = {1,---100}
{"ADDR":"99","setcalibrate":[1,100,600,150],"threshold":45} {"ADDR":"99","setcalibrate":[1,100,600,150],"threshold":45}
{"ADDR":"99","calibrate":"min","threshold":45} {"ADDR":"99","calibrate":"min","threshold":45}
{"ADDR":"99","setcalibrate":"max","threshold":45} {"ADDR":"99","setcalibrate":"max","threshold":45}
{"ADDR":"1","ledtype":[1,1,1,1,1]}
{"ADDR":"99","action":"siteid","hwid":"FFFFFFF","addr":1}
version 0.3 0708 version 0.3 0708
scan command:"A1\nA2\nA3\n" //for example this command means scan addr 1,2,3 and return 1,2 and 3 location status scan command:"A1\nA2\nA3\n" //for example this command means scan addr 1,2,3 and return 1,2 and 3 location status
......
...@@ -104,9 +104,8 @@ def hancalibrate(): ...@@ -104,9 +104,8 @@ def hancalibrate():
command = str(json.dumps({"ADDR":addr,"setcalibrate":setcalibrate})) + '\n' command = str(json.dumps({"ADDR":addr,"setcalibrate":setcalibrate})) + '\n'
ser = SerialCommunication() ser = SerialCommunication()
ser.send_data(command) ser.send_data(command)
line_response = ser.read_Line()
print (command) print (command)
msg = "handle calibrate:{}已发送".format(line_response) msg = "handle calibrate:{}已发送".format(command)
return json.dumps({'msg':msg}) return json.dumps({'msg':msg})
......
...@@ -105,7 +105,7 @@ def confirm_autostart(): ...@@ -105,7 +105,7 @@ def confirm_autostart():
result = re.findall(r"\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b", ip_config['ip']) result = re.findall(r"\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b", ip_config['ip'])
if result: if result:
ip = result[0] ip = result[0]
server_add = "http://{}/smf".format(ip) server_add = "http://{}/neotel".format(ip)
else: else:
server_add = "127.0.0.1:5000" server_add = "127.0.0.1:5000"
line1 = "Comment = star chrome and enter the website for \"{}\"".format(server_add) line1 = "Comment = star chrome and enter the website for \"{}\"".format(server_add)
......
...@@ -21,12 +21,12 @@ from flask_babel import Babel, gettext as _ ...@@ -21,12 +21,12 @@ from flask_babel import Babel, gettext as _
import serial import serial
import timeit import timeit
# from serial_config import ReadConfig # from serial_config import ReadConfig
#serl=None
curren_l = 'zh' curren_l = 'zh'
scan_state = False scan_state = False
config_dict,convert_dict = Location().read_location_file() config_dict,convert_dict = Location().read_location_file()
option_list = Location().init_location_option() option_list = Location().init_location_option()
ser = SerialCommunication() #ser = SerialCommunication()
# state_addr = [] # state_addr = []
basepath = os.path.dirname(__file__) basepath = os.path.dirname(__file__)
uploads_path = basepath + Config.UPLOAD_FOLDER uploads_path = basepath + Config.UPLOAD_FOLDER
...@@ -144,6 +144,7 @@ def process_linetest(data): ...@@ -144,6 +144,7 @@ def process_linetest(data):
@app.route('/indlineledon', methods=['POST']) @app.route('/indlineledon', methods=['POST'])
# @checkscan # @checkscan
def indlineledon(): def indlineledon():
ser=SerialCommunication();
data = request.get_json() data = request.get_json()
texts = process_linetest(data) texts = process_linetest(data)
logging.warning("指令:{}".format(texts)) logging.warning("指令:{}".format(texts))
...@@ -160,6 +161,7 @@ def indlineledon(): ...@@ -160,6 +161,7 @@ def indlineledon():
@app.route('/indlineledoff', methods=['POST']) @app.route('/indlineledoff', methods=['POST'])
def indlineledoff(): def indlineledoff():
ser=SerialCommunication();
data = request.get_json() data = request.get_json()
texts = process_linetest(data) texts = process_linetest(data)
logging.warning("指令:{}".format(texts)) logging.warning("指令:{}".format(texts))
...@@ -195,6 +197,7 @@ def process_lightindex(data): ...@@ -195,6 +197,7 @@ def process_lightindex(data):
# 库位灯打开 # 库位灯打开
@app.route('/indledopen',methods=['POST']) @app.route('/indledopen',methods=['POST'])
def indledopen(): def indledopen():
ser=SerialCommunication();
data = request.get_json() data = request.get_json()
texts = process_lightindex(data) texts = process_lightindex(data)
# logging.warning("当前通道1ON_LED:{},当前通道2ON_LED:{}".format(led_lights1,led_lights2)) # logging.warning("当前通道1ON_LED:{},当前通道2ON_LED:{}".format(led_lights1,led_lights2))
...@@ -208,6 +211,7 @@ def indledopen(): ...@@ -208,6 +211,7 @@ def indledopen():
# 库位灯关闭 # 库位灯关闭
@app.route('/indledoff',methods=['POST']) @app.route('/indledoff',methods=['POST'])
def indledoff(): def indledoff():
ser=SerialCommunication();
data = request.get_json() data = request.get_json()
texts = process_lightindex(data) texts = process_lightindex(data)
print (texts) print (texts)
...@@ -219,6 +223,7 @@ def indledoff(): ...@@ -219,6 +223,7 @@ def indledoff():
@app.route('/indresetled',methods=['POST']) @app.route('/indresetled',methods=['POST'])
def indresetled(): def indresetled():
ser=SerialCommunication();
try: try:
data = {'channel_num':'all','channel_color':'off'} data = {'channel_num':'all','channel_color':'off'}
texts = process_linetest(data) texts = process_linetest(data)
...@@ -239,6 +244,7 @@ def indresetled(): ...@@ -239,6 +244,7 @@ def indresetled():
@app.route('/indworkinglight',methods=['POST']) @app.route('/indworkinglight',methods=['POST'])
def indworkinglight(): def indworkinglight():
ser=SerialCommunication();
data = request.get_json() data = request.get_json()
# channel = data['workchannel'] # channel = data['workchannel']
text=maincollection(data) text=maincollection(data)
...@@ -251,6 +257,7 @@ def indworkinglight(): ...@@ -251,6 +257,7 @@ def indworkinglight():
@app.route('/indworkingoff',methods=['POST']) @app.route('/indworkingoff',methods=['POST'])
def indworkingoff(): def indworkingoff():
ser=SerialCommunication();
data = request.get_json() data = request.get_json()
text=maincollection(data) text=maincollection(data)
ser.send_data(text) ser.send_data(text)
...@@ -284,7 +291,7 @@ def scancom(): ...@@ -284,7 +291,7 @@ def scancom():
@app.route('/resetmain',methods=['POST']) @app.route('/resetmain',methods=['POST'])
def resetmain(): def resetmain():
# ser = SerialCommunication() ser = SerialCommunication()
data = request.get_json() data = request.get_json()
text=maincollection(data) text=maincollection(data)
print (text) print (text)
...@@ -295,6 +302,7 @@ def resetmain(): ...@@ -295,6 +302,7 @@ def resetmain():
@app.route('/powermain',methods=['POST']) @app.route('/powermain',methods=['POST'])
def powermain(): def powermain():
ser=SerialCommunication();
data = request.get_json() data = request.get_json()
text=maincollection(data) text=maincollection(data)
print (text) print (text)
......
...@@ -29,27 +29,27 @@ def production_filter(origin_value): ...@@ -29,27 +29,27 @@ def production_filter(origin_value):
return cur_dict return cur_dict
def transfer(origin_value): def transfer(origin_value):
cur_dict = {} cur_dict = {}
if origin_value: if origin_value:
# receive_data=origin_value.split("\n") # receive_data=origin_value.split("\n")
receive_data=origin_value.decode().split("\r\n") receive_data=origin_value.decode().split("\r\n")
for item in receive_data[::-1]: for item in receive_data[::-1]:
if not (item.startswith("A") and item.endswith("]")): if not (item.startswith("A") and item.endswith("]")):
receive_data.remove(item) receive_data.remove(item)
print (item) print (item)
print("筛选后的数据:", receive_data) print("筛选后的数据:", receive_data)
if receive_data: if receive_data:
for line in receive_data: for line in receive_data:
# print ("-----------------line",line) # print ("-----------------line",line)
addr = re.search("(?<=A)\d+",line) addr = re.search("(?<=A)\d+",line)
led = re.search("\[.*?\]", line) led = re.search("\[.*?\]", line)
c_list = list(led.group()) c_list = list(led.group())
# print ("-------------------c_list",c_list) # print ("-------------------c_list",c_list)
c_list.pop(0) c_list.pop(0)
c_list.pop(-1) c_list.pop(-1)
keyword = 'A' + addr.group() keyword = 'A' + addr.group()
cur_dict[keyword] = c_list cur_dict[keyword] = c_list
return cur_dict return cur_dict
def change_deatil(old_dict): def change_deatil(old_dict):
global s_detail global s_detail
......
A1@A2@A3@A4@A5@A6@A7@A8@A9
\ No newline at end of file \ No newline at end of file
A1
\ No newline at end of file \ No newline at end of file
http://192.168.101.108/smdbox,ls01 http://192.168.1.243/smf-core,4
\ No newline at end of file \ No newline at end of file
/dev/ttyUSB0
\ No newline at end of file \ No newline at end of file
/dev/ttyUSB0
\ No newline at end of file \ No newline at end of file
/dev/ttyUSBCOM9
\ No newline at end of file \ No newline at end of file
1.3-0818
\ No newline at end of file \ No newline at end of file
1.2
\ No newline at end of file \ No newline at end of file
class g():
def __init__(self):
self.seal=None
@property
def name(self):
return self.seal
@name.setter
def name(self, value):
self.seal = value
...@@ -4,15 +4,17 @@ ...@@ -4,15 +4,17 @@
@ content: 串口通讯实现类 @ content: 串口通讯实现类
@ date: 2021.5.10 @ date: 2021.5.10
''' '''
import imp
import serial import serial
import serial.tools.list_ports import serial.tools.list_ports
import logging import logging
from config import Config from config import Config
serl = None
# from serial_config import ReadConfig # from serial_config import ReadConfig
# from app.induction_config import read_com # from app.induction_config import read_com
class SerialCommunication(): class SerialCommunication():
def __init__(self): def __init__(self):
global serl
# serial_cf = ReadConfig() # serial_cf = ReadConfig()
# self.port = serial_cf.get_serial("DEFAULT_COM") # self.port = serial_cf.get_serial("DEFAULT_COM")
# self.bps = int(serial_cf.get_serial("DEFAULT_BAUDRATE")) # self.bps = int(serial_cf.get_serial("DEFAULT_BAUDRATE"))
...@@ -24,14 +26,16 @@ class SerialCommunication(): ...@@ -24,14 +26,16 @@ class SerialCommunication():
self.port = serialcom.strip("\n") self.port = serialcom.strip("\n")
self.bps = 115200 self.bps = 115200
self.timeout = 1 self.timeout = 1
try: if serl is None:
# 打开串口,并得到串口对象 try:
self.main_engine= serial.Serial(port=self.port,baudrate=self.bps,timeout=self.timeout) # 打开串口,并得到串口对象
# 判断是否打开成功 serl = serial.Serial(port=self.port,baudrate=self.bps,timeout=self.timeout)
# if (self.main_engine.is_open): # 判断是否打开成功
# print ("串口已打开") # if (self.main_engine.is_open):
except Exception as e: # print ("串口已打开")
print("---异常---:", e) except Exception as e:
print("---异常---:", e)
self.main_engine=serl
# 打印设备基本信息 # 打印设备基本信息
def print_name(self): def print_name(self):
......
此文件类型无法预览
此文件的差异太大,无法显示。
flask run -p 5000 -h 0.0.0.0
pause
\ No newline at end of file \ No newline at end of file
import configparser import configparser
import os import os
import time import time
import config as Config
class ReadConfig(): class ReadConfig():
"""定义一个读取配置文件的类""" """定义一个读取配置文件的类"""
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!