结构优化
This commit is contained in:
@ -1,3 +1,3 @@
|
||||
User,User_pass,Wifi_SSID,Modbus_IP,Modbus_Port,NFC_ID,Reserve
|
||||
测试用户,0000,zhizhan-2,10.10.100.254,8899,0000,0000
|
||||
正式测试,0000,zhizhan-2,10.10.100.254,8899,0000,1111
|
||||
正式用户,0000,USR-DR404_3EB0,10.10.100.254,8899,0000,0000
|
||||
|
||||
|
246
kv/app.kv
246
kv/app.kv
@ -1,43 +1,36 @@
|
||||
ScreenManager: # 屏幕管理器,用于管理应用中所有的屏幕及其切换
|
||||
MainScreen: # 主屏幕
|
||||
name: 'main' # 屏幕名称,用于导航切换
|
||||
HomeScreen: # 首页屏幕
|
||||
name: 'home' # 首页,显示应用主要内容和功能入口
|
||||
LoginScreen: # 登录屏幕
|
||||
name: 'login' # 用户认证界面
|
||||
ProfileScreen: # 个人资料屏幕
|
||||
name: "profile" # 显示用户个人信息的界面
|
||||
HistoryScreen: # 历史记录屏幕
|
||||
name: 'history' # 显示用户操作历史
|
||||
|
||||
|
||||
ModifyCurrentParamScreen: # 修改参数屏幕
|
||||
name: 'modify_current_param' # 用于修改系统参数的界面
|
||||
ModifyVoltageParamScreen: # 修改电压参数屏幕
|
||||
name: 'modify_voltage_param' # 用于修改电压参数的界面
|
||||
ModifyLeakageParamScreen: # 修改漏电参数屏幕
|
||||
name: 'modify_leakage_param' # 用于修改漏电参数的
|
||||
ModifySystemParamScreen: # 修改系统参数屏幕
|
||||
name: 'modify_system_param' # 用于修改系统设置的界面
|
||||
ModifyProtectionParamScreen: # 修改保护参数屏幕
|
||||
name: 'modify_protection_param' # 用于修改保护参数的界面
|
||||
RealTimeCurveScreen: # 实时曲线屏幕
|
||||
name: 'real_time_curve' # 显示实时数据曲线的界面
|
||||
ControlCommandScreen: # 控制命令屏幕
|
||||
name: 'control_command' # 用于发送控制命令的界面
|
||||
|
||||
AboutScreen: # 关于屏幕
|
||||
name: 'about' # 显示应用信息和开发者信息的界
|
||||
ScreenManager:
|
||||
MainScreen:
|
||||
name: 'main'
|
||||
HomeScreen:
|
||||
name: 'home'
|
||||
LoginScreen:
|
||||
name: 'login'
|
||||
ProfileScreen:
|
||||
name: "profile"
|
||||
HistoryScreen:
|
||||
name: 'history'
|
||||
ModifyCurrentParamScreen:
|
||||
name: 'modify_current_param'
|
||||
ModifyVoltageParamScreen:
|
||||
name: 'modify_voltage_param'
|
||||
ModifyLeakageParamScreen:
|
||||
name: 'modify_leakage_param'
|
||||
ModifySystemParamScreen:
|
||||
name: 'modify_system_param'
|
||||
ModifyProtectionParamScreen:
|
||||
name: 'modify_protection_param'
|
||||
RealTimeCurveScreen:
|
||||
name: 'real_time_curve'
|
||||
ControlCommandScreen:
|
||||
name: 'control_command'
|
||||
AboutScreen:
|
||||
name: 'about'
|
||||
|
||||
|
||||
|
||||
<MainScreen>:
|
||||
MDFloatLayout:
|
||||
# Image:
|
||||
# source: 'assets/logo.png'
|
||||
# size_hint: None, 0.9
|
||||
# width: dp(150)
|
||||
# pos_hint: {'center_x': 0.1, 'center_y': 0.95}
|
||||
|
||||
Image:
|
||||
source: 'assets/img.png'
|
||||
size_hint: 1, 1
|
||||
@ -83,27 +76,6 @@ ScreenManager: # 屏幕管理器,用于管理应用中所有的屏幕及其
|
||||
size: self.size
|
||||
pos: self.pos
|
||||
radius: [5]
|
||||
# Button:
|
||||
# text: "注 册"
|
||||
# size_hint: None, None
|
||||
# font_name: "BPoppins"
|
||||
# width: dp(350)
|
||||
# height: dp(59)
|
||||
# pos_hint: {'center_x': 0.5, 'center_y': 0.19}
|
||||
# background_color: 0,0,0,0
|
||||
# color: rgba(52, 0, 231, 255)
|
||||
# on_touch_down: app.change_cursor(True)
|
||||
# on_touch_up: app.change_cursor(False)
|
||||
# on_release:
|
||||
# root.manager.transition.direction = "left"
|
||||
# root.manager.current = "signup"
|
||||
# canvas.before:
|
||||
# Color:
|
||||
# rgb: rgba(52, 0, 231, 255)
|
||||
# Line:
|
||||
# width: 1.2
|
||||
# rounded_rectangle: self.x, self.y, self.width, self.height, 5,5,5,5,100
|
||||
|
||||
|
||||
<DrawerClickableItem@MDNavigationDrawerItem>
|
||||
<HomeScreen>:
|
||||
@ -242,8 +214,8 @@ ScreenManager: # 屏幕管理器,用于管理应用中所有的屏幕及其
|
||||
id : user
|
||||
title: "欢迎使用"
|
||||
text: "功能总览"
|
||||
title_font_style: "H5" # 使用自定义标题字体
|
||||
text_font_style: "Caption" # 使用自定义正文字体
|
||||
title_font_style: "H5"
|
||||
text_font_style: "Caption"
|
||||
text_color: "#6c7272"
|
||||
text_font_size: '13sp'
|
||||
title_color: "#00f0ff"
|
||||
@ -560,7 +532,7 @@ ScreenManager: # 屏幕管理器,用于管理应用中所有的屏幕及其
|
||||
size_hint_y: None
|
||||
height: '30dp'
|
||||
MDLabel:
|
||||
text: "Your Details"
|
||||
text: "信息"
|
||||
font_name: "BPoppins"
|
||||
font_size: "14sp"
|
||||
color: [0,0,0,1]
|
||||
@ -581,55 +553,41 @@ ScreenManager: # 屏幕管理器,用于管理应用中所有的屏幕及其
|
||||
MDList:
|
||||
spacing: "0dp"
|
||||
OneLineIconListItem:
|
||||
text: profile_user_name.text
|
||||
id: profile_user_name
|
||||
text: ""
|
||||
IconLeftWidget:
|
||||
icon: "account-outline"
|
||||
icon: ""
|
||||
|
||||
OneLineIconListItem:
|
||||
id : profile_user_pass
|
||||
text: ""
|
||||
IconLeftWidget:
|
||||
icon: "email-outline"
|
||||
icon: ""
|
||||
OneLineIconListItem:
|
||||
id : profile_modbus_ip
|
||||
text: ""
|
||||
IconLeftWidget:
|
||||
icon: "dialpad"
|
||||
icon: ""
|
||||
OneLineIconListItem:
|
||||
id : profile_modbus_port
|
||||
text: ""
|
||||
IconLeftWidget:
|
||||
icon: ""
|
||||
OneLineIconListItem:
|
||||
id : profile_wifi_ssid
|
||||
text: ""
|
||||
IconLeftWidget:
|
||||
icon: "phone-outline"
|
||||
MDLabel:
|
||||
text: "Other Details"
|
||||
font_name: "BPoppins"
|
||||
font_size: "14sp"
|
||||
size_hint_y: None
|
||||
height: self.texture_size[1]
|
||||
padding: "12dp"
|
||||
pos_hint: {'center_y': 0.9}
|
||||
|
||||
ScrollView:
|
||||
MDList:
|
||||
spacing: "0dp"
|
||||
OneLineAvatarListItem:
|
||||
id : profile_branch
|
||||
icon: "wifi"
|
||||
OneLineIconListItem:
|
||||
id : profile_nfc_id
|
||||
text: ""
|
||||
ImageLeftWidget:
|
||||
source:'assets/branch.png'
|
||||
size_hint: 2, .68
|
||||
pos: self.pos
|
||||
|
||||
OneLineAvatarListItem:
|
||||
id : profile_semester
|
||||
IconLeftWidget:
|
||||
icon: "nfc"
|
||||
OneLineIconListItem:
|
||||
id : profile_reserve
|
||||
text: ""
|
||||
ImageLeftWidget:
|
||||
source:'assets/semister.png'
|
||||
size_hint: 2, .68
|
||||
pos: self.pos
|
||||
|
||||
|
||||
|
||||
IconLeftWidget:
|
||||
icon: ""
|
||||
|
||||
<HistoryScreen>:
|
||||
MDFloatLayout:
|
||||
@ -720,31 +678,6 @@ ScreenManager: # 屏幕管理器,用于管理应用中所有的屏幕及其
|
||||
spacing: "2dp"
|
||||
Widget:
|
||||
|
||||
MDBottomAppBar:
|
||||
height: "62dp"
|
||||
elevation: 10
|
||||
MDActionBottomAppBarButton:
|
||||
icon: "home"
|
||||
pos_hint:{'center_x':0.15, 'center_y': 0.5}
|
||||
on_press: root.manager.current = 'home'
|
||||
MDActionBottomAppBarButton:
|
||||
icon: "tools"
|
||||
pos_hint:{'center_x':0.38, 'center_y': 0.5}
|
||||
on_press: root.manager.current = 'borrow_book'
|
||||
MDActionBottomAppBarButton:
|
||||
icon: "thumb-up-outline"
|
||||
pos_hint:{'center_x':0.61, 'center_y': 0.5}
|
||||
on_press: root.manager.current = 'recommend'
|
||||
MDActionBottomAppBarButton:
|
||||
icon: "history"
|
||||
pos_hint:{'center_x':0.85, 'center_y': 0.5}
|
||||
on_press:
|
||||
root.manager.current = 'history'
|
||||
# app.book_history()
|
||||
|
||||
|
||||
|
||||
|
||||
MDIconButton:
|
||||
icon: "arrow-left"
|
||||
pos_hint: {'center_y': 0.95}
|
||||
@ -810,7 +743,7 @@ ScreenManager: # 屏幕管理器,用于管理应用中所有的屏幕及其
|
||||
|
||||
|
||||
MDTextField:
|
||||
id: edit_name
|
||||
id: edit_user_name
|
||||
text: ""
|
||||
hint_text: "Enter Name*"
|
||||
font_name: "MPoppins"
|
||||
@ -833,12 +766,12 @@ ScreenManager: # 屏幕管理器,用于管理应用中所有的屏幕及其
|
||||
|
||||
|
||||
MDTextField:
|
||||
id: edit_prn
|
||||
id: edit_user_pass
|
||||
text: ""
|
||||
hint_text: "Provide your PRN*"
|
||||
hint_text: "User_pass*"
|
||||
font_name: "MPoppins"
|
||||
font_size: "15sp"
|
||||
helper_text: "unable to change prn directly"
|
||||
helper_text: "Provide your password"
|
||||
helper_text_mode: "on_focus"
|
||||
readonly: True
|
||||
icon_right: "dialpad"
|
||||
@ -857,15 +790,15 @@ ScreenManager: # 屏幕管理器,用于管理应用中所有的屏幕及其
|
||||
width: dp(0.5)
|
||||
rounded_rectangle: self.x-5, self.y+20, self.width+10, self.height-25, 10,10,10,10,100
|
||||
MDTextField:
|
||||
id: edit_email
|
||||
id: edit_modbus_ip
|
||||
text: ""
|
||||
hint_text: "Provide Email-id*"
|
||||
hint_text: "Modbus_IP*"
|
||||
font_name: "MPoppins"
|
||||
font_size: "15sp"
|
||||
readonly: True
|
||||
helper_text: "unable to change email directly"
|
||||
helper_text: "Provide your Modbus_IP"
|
||||
helper_text_mode: "on_focus"
|
||||
icon_right: "email-arrow-left"
|
||||
icon_right: "network"
|
||||
min_text_length: 11
|
||||
icon_color: app.theme_cls.primary_color
|
||||
pos_hint: {"center_x": 0.5, "center_y": 0.6025}
|
||||
@ -881,15 +814,15 @@ ScreenManager: # 屏幕管理器,用于管理应用中所有的屏幕及其
|
||||
rounded_rectangle: self.x-5, self.y+20, self.width+10, self.height-25, 10,10,10,10,100
|
||||
|
||||
MDTextField:
|
||||
id:edit_no
|
||||
id:edit_modbus_port
|
||||
text: ""
|
||||
hint_text: "Enter WhatsApp Number*"
|
||||
hint_text: "Modbus_Port*"
|
||||
font_name: "MPoppins"
|
||||
font_size: "15sp"
|
||||
readonly: True
|
||||
helper_text: "unable to change number directly"
|
||||
helper_text_mode: "on_focus"
|
||||
icon_right: "whatsapp"
|
||||
icon_right: "dialpad"
|
||||
icon_color: app.theme_cls.primary_color
|
||||
input_filter: 'int'
|
||||
max_text_length: 10
|
||||
@ -906,14 +839,14 @@ ScreenManager: # 屏幕管理器,用于管理应用中所有的屏幕及其
|
||||
rounded_rectangle: self.x-5, self.y+20, self.width+10, self.height-25, 10,10,10,10,100
|
||||
|
||||
MDTextField:
|
||||
id: edit_branch
|
||||
id: edit_nfc_id
|
||||
text: ""
|
||||
hint_text: "Branch*"
|
||||
hint_text: "NFC_ID*"
|
||||
font_name: "MPoppins"
|
||||
font_size: "15sp"
|
||||
helper_text: "Provide your Branch"
|
||||
helper_text: "Provide your NFC_ID"
|
||||
helper_text_mode: "on_focus"
|
||||
icon_right: "source-branch"
|
||||
icon_right: "nfc"
|
||||
min_text_length: 11
|
||||
icon_color: app.theme_cls.primary_color
|
||||
pos_hint: {"center_x": 0.5, "center_y": 0.3625}
|
||||
@ -929,12 +862,12 @@ ScreenManager: # 屏幕管理器,用于管理应用中所有的屏幕及其
|
||||
rounded_rectangle: self.x-5, self.y+20, self.width+10, self.height-25, 10,10,10,10,100
|
||||
|
||||
MDTextField:
|
||||
id: edit_sem
|
||||
id: edit_wifi_ssid
|
||||
text: ""
|
||||
hint_text: "Semester*"
|
||||
hint_text: "wifi ssid*"
|
||||
font_name: "MPoppins"
|
||||
font_size: "15sp"
|
||||
helper_text: "Provide your semester like I,II,III only*"
|
||||
helper_text: "Provide your wifi ssid"
|
||||
helper_text_mode: "on_focus"
|
||||
icon_right: "roman-numeral-2"
|
||||
min_text_length: 11
|
||||
@ -950,9 +883,35 @@ ScreenManager: # 屏幕管理器,用于管理应用中所有的屏幕及其
|
||||
Line:
|
||||
width: dp(0.5)
|
||||
rounded_rectangle: self.x-5, self.y+20, self.width+10, self.height-25, 10,10,10,10,100
|
||||
|
||||
MDTextField:
|
||||
id: edit_reserve
|
||||
text: ""
|
||||
hint_text: "Reserve*"
|
||||
font_name: "MPoppins"
|
||||
font_size: "15sp"
|
||||
helper_text: "Provide your Reserve"
|
||||
helper_text_mode: "on_focus"
|
||||
icon_right: "nfc"
|
||||
min_text_length: 11
|
||||
icon_color: app.theme_cls.primary_color
|
||||
pos_hint: {"center_x": 0.5, "center_y": 0.1225}
|
||||
size_hint_x: None
|
||||
width: dp(335)
|
||||
on_touch_down: app.change_cursor(True)
|
||||
on_touch_up: app.change_cursor(False)
|
||||
canvas.before:
|
||||
Color:
|
||||
rgb: rgba(127, 127, 127, 255)
|
||||
Line:
|
||||
width: dp(0.5)
|
||||
rounded_rectangle: self.x-5, self.y+20, self.width+10, self.height-25, 10,10,10,10,100
|
||||
|
||||
|
||||
|
||||
|
||||
Button:
|
||||
text: "Save Profile & Continue"
|
||||
text: "保存配置"
|
||||
font_name: "BPoppins"
|
||||
size_hint: 0.66, 0.065
|
||||
pos_hint: {'center_x': 0.5, 'center_y': 0.17}
|
||||
@ -972,21 +931,6 @@ ScreenManager: # 屏幕管理器,用于管理应用中所有的屏幕及其
|
||||
pos: self.pos
|
||||
radius: [25]
|
||||
|
||||
MDTextButton:
|
||||
id : edit_private_credential_butn
|
||||
text: "Do you want edit prn/email/No."
|
||||
pos_hint: {'center_x': 0.5, 'center_y': 0.12}
|
||||
color: rgba(68,78,132,255)
|
||||
font_name: "BPoppins"
|
||||
font_size: '13sp'
|
||||
on_touch_down: app.change_cursor(True)
|
||||
on_touch_up: app.change_cursor(False)
|
||||
on_release:
|
||||
root.manager.transition.direction= "down"
|
||||
app.send_otp(edit_no.text)
|
||||
app.otp_button_fun("1")
|
||||
root.manager.current="otp"
|
||||
|
||||
|
||||
<RealTimeCurveScreen>:
|
||||
MDFloatLayout: # 使用浮动布局,可以自由控制子组件的位置
|
||||
|
||||
170
main.py
170
main.py
@ -87,51 +87,31 @@ class app(MDApp):
|
||||
wifi_status_text = StringProperty("")
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.signup_branch = None
|
||||
|
||||
self.user_name = None
|
||||
|
||||
|
||||
|
||||
self.rec_grid = None
|
||||
self.recommend_screen = None
|
||||
self.book_input = None
|
||||
self.data_tables = None
|
||||
self.search_grid = None
|
||||
self.search_field = None
|
||||
self.renew_grid = None
|
||||
self.renewable_books = []
|
||||
self.renew = self.renewable_books
|
||||
self.history_grid = None
|
||||
self.books_history = []
|
||||
self.history = self.books_history
|
||||
self.image_label_grid = None
|
||||
self.books = []
|
||||
self.items = self.books
|
||||
self.book_name = None
|
||||
self.isbn = None
|
||||
self.a = None
|
||||
self.back_button = None
|
||||
self.user = None
|
||||
self.dialog = None
|
||||
self.dialog2 = None
|
||||
|
||||
self.profile_edit_screen = None
|
||||
self.edit_email = None
|
||||
self.edit_prn = None
|
||||
self.edit_name = None
|
||||
|
||||
self.edit_user_pass = None
|
||||
self.edit_user_name = None
|
||||
self.edit_wifi_ssid = None
|
||||
self.edit_branch = None
|
||||
self.profile_semester = None
|
||||
self.profile_branch = None
|
||||
self.profile_wifi_ssid = None
|
||||
self.profile_prn = None
|
||||
self.edit_modbus_ip = None
|
||||
self.edit_modbus_port = None
|
||||
self.edit_nfc_id = None
|
||||
self.edit_reserve = None
|
||||
|
||||
|
||||
self.profile_user_pass = None
|
||||
self.profile_user_name = None
|
||||
self.user_no = None
|
||||
self.user_email = None
|
||||
self.user_prn = None
|
||||
self.d2 = None
|
||||
self.d3 = None
|
||||
self.d4 = None
|
||||
self.profile_wifi_ssid = None
|
||||
self.profile_modbus_ip = None
|
||||
self.profile_modbus_port = None
|
||||
self.profile_nfc_id = None
|
||||
self.profile_reserve = None
|
||||
|
||||
|
||||
self.user_pass = None
|
||||
self.d1 = None
|
||||
self.edit_semester = None
|
||||
@ -217,44 +197,30 @@ class app(MDApp):
|
||||
|
||||
#############################################ALL INPUT TEXT############################################################
|
||||
def on_start(self):
|
||||
|
||||
# 从根窗口中获取名为"login"的屏幕(登录界面)
|
||||
|
||||
login_screen = self.root.get_screen("login")
|
||||
|
||||
|
||||
# 从根窗口中获取名为"home"的屏幕(主界面)
|
||||
home_screen = self.root.get_screen("home")
|
||||
# 通过界面ID获取主界面中的用户信息组件
|
||||
self.user = home_screen.ids.user
|
||||
|
||||
# 从根窗口中获取名为"profile"的屏幕(个人资料界面)
|
||||
profile_screen = self.root.get_screen("profile")
|
||||
# 通过界面ID获取个人资料界面中的姓名展示组件
|
||||
self.profile_user_name = profile_screen.ids.profile_user_name
|
||||
# 通过界面ID获取个人资料界面中的邮箱展示组件
|
||||
self.profile_user_pass = profile_screen.ids.profile_user_pass
|
||||
# 通过界面ID获取个人资料界面中的PRN(身份标识)展示组件
|
||||
self.profile_prn = profile_screen.ids.profile_prn
|
||||
# 通过界面ID获取个人资料界面中的手机号展示组件
|
||||
self.profile_wifi_ssid = profile_screen.ids.profile_wifi_ssid
|
||||
# 通过界面ID获取个人资料界面中的所属部门/专业展示组件
|
||||
self.profile_branch = profile_screen.ids.profile_branch
|
||||
# 通过界面ID获取个人资料界面中的年级/学期展示组件
|
||||
self.profile_semester = profile_screen.ids.profile_semester
|
||||
# 从根窗口中获取名为"profile_edit"的屏幕(个人资料编辑界面)
|
||||
self.profile_modbus_ip = profile_screen.ids.profile_modbus_ip
|
||||
self.profile_modbus_port = profile_screen.ids.profile_modbus_port
|
||||
self.profile_nfc_id = profile_screen.ids.profile_nfc_id
|
||||
self.profile_reserve = profile_screen.ids.profile_reserve
|
||||
|
||||
self.profile_edit_screen = self.root.get_screen("profile_edit")
|
||||
# 通过界面ID获取资料编辑界面中的姓名编辑输入框组件
|
||||
self.edit_name = self.profile_edit_screen.ids.edit_name
|
||||
# 通过界面ID获取资料编辑界面中的邮箱编辑输入框组件
|
||||
self.edit_email = self.profile_edit_screen.ids.edit_email
|
||||
# 通过界面ID获取资料编辑界面中的PRN(身份标识)编辑输入框组件
|
||||
self.edit_prn = self.profile_edit_screen.ids.edit_prn
|
||||
# 通过界面ID获取资料编辑界面中的手机号编辑输入框组件
|
||||
self.edit_wifi_ssid = self.profile_edit_screen.ids.edit_no
|
||||
# 通过界面ID获取资料编辑界面中的所属部门/专业编辑选择组件
|
||||
self.edit_branch = self.profile_edit_screen.ids.edit_branch
|
||||
# 通过界面ID获取资料编辑界面中的年级/学期编辑选择组件
|
||||
self.edit_semester = self.profile_edit_screen.ids.edit_sem
|
||||
|
||||
self.edit_user_name = self.profile_edit_screen.ids.edit_user_name
|
||||
self.edit_user_pass = self.profile_edit_screen.ids.edit_user_pass
|
||||
self.edit_wifi_ssid = self.profile_edit_screen.ids.edit_wifi_ssid
|
||||
self.edit_modbus_ip = self.profile_edit_screen.ids.edit_modbus_ip
|
||||
self.edit_modbus_port = self.profile_edit_screen.ids.edit_modbus_port
|
||||
self.edit_nfc_id = self.profile_edit_screen.ids.edit_nfc_id
|
||||
self.edit_reserve = self.profile_edit_screen.ids.edit_reserve
|
||||
|
||||
|
||||
self.root.bind(current=self.on_screen_changed)
|
||||
@ -450,7 +416,7 @@ class app(MDApp):
|
||||
|
||||
def read_modbus_registers(self, slave_id=1, address=0, count=1):
|
||||
"""
|
||||
通用的Modbus保持寄存器读取函数(优化版)
|
||||
通用的Modbus保持寄存器读取函数
|
||||
:param slave_id: 从机ID
|
||||
:param address: 寄存器地址
|
||||
:param count: 读取数量
|
||||
@ -482,10 +448,10 @@ class app(MDApp):
|
||||
|
||||
def write_modbus_register(self, slave_id=1, address=0, value=None):
|
||||
"""
|
||||
通用写入Modbus保持寄存器(单个寄存器),低耦合版
|
||||
通用写入Modbus保持寄存器(单个寄存器)
|
||||
:param slave_id: 从机ID
|
||||
:param address: 寄存器地址
|
||||
:param value: 要写入的值(整数,0-65535)
|
||||
:param value: 要写入的值(整数,0-65535)
|
||||
:return: {'success': bool, 'msg': str}
|
||||
"""
|
||||
return self.modbus_master.write_single_register(slave_id, address, value)
|
||||
@ -640,22 +606,25 @@ class app(MDApp):
|
||||
if wifi_id == csv_ssid:
|
||||
# 通过列名获取用户信息
|
||||
name = row['User']
|
||||
prn = row['Reserve'] # 根据实际列名调整
|
||||
email = row['Reserve'] # 根据实际列名调整
|
||||
number = row['Reserve'] # 根据实际列名调整
|
||||
password = row['User_pass']
|
||||
branch = row['Reserve'] # 根据实际列名调整
|
||||
semester = row['Reserve'] # 根据实际列名调整
|
||||
wifi_ssid = row['Wifi_SSID']
|
||||
modbus_ip = row['Modbus_IP']
|
||||
modbus_port = row['Modbus_Port']
|
||||
nfc_id = row['NFC_ID']
|
||||
reserve = row['Reserve']
|
||||
|
||||
# 更新界面显示的用户信息
|
||||
self.root.current = "home"
|
||||
self.user.text = f"[b]Hey! {name}[/b]"
|
||||
self.profile_user_name.text = self.edit_name.text = name
|
||||
self.profile_user_pass.text = self.edit_email.text = email
|
||||
self.profile_prn.text = self.edit_prn.text = prn
|
||||
self.profile_wifi_ssid.text = row['Wifi_SSID']
|
||||
self.profile_semester.text = self.edit_semester.text = semester
|
||||
self.profile_branch.text = self.edit_branch.text = branch
|
||||
|
||||
self.profile_user_name.text = self.edit_user_name.text = name
|
||||
self.profile_user_pass.text = self.edit_user_pass.text = password
|
||||
self.profile_wifi_ssid.text = self.edit_wifi_ssid.text = wifi_ssid
|
||||
self.profile_modbus_ip.text = self.edit_modbus_ip.text = modbus_ip
|
||||
self.profile_modbus_port.text = self.edit_modbus_port.text = modbus_port
|
||||
self.profile_nfc_id.text = self.edit_nfc_id.text = nfc_id
|
||||
self.profile_reserve.text = self.edit_reserve.text = reserve
|
||||
|
||||
|
||||
# 连接Modbus设备
|
||||
self.connect_modbus()
|
||||
@ -675,7 +644,7 @@ class app(MDApp):
|
||||
master = None
|
||||
|
||||
try:
|
||||
# 获取当前WiFi SSID(保持不变)
|
||||
# 获取当前WiFi SSID
|
||||
if platform == "android":
|
||||
from jnius import autoclass
|
||||
PythonActivity = autoclass('org.kivy.android.PythonActivity')
|
||||
@ -687,7 +656,7 @@ class app(MDApp):
|
||||
else:
|
||||
current_wifi_id = "zhizhan-2"
|
||||
|
||||
# 读取CSV配置(保持不变)
|
||||
# 读取CSV配置
|
||||
with open("data/Users.csv", "r", encoding="utf-8") as file:
|
||||
csv_reader = csv.DictReader(file)
|
||||
for row in csv_reader:
|
||||
@ -701,16 +670,16 @@ class app(MDApp):
|
||||
Clock.schedule_once(lambda dt: self.dialog1("未找到匹配的Modbus配置"))
|
||||
return
|
||||
|
||||
# 断开现有连接(保持不变)
|
||||
# 断开现有连接
|
||||
self.modbus_master.disconnect()
|
||||
|
||||
# 创建新连接并测试(保持不变)
|
||||
# 创建新连接并测试
|
||||
connect_result = self.modbus_master.connect(modbus_ip, modbus_port)
|
||||
if not connect_result['success']:
|
||||
Clock.schedule_once(lambda dt: self.dialog1(connect_result['msg']))
|
||||
return
|
||||
print(f"Modbus连接成功 (modbus-tk)\nIP: {modbus_ip}\n端口: {modbus_port}")
|
||||
Clock.schedule_once(lambda dt: self.dialog1(f"Modbus连接成功\nIP: {modbus_ip}\n端口: {modbus_port}"))
|
||||
print(f"Modbus连接成功\nIP: {modbus_ip}\n端口: {modbus_port}")
|
||||
# Clock.schedule_once(lambda dt: self.dialog1(f"Modbus连接成功\nIP: {modbus_ip}\n端口: {modbus_port}"))
|
||||
|
||||
except FileNotFoundError as e:
|
||||
# 修复:将异常信息转为字符串或通过默认参数传递
|
||||
@ -722,7 +691,6 @@ class app(MDApp):
|
||||
Clock.schedule_once(lambda dt, msg=err_msg: self.dialog1(msg))
|
||||
self.modbus_master = None
|
||||
except socket.error as e:
|
||||
# 修复:提前格式化错误信息
|
||||
err_msg = f"网络连接失败: {e}"
|
||||
Clock.schedule_once(lambda dt, msg=err_msg: self.dialog1(msg))
|
||||
self.modbus_master = None
|
||||
@ -735,28 +703,32 @@ class app(MDApp):
|
||||
threading.Thread(target=_connect_in_background, daemon=True).start()
|
||||
|
||||
def edit_profile(self):
|
||||
if self.edit_name.text == "" or self.edit_prn.text == "" or self.edit_email.text == "" or self.edit_number.text == "":
|
||||
if self.edit_user_name.text == "" or self.edit_user_pass.text == "" or self.edit_wifi_ssid.text == "" or self.edit_modbus_ip.text == "" or self.edit_modbus_port.text == "" or self.edit_nfc_id.text == "" or self.edit_reserve.text == "":
|
||||
check = "Enter all required fields"
|
||||
return self.dialog1(check)
|
||||
else:
|
||||
user_data = {
|
||||
'User': self.edit_name.text,
|
||||
'User_pass': self.edit_prn.text,
|
||||
'Wifi_SSID': self.edit_email.text,
|
||||
'Modbus_IP': self.edit_number.text,
|
||||
'Modbus_Port': self.password.text,
|
||||
'Reserve_branch': self.edit_branch.text,
|
||||
'Reserve_semester': self.edit_semester.text
|
||||
'User': self.edit_user_name.text,
|
||||
'User_pass': self.edit_user_pass.text,
|
||||
'Wifi_SSID': self.edit_wifi_ssid.text,
|
||||
'Modbus_IP': self.edit_modbus_ip.text,
|
||||
'Modbus_Port': self.edit_modbus_port.text,
|
||||
'NFC_ID': self.edit_nfc_id.text,
|
||||
'Reserve': self.edit_reserve.text
|
||||
}
|
||||
update_user_profile(user_data, self.profile_wifi_ssid.text)
|
||||
self.verify(True)
|
||||
self.root.current = "home"
|
||||
|
||||
def secure_profile(self):
|
||||
self.profile_edit_screen.ids.edit_email.readonly = True
|
||||
self.profile_edit_screen.ids.edit_prn.readonly = True
|
||||
self.profile_edit_screen.ids.edit_no.readonly = True
|
||||
self.profile_edit_screen.ids.edit_private_credential_butn.disabled = False
|
||||
self.profile_edit_screen.ids.edit_user_pass.readonly = True
|
||||
self.profile_edit_screen.ids.edit_wifi_ssid.readonly = True
|
||||
self.profile_edit_screen.ids.edit_modbus_ip.readonly = True
|
||||
self.profile_edit_screen.ids.edit_modbus_port.readonly = True
|
||||
self.profile_edit_screen.ids.edit_nfc_id.readonly = True
|
||||
self.profile_edit_screen.ids.edit_reserve.readonly = False
|
||||
|
||||
|
||||
|
||||
from user_data_manager import update_user_profile
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ class ModbusClient:
|
||||
|
||||
def read_holding_registers(self, slave_id, address, count):
|
||||
if not self.master:
|
||||
return {'success': False, 'data': None, 'msg': "Modbus未初始化,请先连接"}
|
||||
return {'success': False, 'data': None, 'msg': "Modbus未初始化,请先连接"}
|
||||
try:
|
||||
result = self.master.execute(
|
||||
slave=slave_id,
|
||||
@ -52,7 +52,7 @@ class ModbusClient:
|
||||
|
||||
def write_single_register(self, slave_id, address, value):
|
||||
if not self.master:
|
||||
return {'success': False, 'msg': "Modbus未连接,请先初始化连接"}
|
||||
return {'success': False, 'msg': "Modbus未连接,请先初始化连接"}
|
||||
if value is None:
|
||||
return {'success': False, 'msg': "未指定要写入的值"}
|
||||
try:
|
||||
|
||||
@ -2,10 +2,10 @@ import csv
|
||||
|
||||
def update_user_profile(user_data, profile_wifi_ssid):
|
||||
"""
|
||||
Updates user profile information in the Users.csv file.
|
||||
Args:
|
||||
user_data (dict): A dictionary containing user profile data (e.g., 'User', 'User_pass', etc.).
|
||||
profile_wifi_ssid (str): The Wifi_SSID of the user to update.
|
||||
更新Users.csv文件中的用户配置文件信息。
|
||||
参数:
|
||||
user_data:一个包含用户配置文件数据的字典
|
||||
profile_wifi_ssid:要更新的用户的Wifi_SSID
|
||||
"""
|
||||
with open('data/Users.csv', "r", encoding="utf-8") as file:
|
||||
csv_reader = csv.DictReader(file, delimiter=",")
|
||||
@ -18,18 +18,12 @@ def update_user_profile(user_data, profile_wifi_ssid):
|
||||
row['Wifi_SSID'] = user_data['Wifi_SSID']
|
||||
row['Modbus_IP'] = user_data['Modbus_IP']
|
||||
row['Modbus_Port'] = user_data['Modbus_Port']
|
||||
# The original code had 'Reserve' overwritten twice. Assuming it's a single 'Reserve' column.
|
||||
# If there are two distinct 'Reserve' fields (e.g., branch and semester), the CSV header and logic need clarification.
|
||||
# For now, I'll use the last assigned value for 'Reserve' as per original logic.
|
||||
row['Reserve'] = user_data['Reserve_branch'] # Assuming this is for branch
|
||||
row['Reserve'] = user_data['Reserve_semester'] # This will overwrite the previous 'Reserve' value
|
||||
row['NFC_ID'] = user_data['NFC_ID']
|
||||
row['Reserve'] = user_data['Reserve']
|
||||
break
|
||||
|
||||
with open('data/Users.csv', newline="", mode="w", encoding="utf-8") as file:
|
||||
# The original header had two 'Reserve' columns. This is unusual for CSV and might be a typo.
|
||||
# I will use a single 'Reserve' column as it's more common, or clarify if two are truly needed.
|
||||
# Based on the original code, it seems like the second 'Reserve' assignment overwrites the first.
|
||||
header = ["User", "User_pass", "Wifi_SSID", "Modbus_IP", "Modbus_Port", "Reserve"]
|
||||
header = ["User", "User_pass", "Wifi_SSID", "Modbus_IP", "Modbus_Port", "NFC_ID", "Reserve"]
|
||||
csv_writer = csv.DictWriter(file, fieldnames=header)
|
||||
csv_writer.writeheader()
|
||||
csv_writer.writerows(rows)
|
||||
Reference in New Issue
Block a user