【国产RISC-V Linux板 昉·星光VisionFive试用报告】与迪文串口屏数据交换成功
<p><a href="https://bbs.eeworld.com.cn/thread-1206010-1-1.html">【国产RISC-V Linux板 昉·星光VisionFive试用报告】核酸采样系统前期论证 - 国产芯片交流 - 电子工程世界-论坛 (eeworld.com.cn)</a></p><p><a href="https://bbs.eeworld.com.cn/thread-1206030-1-1.html">【国产RISC-V Linux板 昉·星光VisionFive试用报告】python 输出HELLOWORLD - 国产芯片交流 - 电子工程世界-论坛 (eeworld.com.cn)</a></p>
<p><a href="https://bbs.eeworld.com.cn/thread-1206110-1-1.html">【国产RISC-V Linux板 昉·星光VisionFive试用报告】与迪文屏成功通信 - 国产芯片交流 - 电子工程世界-论坛 (eeworld.com.cn)</a></p>
<p><a href="https://bbs.eeworld.com.cn/thread-1206415-1-1.html">【国产RISC-V Linux板 昉·星光VisionFive试用报告】环境准备——安装mysql - 国产芯片交流 - 电子工程世界-论坛 (eeworld.com.cn)</a></p>
<p><a href="https://bbs.eeworld.com.cn/thread-1206418-1-1.html">【国产RISC-V Linux板 昉·星光VisionFive试用报告】环境准备-设计数据表 - 国产芯片交流 - 电子工程世界-论坛 (eeworld.com.cn)</a></p>
<p><a href="https://bbs.eeworld.com.cn/thread-1206565-1-1.html">【国产RISC-V Linux板 昉·星光VisionFive试用报告】环境准备+搭建服务器 - 国产芯片交流 - 电子工程世界-论坛 (eeworld.com.cn)</a></p>
<p><a href="https://bbs.eeworld.com.cn/thread-1206893-1-1.html">【国产RISC-V Linux板 昉·星光VisionFive试用报告】创建用户数据插入 - 国产芯片交流 - 电子工程世界-论坛 (eeworld.com.cn)</a></p>
<p><a href="https://bbs.eeworld.com.cn/thread-1206982-1-1.html">【国产RISC-V Linux板 昉·星光VisionFive试用报告】Tornado 数据写入读取 - 国产芯片交流 - 电子工程世界-论坛 (eeworld.com.cn)</a></p>
<p>经过上面的环境搭建,现在书写昉.星光的数据交换程序main.py程序如下:</p>
<pre>
<code># -*- coding: gbk -*-
#!/usr/bin/python
import time
import serial# 导入模块
import threading
import urllib3
import json
import time
url = "http://192.168.3.192:9000/man"
http = urllib3.PoolManager()
STRGLO = ""# 读取的数据
BOOL = True# 读取标志位
cmd_read_phone = bytes()
cmd_read_ID_number = bytes()
cmd_write_to_enter_page = bytes()
cmd_write_to_main_page = bytes()
cmd_write_to_waite_page = bytes()
cmd_write_to_noinfor_page = bytes()
cmd_write_to_ERROR_page = bytes()
send_list =
all_range = None
class sampleNet:
def post(self, dict_info):
try:
encoded_data = json.dumps(dict_info).encode("gbk")
resp = http.request(
"POST",
url,
body=encoded_data,
headers={
'x-env-code': 'mafutian',
'content-type': 'application/json;charset=gbk'
}
)
return resp
except Exception as e:
print("post ERR:" + str(e))
# 按手机号码查询
def phone_get(phone):
net_post = sampleNet()
data = {"command": "getPersonnel", "phone": phone}
try:
resp = net_post.post(data)
if resp.status == 200:
data = json.loads(resp.data)
print(data)
return data
else:
return None
except Exception as e:
print(e)
# 姓名数据组装
def creat_gbk_list(mydata, my_commad, H_address, L_address):
# 发送的list
send_list =
send_len = 1 + 2 + 2 + len(mydata) * 2
send_list = send_len
# 添加 命令
send_list = my_commad
send_list = H_address
send_list = 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
while BOOL:
if ser.in_waiting:
try:
# STRGLO = ser.read(ser.in_waiting).decode("gbk")
STRGLO = ser.read(ser.in_waiting)
print("收到数据")
print("长度为:" + str(len(STRGLO)))
if STRGLO == 0x5a and STRGLO == 0xa5:
# 获取地址
addres = STRGLO << 8 | STRGLO
commd = STRGLO
recv_len = STRGLO
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
if (recv_phone_len == 0x13):
str_ph = STRGLO
phone_code = str_ph.decode()
print(phone_code)
# 开始查找是否有手机号存在
try:
data = phone_get(phone_code)
if data is not None:
if data['code'] == 1000:
# 获取身份证号码
# 写性别
#creat_gbk_list(my_xb, 0x82, 0x11, 0x20)
creat_gbk_list(data['ID_card'], 0x82, 0x10, 0x20)
# 写职业
creat_gbk_list(data['uint'], 0x82, 0x11, 0x40)
# 写姓名
creat_gbk_list(data['name'], 0x82, 0x11, 0x60)
# 写职业
creat_gbk_list(data['uint'], 0x82, 0x11, 0x40)
# 页面转移到确认页面
# 写姓名
creat_gbk_list(data['name'], 0x82, 0x11, 0x60)
#DWritePort(ser, cmd_write_to_enter_page)
time.sleep(0.5)
DWritePort(ser, cmd_write_to_enter_page)
except Exception as e:
print("出错啦:" + str(e))
else:
print("接收到的电话号码长度不对 长度为:" + str((recv_phone_len - 8)))
# 查找手机号
elif commd == 0x83 and recv_len == 52 and addres == 0x1020:
print("接收到手机号码")
recv_ID_len = STRGLO
if (recv_ID_len == 0x18):
str_ID = STRGLO
str_ID = str_ID.decode()
# 开始查找是否有手机号存在
try:
if ID_code == str_ID:
# 写性别
creat_gbk_list(my_xb, 0x82, 0x11, 0x20)
# 获取手机号码
creat_gbk_list(my_phone, 0x82, 0x10, 0x60)
# 写职业
creat_gbk_list(my_job, 0x82, 0x11, 0x40)
# 写职业
creat_gbk_list(my_job, 0x82, 0x11, 0x40)
# 写姓名
creat_gbk_list(my_name, 0x82, 0x11, 0x60)
# 页面转移到确认页面
DWritePort(ser, cmd_write_to_enter_page)
except Exception as e:
print("出错啦:" + str(e))
else:
print("接收到的电话号码长度不对 长度为:" + str((recv_phone_len - 8)))
# 查找手机号码
else:
print("非法数据")
except Exception as e:
print("错误:" + str(e))
# 打开串口
# 端口,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
if __name__ == "__main__":
ser, ret = DOpenPort("/dev/ttyUSB0", 115200, None)
if (ret == True):# 判断串口是否成功打开
print("打开串口成功1")
# count=DWritePort(ser,"我是东小东,哈哈")
# print("写入字节数:",count)
# DReadPort() #读串口数据
# DColsePort(ser)#关闭串口</code></pre>
<p>1、运行主程序:</p>
<p> 2、迪文屏接到usb上:</p>
<p> 然后输入手机号码:</p>
<p></p>
<p>查询后得到数据库的信息:</p>
<p> 与数据库的信息是一致的:</p>
<p> 到这一步与迪文屏的交互基本上没有什么问题了,下一步做数据的保存。</p>
<p>a22c3825fbb740b180a7f49f316015b4<br />
</p>
<p><img height="48" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/wanwan88.gif" width="59" /></p>
页:
[1]