【开源】基于迪文屏的新冠核酸采样登记系统
该方案是基于迪文屏开发的一款核酸采样登记的系统,使用了两块屏幕,一块用于登记、一块用于采样确认。开发目的是使用迪文屏当作输入窗口,替代原先手工填写表格,提高数据质量,减少群众等待时间等,在此向迪文及广大网友将所有的源码、素材开源如下:
一、前言 我是一名新冠肺炎防控一线的白衣战士,同时也是一名软硬件开发的工程师,在上次电子发烧友的迪文智慧屏的试用活动中,我与迪文屏相识,当时开发出的一个小作品得到了优秀作品奖。于是我产生了用迪文屏给我们单位采样室做一款核酸采样登记的系统,于是加班加点开始项目的研发,从项目开始到现在快40天,这40天来早上6点起来、下班后加班到晚上11点,写代码、调试,终于项目有了开发结果,经过两次实战,成功上线。得到单位领导、同事、以及采集群众的认可,效果非常好! 【材料】迪文屏10.1寸、7寸智慧串口屏各1块,笔记本电脑一台。 【软件】DGUS_V7.637,Python
主登记台
采样确认台
效果合照
二、设计过程
(一)架构设想 这次我在迪文官方申请到了两块屏,用于制作一个新冠核酸采样的登记系统。我的日常有一项工作就是核酸采样,以前都是用手工登记姓名、手机号码等。然后拿到登记表后还要人工转成电子表格才能完成送样。在工作中遇到有些人写的字不是很工整,难以辩认。我前段时间参与了迪文屏有评测,就想出了设计一个核酸登记系统的想法,这个想法得到迪文的认可,我申请了两块屏。今天屏已经到了,下面就记录一下我的开发记录。 【架构设想】PC端用python与两块迪文屏建立串口通讯。Python提供查询数据、接收数据、最后生成送样的excel文件。迪文屏负责与采样人以及被采样人的交互。 今天先晒晒我收到的屏:屏的包装非常好,专业水准呀,这里给迪文的点赞。 这个是10.1寸的型号:DMG10600C101-03WTC是一块电容触摸屏。 这是两块屏的全家福,还送了转接线、16G的转接卡、USB数据线。 最后,再次感谢迪文屏的支持。其如果你有好的创意,也可以跟他们申请哦。作品还可以发到迪文论坛,每个月都评选优秀作品,还有机会得大奖! (二)UI人机界面设计 串口屏开发,先是要制作背景图片。今天花了好几个小时整好了部份图片: 2.1 输入手机号查找档案: 2.2 输入身份证查找界面: 2.3 如果没有在数据库找到信息,进行自主登记界面 2.4 身份证录入键盘 2.5 这个是查到到信息,确认的界面: 因为不懂PS,花了很大的心思的才弄好。大家给点建议呀,或者有好的素材借给我用用哈! (三)连上迪文云 几天没有更新帖子了,一来是单位的任务繁重,忙了一天回来不想动了;二来是等屏的wifi模块回来。昨天焊了wifi模块跟其他的几个元件,焊0603的还好,焊0403的电容,搞了半天,电容没焊成,原因是人老眼花,用风枪吹一下就跑了,用焊台就看不见,头大。所以想买一套好的设备,不服老不行呀。但是wifi模块还是成功工作了,也成功的连上了迪文云,实现数据互动。今天在这里小结一下: 3.1 我申请的屏是支持wifi,但是出厂默认是不带模块的,我上迪文的官方淘宝准备买wifi模块,细心的小姐姐提前跟我说还需要其他几个元件才行,我于是联系迪云的业务员,买了3个模块(其实只要两个,我是留一个做预备),附带给我申请了三个配套的元件。这里给大家展示一下前后的对比哈: 焊接前: 焊接后: 我这焊工纯属入门级的呀。有点惨吧。。。 3.2 在迪文云上申请帐号,创建自己的帐号跟产品: 拿到生产商地址、设备分类地址、产品编号地址后改写22_config.bin 注意在bin中的地址要用变量地址乘2:即0x822 \0x0826 0x828 如果有需要可以去看看。 然后,配置wifiSSD\密码就可以啦,很简单滴: 展示一下,咱们看视频吧: 视频展示链接:http://bbs.eeworld.com.cn/thread-1200897-1-1.html 下一步,实现mqtt与后台数据的交换。 (四)查询数据并显示 今天要实现的功能是输入身份证号号码或者手机号码查询出资料,并显示在迪云屏上面: 实现思路是输入手机号码或者身份证号,点击查询,然后通过串口上传到PC,PC接收到命令后读取存储手机或身份证的地址上取回数据,读取excel的数据进行对比。 【python代码】 - import time
- import serial #导入模块
- import threading
- from win32com.client import Dispatch
- import pythoncom
- from excel import *
- STRGLO="" #读取的数据
- BOOL=True #读取标志位
- import win32com.client
- cmd_read_phone = bytes([0x5a, 0xa5, 0x04, 0x83, 0x10, 0x60, 0x13])
- cmd_read_ID_number = bytes([0x5a, 0xa5, 0x04, 0x83, 0x10, 0x20, 0x18])
- cmd_write_to_enter_page = bytes([0x5a, 0xa5, 0x07, 0x82, 0x00, 0x84, 0x5a, 0x01, 0x00, 0x03])
- send_list = [0x5a, 0xa5, 0x00, 0x00, 0x00, 0x00]
- # 姓名数据组装
- def creat_gbk_list(mydata, my_commad, H_address,L_address):
- # 发送的list
- send_list = [0x5a, 0xa5, 0x00, 0x00, 0x00, 0x00]
- send_len = 1 + 2 + 2 + len(mydata)*2
- send_list[2] = send_len
- # 添加 命令
- send_list[3] = my_commad
- send_list[4] = H_address
- send_list[5] = L_address
- mysend_list = bytes(send_list) + mydata.encode("gbk") + b'\xFF\xFF'
- print(mysend_list)
- DWritePort(ser, mysend_list)
- def ReadData(ser):
- while BOOL:
- if ser.in_waiting:
- #STRGLO = ser.read(ser.in_waiting).decode("gbk")
- STRGLO = ser.read(ser.in_waiting)
- # print(STRGLO)
- # print("长度为:" + str(len(STRGLO)))
- if STRGLO[0] == 0x5a and STRGLO[1] == 0xa5:
- #获取地址
- addres = STRGLO[4] << 8 | STRGLO[5]
- commd = STRGLO[3]
- recv_len = STRGLO[2]
- print("地址为:" + hex(addres) + " 长度为:" + str(recv_len) + " 命令为:" + hex(commd))
- if recv_len == 0x06 and commd == 0x83:
- if addres == 0x1080:
- print("按身手机号码查询")
- # 读取手机号码数据
- DWritePort(ser, cmd_read_phone)
- elif addres == 0x1090:
- print("按身份证查询")
- DWritePort(ser, cmd_read_ID_number)
- elif commd == 0x83 and recv_len == 42 and addres == 0x1060:
- # print("接收到手机号码")
- recv_phone_len = STRGLO[6]
- if(recv_phone_len == 0x13):
- str_ph = STRGLO[7:18]
- phone_code = str_ph.decode()
- # 开始查找是否有手机号存在
- pythoncom.CoInitialize()
- try:
- xls = easyExcel(r'H:\疫情登记项目\pythonpro\核酸数据库.xlsx')
- xls_phone_code = str(int(xls.getCell('Sheet1', 2, 3)))
- if xls_phone_code == phone_code:
- #获取身份证号码
- # 写性别
- my_xb = xls.getCell('Sheet1', 2, 5)
- creat_gbk_list(my_xb, 0x82, 0x11, 0x20)
- my_sh = str(int(xls.getCell('Sheet1', 2, 4)))
- creat_gbk_list(my_sh, 0x82, 0x10, 0x20)
- # 写职业
- my_job = xls.getCell('Sheet1', 2, 6)
- creat_gbk_list(my_job, 0x82, 0x11, 0x40)
- # 写姓名
- my_name = xls.getCell('Sheet1', 2, 2)
- creat_gbk_list(my_name, 0x82, 0x11, 0x60)
- # 写职业
- my_job = xls.getCell('Sheet1', 2, 6)
- creat_gbk_list(my_job, 0x82, 0x11, 0x40)
- # 页面转移到确认页面
- # 写姓名
- my_name = xls.getCell('Sheet1', 2, 2)
- creat_gbk_list(my_name, 0x82, 0x11, 0x60)
- DWritePort(ser, cmd_write_to_enter_page)
- xls.close()
- except Exception as e:
- print("出错啦:" + str(e))
- xls.close()
- pythoncom.CoUninitialize()
- else:
- print("接收到的电话号码长度不对 长度为:" + str((recv_phone_len-8)))
- # 查找手机号
- elif commd == 0x83 and recv_len == 52 and addres == 0x1020:
- print("接收到手机号码")
- recv_ID_len = STRGLO[6]
- if(recv_ID_len == 0x18):
- str_ID = STRGLO[7:25]
- str_ID = str_ID.decode()
- # 开始查找是否有手机号存在
- pythoncom.CoInitialize()
- try:
- xls = easyExcel(r'H:\疫情登记项目\pythonpro\核酸数据库.xlsx')
- ID_code = str(int(xls.getCell('Sheet1', 2, 4)))
- if ID_code == str_ID:
- # 写性别
- my_xb = xls.getCell('Sheet1', 2, 5)
- creat_gbk_list(my_xb, 0x82, 0x11, 0x20)
- #获取手机号码
- my_phone = str(int(xls.getCell('Sheet1', 2, 3)))
- creat_gbk_list(my_phone, 0x82, 0x10, 0x60)
- # 写职业
- my_job = xls.getCell('Sheet1', 2, 6)
- creat_gbk_list(my_job, 0x82, 0x11, 0x40)
- # 写职业
- my_job = xls.getCell('Sheet1', 2, 6)
- creat_gbk_list(my_job, 0x82, 0x11, 0x40)
- # 写姓名
- my_name = xls.getCell('Sheet1', 2, 2)
- creat_gbk_list(my_name, 0x82, 0x11, 0x60)
- # 页面转移到确认页面
- DWritePort(ser, cmd_write_to_enter_page)
- xls.close()
- except Exception as e:
- print("出错啦:" + str(e))
- xls.close()
- pythoncom.CoUninitialize()
- else:
- print("接收到的电话号码长度不对 长度为:" + str((recv_phone_len-8)))
- # 查找手机号码
- else:
- print("非法数据")
- #打开串口
- # 端口,GNU / Linux上的/ dev / ttyUSB0 等 或 Windows上的 COM3 等
- # 波特率,标准值之一:50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600,19200,38400,57600,115200
- # 超时设置,None:永远等待操作,0为立即返回请求结果,其他值为等待超时时间(单位为秒)
- def DOpenPort(portx,bps,timeout):
- ret=False
- try:
- # 打开串口,并得到串口对象
- ser = serial.Serial(portx, bps, timeout=timeout)
- #判断是否打开成功
- if(ser.is_open):
- ret=True
- threading.Thread(target=ReadData, args=(ser,)).start()
- except Exception as e:
- print("---异常---:", e)
- return ser, ret
- #关闭串口
- def DColsePort(ser):
- global BOOL
- BOOL=False
- ser.close()
- #写数据
- def DWritePort(ser,text):
- result = ser.write(text) # 写数据
- return result
- #读数据
- def DReadPort():
- global STRGLO
- str=STRGLO
- STRGLO="" #清空当次读取
- return str
- def reade_excel():
- global STRGLO,BOOL
- # 循环接收数据,此为死循环,可用线程实现
- try:
- xls = easyExcel(r'H:\疫情登记项目\pythonpro\核酸数据库.xlsx')
- xls_phone_code = str(int(xls.getCell('Sheet1', 2, 3)))
- xls.close()
- return xls_phone_code
- except Exception as e:
- print("出错啦:" + str(e))
- if __name__=="__main__":
- ser,ret=DOpenPort("COM18",115200,None)
- if(ret==True):#判断串口是否成功打开
- print("打开串口成功1")
- reade_excel()
- # count=DWritePort(ser,"我是东小东,哈哈")
- # print("写入字节数:",count)
- #DReadPort() #读串口数据
- #DColsePort(ser) #关闭串口
复制代码excel文件: 查询界面: 新建档案界面 数据确认界面: 目前做可以查询档案,具体多数据库查询待后一步: 效果展示视频链接:http://bbs.eeworld.com.cn/thread-1201503-1-1.html (五)数据保存 优化了python代码,实现了查数的查询,数据的保存: - import time
- import serial # 导入模块
- import threading
- from win32com.client import Dispatch
- import pythoncom
- from excel import *
- STRGLO = "" # 读取的数据
- BOOL = True # 读取标志位
- import win32com.client
- cmd_read_phone = bytes([0x5a, 0xa5, 0x04, 0x83, 0x10, 0x60, 0x13])
- cmd_read_ID_number = bytes([0x5a, 0xa5, 0x04, 0x83, 0x10, 0x20, 0x18])
- cmd_write_to_enter_page = bytes([0x5a, 0xa5, 0x07, 0x82, 0x00, 0x84, 0x5a, 0x01, 0x00, 0x10])
- cmd_write_to_main_page = bytes([0x5a, 0xa5, 0x07, 0x82, 0x00, 0x84, 0x5a, 0x01, 0x00, 0x00])
- send_list = [0x5a, 0xa5, 0x00, 0x00, 0x00, 0x00]
- all_range = None
- """
- # 等待接收命令: wait_infor
- # 查询状态 query_infor
- # 确认信息: confirmation_infor
- # 保存信息: save_infor
- """
- work_state = 'wait_enter'
- dict_in_data = {
- 'tube_number': '',
- 'name': '',
- 'phone': '',
- 'ID': '',
- 'sex': '',
- 'company': '',
- 'test_date': ''
- }
- # 姓名数据组装
- def creat_gbk_list(mydata, my_commad, H_address, L_address):
- # 发送的list
- send_list = [0x5a, 0xa5, 0x00, 0x00, 0x00, 0x00]
- send_len = 1 + 2 + 2 + len(mydata) * 2
- send_list[2] = send_len
- # 添加 命令
- send_list[3] = my_commad
- send_list[4] = H_address
- send_list[5] = L_address
- mysend_list = bytes(send_list) + mydata.encode("gbk") + b'\xFF\xFF'
- print(mysend_list)
- DWritePort(ser, mysend_list)
- def ReadData(ser):
- global all_range, work_state
- while BOOL:
- if ser.in_waiting:
- # STRGLO = ser.read(ser.in_waiting).decode("gbk")
- STRGLO = ser.read(ser.in_waiting)
- # print(STRGLO)
- # print("长度为:" + str(len(STRGLO)))
- if STRGLO[0] == 0x5a and STRGLO[1] == 0xa5:
- # 获取地址
- addres = STRGLO[4] << 8 | STRGLO[5]
- commd = STRGLO[3]
- recv_len = STRGLO[2]
- print("地址为:" + hex(addres) + " 长度为:" + str(recv_len) + " 命令为:" + hex(commd))
- if recv_len == 0x06 and commd == 0x83:
- if addres == 0x1080:
- print("按身手机号码查询")
- # 读取手机号码数据
- work_state = 'query_infor'
- DWritePort(ser, cmd_read_phone)
- elif addres == 0x1090:
- print("按身份证查询")
- work_state = 'query_infor'
- DWritePort(ser, cmd_read_ID_number)
- elif addres == 0x1200 and work_state == 'wait_enter':
- # 增加时间,保存数据
- pythoncom.CoInitialize()
- save_test_file(my_data)
- pythoncom.CoUninitialize()
- print("保存数据")
- work_state = 'query_infor'
- my_data = dict_in_data
- # 转到主页面
- DWritePort(ser, cmd_write_to_main_page)
- elif commd == 0x83 and recv_len == 42 and addres == 0x1060 and work_state == 'query_infor':
- # print("接收到手机号码")
- recv_phone_len = STRGLO[6]
- if (recv_phone_len == 0x13):
- str_ph = STRGLO[7:18]
- phone_code = str_ph.decode()
- # 开始查找是否有手机号存在
- my_index = None
- try:
- for index, value in enumerate(all_range):
- xls_phone_code = str(int(value[2]))
- if phone_code == xls_phone_code:
- my_index = index
- break
- if xls_phone_code == phone_code and (my_index is not None):
- my_data = dict_in_data
- my_data['name'] = all_range[my_index][1]
- my_data['sex'] = all_range[my_index][4]
- my_data['company'] = all_range[my_index][5]
- my_data['phone'] = xls_phone_code
- my_data['ID'] = all_range[my_index][3]
- creat_gbk_list(my_data['sex'], 0x82, 0x11, 0x20)
- creat_gbk_list(my_data['ID'], 0x82, 0x10, 0x20)
- creat_gbk_list(my_data['company'], 0x82, 0x11, 0x40)
- creat_gbk_list(my_data['name'], 0x82, 0x11, 0x60)
- creat_gbk_list(my_data['company'], 0x82, 0x11, 0x40)
- creat_gbk_list(my_data['name'], 0x82, 0x11, 0x60)
- # 页面转移到确认页面 为什么要写两遍,BUG——
- DWritePort(ser, cmd_write_to_enter_page)
- DWritePort(ser, cmd_write_to_enter_page)
- work_state = 'wait_enter'
- except Exception as e:
- print("出错啦:" + str(e))
- else:
- print("接收到的电话号码长度不对 长度为:" + str((recv_phone_len - 8)))
- # 查找手机号
- elif commd == 0x83 and recv_len == 52 and addres == 0x1020 and work_state == 'query_infor':
- print("接收到身份证号码")
- recv_ID_len = STRGLO[6]
- if (recv_ID_len == 0x18):
- str_ID = STRGLO[7:25]
- str_ID = str_ID.decode()
- # 开始查找是否有手机号存在
- try:
- my_index = None
- for index, value in enumerate(all_range):
- xls_ID_code = str(int(value[3]))
- if str_ID == xls_ID_code:
- my_index = index
- break
- if xls_ID_code == str_ID:
- # 写性别
- my_data = dict_in_data
- my_data['name'] = all_range[my_index][1]
- my_data['sex'] = all_range[my_index][4]
- my_data['company'] = all_range[my_index][5]
- my_data['phone'] = all_range[my_index][2]
- my_data['ID'] = xls_ID_code
- creat_gbk_list(my_data['sex'], 0x82, 0x11, 0x20)
- creat_gbk_list(my_data['phone'], 0x82, 0x10, 0x60)
- creat_gbk_list(my_data['company'], 0x82, 0x11, 0x40)
- creat_gbk_list(my_data['name'], 0x82, 0x11, 0x60)
- creat_gbk_list(my_data['company'], 0x82, 0x11, 0x40)
- creat_gbk_list(my_data['name'], 0x82, 0x11, 0x60)
- # 页面转移到确认页面 为什么要写两遍,BUG——
- DWritePort(ser, cmd_write_to_enter_page)
- DWritePort(ser, cmd_write_to_enter_page)
- work_state = 'wait_enter'
- except Exception as e:
- work_state = 'wait_enter'
- print("出错啦:" + str(e))
- else:
- work_state = 'wait_enter'
- print("接收到的电话号码长度不对 长度为:" + str((recv_phone_len - 8)))
- else:
- print("非法数据")
- # 打开串口
- # 端口,GNU / Linux上的/ dev / ttyUSB0 等 或 Windows上的 COM3 等
- # 波特率,标准值之一:50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600,19200,38400,57600,115200
- # 超时设置,None:永远等待操作,0为立即返回请求结果,其他值为等待超时时间(单位为秒)
- def DOpenPort(portx, bps, timeout):
- ret = False
- try:
- # 打开串口,并得到串口对象
- ser = serial.Serial(portx, bps, timeout=timeout)
- # 判断是否打开成功
- if (ser.is_open):
- ret = True
- threading.Thread(target=ReadData, args=(ser,)).start()
- except Exception as e:
- print("---异常---:", e)
- return ser, ret
- # 关闭串口
- def DColsePort(ser):
- global BOOL
- BOOL = False
- ser.close()
- # 写数据
- def DWritePort(ser, text):
- result = ser.write(text) # 写数据
- return result
- # 读数据
- def DReadPort():
- global STRGLO
- str = STRGLO
- STRGLO = "" # 清空当次读取
- return str
- def reade_excel():
- global all_range
- # 循环接收数据,此为死循环,可用线程实现
- try:
- my_xls = easyExcel(r'H:\疫情登记项目\pythonpro\核酸数据库.xlsx')
- cols = my_xls.getCols('Sheet1')
- print("总列数为:" + str(cols))
- rows = my_xls.getRows('Sheet1') - 1
- print("总行数为:" + str(rows))
- # 获取全部数据到内存
- all_range = my_xls.getRange('Sheet1', 2, 1, rows - 1, cols)
- my_xls.close()
- except Exception as e:
- print("出错啦:" + str(e))
- # 保存数据
- def save_test_file(data):
- # 先检查是否有文件,没有新建一个,有测打开
- """
- :param data: dict_in_data = {
- 'tube_number': '',
- 'name': '',
- 'phone': '',
- 'ID': '',
- 'sex': '',
- 'company': '',
- 'test_date': ''
- }
- :return: None
- """
- try:
- save_xls = easyExcel(r'H:\疫情登记项目\pythonpro\送检单.xlsx')
- max_row = save_xls.getRows('Sheet1')
- if max_row == 1:
- print("当天第一次写数据,初始化一下")
- # 试号管为 1
- data['tube_number'] = 1
- this_row = 1
- else:
- tube = save_xls.getCell('Sheet1', max_row, 2)
- this_row = save_xls.getCell('Sheet1', max_row, 2)
- if (this_row % 10) == 0: # 10混1
- tube = tube + 1
- # 表行号增加一行
- max_row = max_row + 1
- save_xls.setCell('Sheet1', max_row, 1, this_row) # 增加序号
- save_xls.setCell('Sheet1', max_row, 2, data['tube_number']) # 增加管号
- save_xls.setCell('Sheet1', max_row, 3, data['name']) # 增加姓名
- save_xls.setCell('Sheet1', max_row, 4, data['sex']) # 增加性别
- save_xls.setCell('Sheet1', max_row, 5, data['phone']) # 增加电话号码
- save_xls.setCell('Sheet1', max_row, 6, data['ID']) # 增加身份证号
- save_xls.setCell('Sheet1', max_row, 7, data['company']) # 增加单位
- save_xls.setCell('Sheet1', max_row, 8, time.strftime("%Y-%m-%d", time.localtime())) # 增加检测时间
- save_xls.save()
- save_xls.close()
- except Exception as e:
- save_xls.close()
- print("保存数据出错:" + str(e))
- if __name__ == "__main__":
- ser, ret = DOpenPort("COM18", 115200, None)
- if (ret == True): # 判断串口是否成功打开
- print("打开串口成功1")
- reade_excel()
复制代码修改了数据确认页面: 基本功能实现50%了,展示一下: 查到数据的界面: 没有添加数据的表格: 成功录入数据以后的表格: 下一步,新建信息的录入,还有一些弹出菜单提示等 效果展示视频链接:http://bbs.eeworld.com.cn/thread-1201641-1-1.html (六)增加采样工作台 上个星期去单位试用了,没有正式投入,这个星期再进行改进,增加了采样工作站。 采样站的主要功能就是被采样人登记好后,会在采样工作显示姓名,采样到第一个试管了,序号是多少,好核实信息等等。采样完后发送信号给服务器,服务清空数据,等待下一个采样人员进行登记。 服务器代码已经更新可以同时操作两个串口: - import os
- import sys
- import time
- import serial # 导入模块
- import threading
- from win32com.client import Dispatch
- import pythoncom
- from excel import *
- STRGLO = "" # 读取的数据
- BOOL = True # 读取标志位
- ser10 = None
- ser7 = None
- import win32com.client
- cmd_read_phone = bytes([0x5a, 0xa5, 0x04, 0x83, 0x10, 0x60, 0x13])
- cmd_read_ID_number = bytes([0x5a, 0xa5, 0x04, 0x83, 0x10, 0x20, 0x18])
- cmd_write_to_enter_page = bytes([0x5a, 0xa5, 0x07, 0x82, 0x00, 0x84, 0x5a, 0x01, 0x00, 0x10])
- cmd_write_to_main_page = bytes([0x5a, 0xa5, 0x07, 0x82, 0x00, 0x84, 0x5a, 0x01, 0x00, 0x00])
- cmd_write_to_waite_page = bytes([0x5a, 0xa5, 0x07, 0x82, 0x00, 0x84, 0x5a, 0x01, 0x00, 0x12])
- send_list = [0x5a, 0xa5, 0x00, 0x00, 0x00, 0x00]
- all_range = None
- """
- # 等待接收命令: wait_infor
- # 查询状态 query_infor
- # 确认信息: confirmation_infor
- # 保存信息: save_infor
- """
- work_state = 'wait_enter'
- path = sys.path[0]
- dict_in_data = {
- 'tube_number': '',
- 'name': '',
- 'phone': '',
- 'ID': '',
- 'sex': '',
- 'company': '',
- 'test_date': ''
- }
- save_dict = None
- # 姓名数据组装
- def creat_gbk_list(mydata, my_commad, H_address, L_address, ser):
- # 发送的list
- send_list = [0x5a, 0xa5, 0x00, 0x00, 0x00, 0x00]
- send_len = 1 + 2 + 2 + len(mydata) * 2
- send_list[2] = send_len
- # 添加 命令
- send_list[3] = my_commad
- send_list[4] = H_address
- send_list[5] = L_address
- mysend_list = bytes(send_list) + mydata.encode("gbk") + b'\xFF\xFF'
- print(mysend_list)
- DWritePort(ser, mysend_list)
- # 清空数据
- def clear_show_data():
- dict_in_data['name'] = ''
- dict_in_data['sex'] = ''
- dict_in_data['company'] = ''
- dict_in_data['phone'] = ''
- dict_in_data['phone'] = ''
- dict_in_data['ID'] = ''
- creat_gbk_list(dict_in_data['sex'], 0x82, 0x11, 0x20, ser10)
- creat_gbk_list(dict_in_data['phone'], 0x82, 0x10, 0x60, ser10)
- creat_gbk_list(dict_in_data['company'], 0x82, 0x11, 0x40, ser10)
- creat_gbk_list(dict_in_data['name'], 0x82, 0x11, 0x60, ser10)
- creat_gbk_list(dict_in_data['company'], 0x82, 0x11, 0x40, ser10)
- creat_gbk_list(dict_in_data['name'], 0x82, 0x11, 0x60, ser10)
- creat_gbk_list(dict_in_data['ID'], 0x82, 0x10, 0x20, ser10)
- # 清理护士站的
- creat_gbk_list(dict_in_data['name'], 0x82, 0x20, 0x20, ser7)
- def ReadData(ser):
- global all_range, work_state, dict_in_data, ser10,ser7
- while BOOL:
- if ser.in_waiting:
- # STRGLO = ser.read(ser.in_waiting).decode("gbk")
- STRGLO = ser.read(ser.in_waiting)
- print(STRGLO)
- print(ser)
- print("长度为:" + str(len(STRGLO)))
- if STRGLO[0] == 0x5a and STRGLO[1] == 0xa5:
- # 获取地址
- addres = STRGLO[4] << 8 | STRGLO[5]
- commd = STRGLO[3]
- recv_len = STRGLO[2]
- print("地址为:" + hex(addres) + " 长度为:" + str(recv_len) + " 命令为:" + hex(commd))
- try:
- if recv_len == 0x06 and commd == 0x83:
- if addres == 0x1080:
- print("按手机号码查询")
- # 读取手机号码数据
- print("手机号码为:" + dict_in_data['phone'])
- my_index = None
- try:
- for index, value in enumerate(all_range):
- xls_phone_code = str(int(value[2]))
- if phone_code == xls_phone_code:
- my_index = index
- break
- if xls_phone_code == phone_code and (my_index is not None):
- dict_in_data['name'] = all_range[my_index][1]
- dict_in_data['sex'] = all_range[my_index][4]
- dict_in_data['company'] = all_range[my_index][5]
- dict_in_data['ID'] = all_range[my_index][3]
- creat_gbk_list(dict_in_data['sex'], 0x82, 0x11, 0x20, ser10)
- creat_gbk_list(dict_in_data['ID'], 0x82, 0x10, 0x20, ser10)
- creat_gbk_list(dict_in_data['company'], 0x82, 0x11, 0x40, ser10)
- creat_gbk_list(dict_in_data['name'], 0x82, 0x11, 0x60, ser10)
- creat_gbk_list(dict_in_data['company'], 0x82, 0x11, 0x40, ser10)
- creat_gbk_list(dict_in_data['name'], 0x82, 0x11, 0x60, ser10)
- # 页面转移到确认页面 为什么要写两遍,BUG——
- DWritePort(ser10, cmd_write_to_enter_page)
- DWritePort(ser10, cmd_write_to_enter_page)
- except Exception as e:
- print("出错啦:" + str(e))
- elif addres == 0x1090:
- print("按身份证查询")
- print("身份证号码为:" + dict_in_data['ID'])
- try:
- my_index = None
- for index, value in enumerate(all_range):
- xls_ID_code = value[3]
- if dict_in_data['ID'] == xls_ID_code:
- my_index = index
- break
- dict_in_data['name'] = all_range[my_index][1]
- dict_in_data['sex'] = all_range[my_index][4]
- dict_in_data['company'] = all_range[my_index][5]
- dict_in_data['phone'] = str(int(all_range[my_index][2]))
- creat_gbk_list(dict_in_data['sex'], 0x82, 0x11, 0x20, ser10)
- creat_gbk_list(dict_in_data['phone'], 0x82, 0x10, 0x60, ser10)
- creat_gbk_list(dict_in_data['company'], 0x82, 0x11, 0x40, ser10)
- creat_gbk_list(dict_in_data['name'], 0x82, 0x11, 0x60, ser10)
- creat_gbk_list(dict_in_data['company'], 0x82, 0x11, 0x40, ser10)
- creat_gbk_list(dict_in_data['name'], 0x82, 0x11, 0x60, ser10)
- # 页面转移到确认页面 为什么要写两遍,BUG——
- # 页面转移到确认页面 为什么要写两遍,BUG——
- DWritePort(ser10, cmd_write_to_enter_page)
- DWritePort(ser10, cmd_write_to_enter_page)
- except Exception as e:
- print("出错啦:" + str(e))
- # DWritePort(ser, cmd_read_ID_number)
- elif addres == 0x1200:
- # 增加时间,保存数据
- print("确认登记数据")
- # 转到等待画面
- DWritePort(ser10, cmd_write_to_waite_page)
- DWritePort(ser10, cmd_write_to_waite_page)
- pythoncom.CoInitialize()
- tub, xh = save_test_file(dict_in_data)
- pythoncom.CoUninitialize()
- if tub is not None:
- creat_gbk_list(dict_in_data['name'], 0x82, 0x20, 0x20, ser7)
- creat_gbk_list(str(int(tub)), 0x82, 0x20, 0x40, ser7)
- creat_gbk_list(str(int(tub)), 0x82, 0x20, 0x40, ser7)
- creat_gbk_list(str(xh), 0x82, 0x20, 0x60, ser7)
- creat_gbk_list(str(xh), 0x82, 0x20, 0x60, ser7)
- else:
- # 弹出失败
- pass
- # 转到主页面
- elif addres == 0x1210:
- print('保存数据')
- pythoncom.CoInitialize()
- save_state = save_infor_file(dict_in_data)
- reade_excel()
- pythoncom.CoUninitialize()
- DWritePort(ser, cmd_write_to_enter_page)
- elif addres == 0x2004:
- clear_show_data()
- DWritePort(ser10, cmd_write_to_main_page)
- elif commd == 0x83 and recv_len == 0x12 and addres == 0x1060:
- print("接收到手机号码")
- recv_phone_len = STRGLO[6]
- if recv_phone_len == 0x07:
- str_ph = STRGLO[7:18]
- phone_code = str_ph.decode()
- # 开始查找是否有手机号存在
- dict_in_data['phone'] = phone_code
- else:
- print("接收到的电话号码长度不对 长度为:" + str((recv_phone_len - 8)))
- elif commd == 0x83 and recv_len == 24 and addres == 0x1020:
- print("接收到身份证号码")
- recv_ID_len = STRGLO[6]
- if recv_ID_len == 10:
- dict_in_data['ID'] = STRGLO[7:25].decode()
- else:
- print("接收到的身份证长度不对 长度为:" + str((recv_ID_len - 8)))
- elif commd == 0x83 and addres == 0x1160:
- # 接收到姓名
- recv_name_len = STRGLO[6] - 1
- if 0 < recv_name_len < 5:
- dict_in_data['name'] = (STRGLO[7:(7 + recv_name_len * 2)]).decode("gbk")
- else:
- print("姓名的长度不符合")
- print(dict_in_data['name'])
- elif commd == 0x83 and addres == 0x1140:
- # 接收到姓名
- recv_company_len = STRGLO[6] - 1
- if 1 < recv_company_len < 6:
- dict_in_data['company'] = (STRGLO[7:(7 + recv_company_len * 2)]).decode("gbk")
- else:
- print("单位的长度不符合")
- print(dict_in_data['company'])
- elif commd == 0x83 and addres == 0x1120:
- # 接收到性别
- recv_sex_len = STRGLO[6]
- if recv_sex_len == 2:
- str_sex = (STRGLO[7:9]).decode("gbk")
- if str_sex == '男' or str_sex == '女':
- dict_in_data['sex'] = str_sex
- else:
- print("性别必须为男或者女")
- dict_in_data['sex'] = ''
- else:
- print("姓名的长度不符合")
- print(dict_in_data['sex'])
- except Exception as e:
- print(str(e))
- else:
- print("非法数据")
- # 打开串口
- # 端口,GNU / Linux上的/ dev / ttyUSB0 等 或 Windows上的 COM3 等
- # 波特率,标准值之一:50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600,19200,38400,57600,115200
- # 超时设置,None:永远等待操作,0为立即返回请求结果,其他值为等待超时时间(单位为秒)
- def DOpenPort(portx, bps, timeout):
- ret = False
- try:
- # 打开串口,并得到串口对象
- ser = serial.Serial(portx, bps, timeout=timeout)
- # 判断是否打开成功
- if (ser.is_open):
- ret = True
- threading.Thread(target=ReadData, args=(ser,)).start()
- except Exception as e:
- print("---异常---:", e)
- return ser, ret
- # 关闭串口
- def DColsePort(ser):
- global BOOL
- BOOL = False
- ser.close()
- # 写数据
- def DWritePort(ser, text):
- result = ser.write(text) # 写数据
- return result
- # 读数据
- def DReadPort():
- global STRGLO
- str = STRGLO
- STRGLO = "" # 清空当次读取
- return str
- def reade_excel():
- global all_range
- # 循环接收数据,此为死循环,可用线程实现
- try:
- print(path)
- my_xls_path = path + '\核酸数据库.xlsx'
- my_xls = easyExcel(my_xls_path)
- cols = my_xls.getCols('Sheet1')
- print("总列数为:" + str(cols))
- rows = my_xls.getRows('Sheet1') + 1
- print("总行数为:" + str(rows))
- # 获取全部数据到内存
- all_range = my_xls.getRange('Sheet1', 2, 1, rows - 1, cols)
- my_xls.close()
- except Exception as e:
- print("出错啦:" + str(e))
- # 保存基本信息数据
- def save_infor_file(data):
- try:
- my_xls_path = path + '\核酸数据库.xlsx'
- save_infor_xls = easyExcel(my_xls_path)
- rows = save_infor_xls.getRows('Sheet1') + 1
- save_infor_xls.setCell('Sheet1', rows, 1, rows) # 增加姓名
- save_infor_xls.setCell('Sheet1', rows, 2, data['name']) # 增加姓名
- save_infor_xls.setCell('Sheet1', rows, 5, data['sex']) # 增加性别
- save_infor_xls.setCell('Sheet1', rows, 3, data['phone']) # 增加电话号码
- save_infor_xls.setCell('Sheet1', rows, 4, data['ID']) # 增加身份证号
- save_infor_xls.setCell('Sheet1', rows, 6, data['company']) # 增加单位
- save_infor_xls.save()
- save_infor_xls.close()
- return 1
- except Exception as e:
- print("保存基本信息出错:" + str(e))
- # 保存采样信息数据
- def save_test_file(data):
- # 先检查是否有文件,没有新建一个,有测打开
- """
- :param data: dict_in_data = {
- 'tube_number': '',
- 'name': '',
- 'phone': '',
- 'ID': '',
- 'sex': '',
- 'company': '',
- 'test_date': ''
- }
- :return: None
- """
- try:
- my_save_xls_path = path + '\送检单.xlsx'
- save_xls = easyExcel(my_save_xls_path)
- max_row = save_xls.getRows('Sheet1')
- if max_row == 1:
- print("当天第一次写数据,初始化一下")
- # 试号管为 1
- data['tube_number'] = 1
- this_row = 1
- tube = 1
- else:
- tube = save_xls.getCell('Sheet1', max_row, 2)
- if ((max_row-1) % 10) == 0: # 10混1
- tube = tube + 1
- # 表行号增加一行
- max_row = max_row + 1
- save_xls.setCell('Sheet1', max_row, 1, max_row - 1) # 增加序号
- save_xls.setCell('Sheet1', max_row, 2, tube) # 增加管号
- save_xls.setCell('Sheet1', max_row, 3, data['name']) # 增加姓名
- save_xls.setCell('Sheet1', max_row, 4, data['sex']) # 增加性别
- save_xls.setCell('Sheet1', max_row, 5, data['phone']) # 增加电话号码
- save_xls.setCell('Sheet1', max_row, 6, data['ID']) # 增加身份证号
- save_xls.setCell('Sheet1', max_row, 7, data['company']) # 增加单位
- save_xls.setCell('Sheet1', max_row, 8, time.strftime("%Y-%m-%d", time.localtime())) # 增加检测时间
- save_xls.save()
- save_xls.close()
- save_xls = None
- print("保存数据成功")
- xh = max_row - 1 # 修正序号
- return tube, xh
- except Exception as e:
- save_xls.close()
- print("保存数据出错:" + str(e))
- return 0
- if __name__ == "__main__":
- ser10, ret = DOpenPort("COM3", 115200, None)
- if ret: # 判断串口是否成功打开
- reade_excel()
- ser7, ret1 = DOpenPort('COM23',115200,None)
- if ret1:
- print("打开串口2成功")
复制代码【总结】现在还有一个缺点,就是读取EXCEL文件还很慢,差不多要2秒钟才能反应过来。下一步考虑是不是用数据库。还有一些细节要处理好。明天到单位再试用一下,看看效果。 效果展示视频链接:http://bbs.eeworld.com.cn/thread-1202802-1-1.html (七)实战应用 上个星期四到单位实用,在保存数方面比较慢,究其原因是读写excel占用了太多的时间,这个星期一直在考虑如何解决这个问题,再加上最近的评测作品比较多,今年花了一天的时间对项目进行的修正,基本达到实用效果,现在跟大家汇报如下: 7.1 更新了界面,用Pyside设计界面: 7.2 代码: - import sys
- import time
- from PySide2.QtWidgets import *
- from PySide2.QtCore import *
- from PySide2.QtGui import *
- from PySide2.QtSerialPort import *
- from excel import *
- from Test_main import Ui_MainWindow
- from threading import Thread # 导入thread
- import qtmodern.styles
- import qtmodern.windows
- import pythoncom
- from PySide2.QtCore import Signal,QObject # 导入信号类
- cmd_read_phone = bytes([0x5a, 0xa5, 0x04, 0x83, 0x10, 0x60, 0x13])
- cmd_read_ID_number = bytes([0x5a, 0xa5, 0x04, 0x83, 0x10, 0x20, 0x18])
- cmd_write_to_enter_page = bytes([0x5a, 0xa5, 0x07, 0x82, 0x00, 0x84, 0x5a, 0x01, 0x00, 0x10])
- cmd_write_to_main_page = bytes([0x5a, 0xa5, 0x07, 0x82, 0x00, 0x84, 0x5a, 0x01, 0x00, 0x00])
- cmd_write_to_waite_page = bytes([0x5a, 0xa5, 0x07, 0x82, 0x00, 0x84, 0x5a, 0x01, 0x00, 0x12])
- send_list = [0x5a, 0xa5, 0x00, 0x00, 0x00, 0x00]
- all_range = None
- phone_code = None
- xls_ID_code = None
- dict_in_data = {
- 'tube_number': '',
- 'name': '',
- 'phone': '',
- 'ID': '',
- 'sex': '',
- 'company': '',
- 'test_date': ''
- }
- class MainWindow(Ui_MainWindow, QMainWindow):
- global all_range, my_xls, save_xls, phone_code
- def __init__(self):
- super(MainWindow, self).__init__()
- self.setupUi(self)
- self.setWindowTitle("核酸检测登记管理系统")
- self.comboBaudrate = 115200
- serial_list = QSerialPortInfo.availablePorts()
- for port in serial_list:
- self.comMainPort.addItem(port.portName())
- self.comSlavePort.addItem(port.portName())
- self.serialMain = QSerialPort()
- self.serialSlave = QSerialPort()
- self.bntOpen.clicked.connect(self.open_serial)
- self.serialMain.readyRead.connect(self.MainPortReadData)
- self.serialSlave.readyRead.connect(self.SlavePortReadData)
- self.bntExit.clicked.connect(self.exit_save_data)
- self.reade_excel()
- def reade_excel(self):
- # 循环接收数据,此为死循环,可用线程实现
- global my_xls, save_xls, all_range
- try:
- path = sys.path[0]
- print(path)
- my_xls_path = path + '\核酸数据库.xlsx'
- my_save_xls_path = path + '\送检单.xlsx'
- pythoncom.CoInitialize()
- my_xls = easyExcel(my_xls_path)
- cols = my_xls.getCols('Sheet1')
- print("总列数为:" + str(cols))
- rows = my_xls.getRows('Sheet1') + 1
- print("总行数为:" + str(rows))
- # 获取全部数据到内存
- all_range = my_xls.getRange('Sheet1', 2, 1, rows - 1, cols)
- save_xls = easyExcel(my_save_xls_path)
- pythoncom.CoUninitialize()
- except Exception as e:
- print("打开EXCEL出错啦:" + str(e))
- # 保存基本信息数据
- def save_infor_file(self,data):
- global my_xls
- try:
- rows = my_xls.getRows('Sheet1') + 1
- my_xls.setCell('Sheet1', rows, 1, rows) # 增加姓名
- my_xls.setCell('Sheet1', rows, 2, data['name']) # 增加姓名
- my_xls.setCell('Sheet1', rows, 5, data['sex']) # 增加性别
- my_xls.setCell('Sheet1', rows, 3, data['phone']) # 增加电话号码
- my_xls.setCell('Sheet1', rows, 4, data['ID']) # 增加身份证号
- my_xls.setCell('Sheet1', rows, 6, data['company']) # 增加单位
- my_xls.save()
- return 1
- except Exception as e:
- print("保存基本信息出错:" + str(e))
- # 保存采样信息数据
- def save_test_file(self,data):
- global save_xls
- # 先检查是否有文件,没有新建一个,有测打开
- try:
- max_row = save_xls.getRows('Sheet1')
- if max_row == 1:
- print("当天第一次写数据,初始化一下")
- # 试号管为 1
- data['tube_number'] = 1
- this_row = 1
- tube = 1
- else:
- tube = save_xls.getCell('Sheet1', max_row, 2)
- if ((max_row - 1) % 10) == 0: # 10混1
- tube = tube + 1
- # 表行号增加一行
- max_row = max_row + 1
- save_xls.setCell('Sheet1', max_row, 1, max_row - 1) # 增加序号
- save_xls.setCell('Sheet1', max_row, 2, tube) # 增加管号
- save_xls.setCell('Sheet1', max_row, 3, data['name']) # 增加姓名
- save_xls.setCell('Sheet1', max_row, 4, data['sex']) # 增加性别
- save_xls.setCell('Sheet1', max_row, 5, data['phone']) # 增加电话号码
- save_xls.setCell('Sheet1', max_row, 6, data['ID']) # 增加身份证号
- save_xls.setCell('Sheet1', max_row, 7, data['company']) # 增加单位
- save_xls.setCell('Sheet1', max_row, 8, time.strftime("%Y-%m-%d", time.localtime())) # 增加检测时间
- save_xls.save()
- print("保存数据成功")
- xh = max_row - 1 # 修正序号
- return tube, xh
- except Exception as e:
- print("保存数据出错:" + str(e))
- return 0
- def open_serial(self):
- self.serialMain.setPortName(self.comMainPort.currentText())
- self.serialSlave.setPortName(self.comSlavePort.currentText())
- if self.bntOpen.text() == "打开":
- self.serialMain.open(QIODevice.ReadWrite)
- self.serialMain.setBaudRate(self.comboBaudrate)
- self.serialSlave.open(QIODevice.ReadWrite)
- self.serialSlave.setBaudRate(self.comboBaudrate)
- self.bntOpen.setText("关闭")
- else:
- self.serialMain.close()
- self.serialSlave.close()
- self.bntOpen.setText("打开")
- # 姓名数据组装
- def creat_gbk_list(self, mydata, my_commad, H_address, L_address):
- # 发送的list
- send_list = [0x5a, 0xa5, 0x00, 0x00, 0x00, 0x00]
- send_len = 1 + 2 + 2 + len(mydata) * 2
- send_list[2] = send_len
- # 添加 命令
- send_list[3] = my_commad
- send_list[4] = H_address
- send_list[5] = L_address
- mysend_list = bytes(send_list) + mydata.encode("gbk") + b'\xFF\xFF'
- print(mysend_list)
- self.MaiNwritePort(mysend_list)
- # 清空数据
- def clear_show_data(self):
- global dict_in_data
- dict_in_data['name'] = ''
- dict_in_data['sex'] = ''
- dict_in_data['company'] = ''
- dict_in_data['phone'] = ''
- dict_in_data['phone'] = ''
- dict_in_data['ID'] = ''
- self.creat_gbk_list(dict_in_data['sex'], 0x82, 0x11, 0x20)
- self.creat_gbk_list(dict_in_data['phone'], 0x82, 0x10, 0x60)
- self.creat_gbk_list(dict_in_data['company'], 0x82, 0x11, 0x40)
- # self.creat_gbk_list(dict_in_data['name'], 0x82, 0x11, 0x60)
- # self.creat_gbk_list(dict_in_data['company'], 0x82, 0x11, 0x40)
- self.creat_gbk_list(dict_in_data['name'], 0x82, 0x11, 0x60)
- self.creat_gbk_list(dict_in_data['ID'], 0x82, 0x10, 0x20)
- # 护士站姓名数据组装
- def creat_gbk_list_nu(self, mydata, my_commad, H_address, L_address):
- # 发送的list
- send_list = [0x5a, 0xa5, 0x00, 0x00, 0x00, 0x00]
- send_len = 1 + 2 + 2 + len(mydata) * 2
- send_list[2] = send_len
- # 添加 命令
- send_list[3] = my_commad
- send_list[4] = H_address
- send_list[5] = L_address
- mysend_list = bytes(send_list) + mydata.encode("gbk") + b'\xFF\xFF\xFF'
- print(mysend_list)
- self.SlaveWritePort(mysend_list)
- # 护士站写数据
- def SlaveWritePort(self, text):
- if self.serialSlave.isOpen():
- self.serialSlave.write(text)
- # 主屏写数据
- def MaiNwritePort(self, text):
- if self.serialMain.isOpen():
- self.serialMain.write(text)
- def MainPortReadData(self):
- global all_range, dict_in_data, phone_code, xls_ID_code
- ba = self.serialMain.readAll()
- main_port_recv = QTextCodec.codecForLocale().toUnicode(ba.data())
- self.textInfor.appendPlainText(main_port_recv)
- STRGLO = ba.data()
- try:
- if STRGLO[0] == 0x5a and STRGLO[1] == 0xa5:
- # 获取地址
- addres = STRGLO[4] << 8 | STRGLO[5]
- commd = STRGLO[3]
- recv_len = STRGLO[2]
- print("地址为:" + hex(addres) + " 长度为:" + str(recv_len) + " 命令为:" + hex(commd))
- try:
- if recv_len == 0x06 and commd == 0x83:
- if addres == 0x1080:
- print("按手机号码查询")
- # # 读取手机号码数据
- # print("手机号码为:" + dict_in_data['phone'])
- my_index = None
- try:
- for index, value in enumerate(all_range):
- xls_phone_code = str(int(value[2]))
- if phone_code == xls_phone_code:
- my_index = index
- break
- if xls_phone_code == phone_code and (my_index is not None):
- print("查到数据")
- dict_in_data['name'] = all_range[my_index][1]
- dict_in_data['sex'] = all_range[my_index][4]
- dict_in_data['company'] = all_range[my_index][5]
- dict_in_data['ID'] = all_range[my_index][3]
- self.creat_gbk_list(dict_in_data['sex'], 0x82, 0x11, 0x20)
- self.creat_gbk_list(dict_in_data['ID'], 0x82, 0x10, 0x20)
- self.creat_gbk_list(dict_in_data['company'], 0x82, 0x11, 0x40)
- self.creat_gbk_list(dict_in_data['name'], 0x82, 0x11, 0x60)
- # self.creat_gbk_list(dict_in_data['company'], 0x82, 0x11, 0x40)
- self.creat_gbk_list(dict_in_data['name'], 0x82, 0x11, 0x60)
- # 页面转移到确认页面 为什么要写两遍,BUG——
- self.MaiNwritePort(cmd_write_to_enter_page)
- self.MaiNwritePort(cmd_write_to_enter_page)
- else:
- print("没有查到信息")
- except Exception as e:
- print("按手机号码查询出错啦:" + str(e))
- elif addres == 0x1090:
- # print("按身份证查询")
- # print("身份证号码为:" + dict_in_data['ID'])
- try:
- my_index = None
- for index, value in enumerate(all_range):
- xls_ID_code = value[3]
- if dict_in_data['ID'] == xls_ID_code:
- my_index = index
- break
- dict_in_data['name'] = all_range[my_index][1]
- dict_in_data['sex'] = all_range[my_index][4]
- dict_in_data['company'] = all_range[my_index][5]
- dict_in_data['phone'] = str(int(all_range[my_index][2]))
- self.creat_gbk_list(dict_in_data['sex'], 0x82, 0x11, 0x20)
- self.creat_gbk_list(dict_in_data['phone'], 0x82, 0x10, 0x60)
- self.creat_gbk_list(dict_in_data['company'], 0x82, 0x11, 0x40)
- self.creat_gbk_list(dict_in_data['name'], 0x82, 0x11, 0x60)
- self.creat_gbk_list(dict_in_data['company'], 0x82, 0x11, 0x40)
- self.creat_gbk_list(dict_in_data['name'], 0x82, 0x11, 0x60)
- # 页面转移到确认页面 为什么要写两遍,BUG——
- # 页面转移到确认页面 为什么要写两遍,BUG——
- self.MaiNwritePort(cmd_write_to_enter_page)
- self.MaiNwritePort(cmd_write_to_enter_page)
- except Exception as e:
- print("出错啦:" + str(e))
- # DWritePort(ser, cmd_read_ID_number)
- elif addres == 0x1200:
- # 增加时间,保存数据
- print("确认登记数据")
- tub, xh = self.save_test_file(dict_in_data)
- if tub is not None:
- self.MaiNwritePort(cmd_write_to_waite_page)
- self.creat_gbk_list_nu(dict_in_data['name'], 0x82, 0x20, 0x20)
- self.creat_gbk_list_nu(str(int(tub)), 0x82, 0x20, 0x40)
- self.creat_gbk_list_nu(str(int(tub)), 0x82, 0x20, 0x40)
- self.creat_gbk_list_nu(str(xh), 0x82, 0x20, 0x60)
- self.creat_gbk_list_nu(str(xh), 0x82, 0x20, 0x60)
- else:
- # 弹出失败
- pass
- # 转到主页面
- elif addres == 0x1210:
- print('保存数据')
- if dict_in_data['name'] == "" or \
- dict_in_data['sex'] == "" or\
- dict_in_data['company'] == "" or\
- dict_in_data['phone'] == "" or\
- dict_in_data['ID'] == "":
- print("data ERROR")
- else:
- save_state = self.save_infor_file(dict_in_data)
- cols = my_xls.getCols('Sheet1')
- print("总列数为:" + str(cols))
- rows = my_xls.getRows('Sheet1') + 1
- print("总行数为:" + str(rows))
- # 获取全部数据到内存
- all_range = my_xls.getRange('Sheet1', 2, 1, rows - 1, cols)
- self.MaiNwritePort(cmd_write_to_enter_page)
- elif commd == 0x83 and recv_len == 0x12 and addres == 0x1060:
- print("接收到手机号码")
- recv_phone_len = STRGLO[6]
- if recv_phone_len == 0x07:
- str_ph = STRGLO[7:18]
- phone_code = str_ph.decode()
- # 开始查找是否有手机号存在
- dict_in_data['phone'] = phone_code
- else:
- print("接收到的电话号码长度不对 长度为:" + str((recv_phone_len - 8)))
- elif commd == 0x83 and recv_len == 24 and addres == 0x1020:
- print("接收到身份证号码")
- recv_ID_len = STRGLO[6]
- if recv_ID_len == 10:
- dict_in_data['ID'] = STRGLO[7:25].decode()
- else:
- print("接收到的身份证长度不对 长度为:" + str((recv_ID_len - 8)))
- elif commd == 0x83 and addres == 0x1160:
- # 接收到姓名
- recv_name_len = STRGLO[6] - 1
- if 0 < recv_name_len < 5:
- dict_in_data['name'] = (STRGLO[7:(7 + recv_name_len * 2)]).decode("gbk")
- else:
- print("姓名的长度不符合")
- print(dict_in_data['name'])
- elif commd == 0x83 and addres == 0x1140:
- # 接收到姓名
- recv_company_len = STRGLO[6] - 1
- if 1 < recv_company_len < 6:
- dict_in_data['company'] = (STRGLO[7:(7 + recv_company_len * 2)]).decode("gbk")
- else:
- print("单位的长度不符合")
- print(dict_in_data['company'])
- elif commd == 0x83 and addres == 0x1120:
- # 接收到性别
- recv_sex_len = STRGLO[6]
- if recv_sex_len == 2:
- str_sex = (STRGLO[7:9]).decode("gbk")
- if str_sex == '男' or str_sex == '女':
- dict_in_data['sex'] = str_sex
- else:
- print("性别必须为男或者女")
- dict_in_data['sex'] = ''
- else:
- print("姓名的长度不符合")
- print(dict_in_data['sex'])
- except Exception as e:
- print("解释命令出错" + str(e))
- else:
- print("命令不认识")
- except Exception as e:
- print(str(e))
- def SlavePortReadData(self):
- ba = self.serialSlave.readAll()
- main_port_recv = QTextCodec.codecForLocale().toUnicode(ba.data())
- self.textInfor.appendPlainText(main_port_recv)
- STRGLO = ba.data()
- try:
- if STRGLO[0] == 0x5a and STRGLO[1] == 0xa5:
- # 获取地址
- addres = STRGLO[4] << 8 | STRGLO[5]
- commd = STRGLO[3]
- recv_len = STRGLO[2]
- print("地址为:" + hex(addres) + " 长度为:" + str(recv_len) + " 命令为:" + hex(commd))
- if addres == 0x2004:
- self.clear_show_data()
- self.MaiNwritePort(cmd_write_to_main_page)
- self.creat_gbk_list_nu('', 0x82, 0x11, 0x60)
- except Exception as e:
- print("接收护士站错据出错:" + str(e))
- def save_exec_data(self):
- try:
- my_xls.save()
- save_xls.save()
- except Exception as e:
- print("保存数据出错:" + str(e))
- def exit_save_data(self):
- try:
- my_xls.save()
- my_xls.close()
- save_xls.save()
- save_xls.close()
- sys.exit(1)
- except Exception as e:
- print("保存数据出错:" + str(e))
- if __name__ == "__main__":
- app = QApplication(sys.argv)
- qtmodern.styles.dark(app)
- app.setWindowIcon(QIcon("../monkey.ico"))
- mwin = MainWindow()
- win = qtmodern.windows.ModernWindow(mwin)
- win.show()
- sys.exit(app.exec_())
复制代码7.3 应用的视频: 效果展示视频链接:http://bbs.eeworld.com.cn/thread-1204656-1-1.html 总的来说基本功能实现了,还有一些需要进一步完善的地方
备注说明:如需源码,请参考此链接:http://inforum.dwin.com.cn:20080/forum.php?mod=viewthread&tid=6070&_dsign=7cf6c848
|