# -*- coding: utf-8 -*-
# @Time : 2018/1/18 21:34
# @Author : houyujiang
# @Email : houyujiang@live.cn
# @File : SendRead.py
# @Software: PyCharm
import serial
import os#用于清屏,os.system('cls')
def ui():
print '-------------------------------获取参数----------------------------------------'
print '1.获取射频参数 2.获取模块地址 3.目标地址 4.获取分组码 5.获取语音地址 6.音频参数 7.中继等级'
print '----------10.设置目标地址------------11.设置分组码-----------------------'
print '---------------------------语音对讲模块----------------------------------------'
print '-----------8.打开PTT-----------9.关闭PTT------------------'
input_num = raw_input('请输入数字: ')
return input_num
#串口工厂
def serial_Factory(cmd,num):
serials = serial.Serial('com3',115200)
serials.write(cmd)
argv = serials.read(num)
result = ''
hlen = len(argv)
for i in xrange(hlen):
hvol = ord(argv[i])
hhex = '%02x' % hvol
result += hhex + ''
return result
#return cmd+'ok'
#获取射频参数
def get_she_ping():
cmd = '\x68\x01\x00'
num = 15
back = serial_Factory(cmd,num)
print back
# 获取模块地址
def get_mo_kuai():
cmd = '\x68\x01\x02'
num = 6
back = serial_Factory(cmd,num)
print back
# 获取目标地址
def get_mu_biao():
cmd = '\x68\x01\x04'
num = 6
back = serial_Factory(cmd,num)
print back
#获取分组码
def get_fen_zu():
cmd = '\x68\x01\x06'
num = 5
back = serial_Factory(cmd,num)
print back
#获取语音地址
def get_yu_yin():
cmd = '\x68\x01\x08'
num = 6
back = serial_Factory(cmd,num)
print back
#获取音频参数
def get_yin_pin():
cmd = '\x68\x01\x0A'
num = 5
back = serial_Factory(cmd,num)
print back
#获取中继等级
def get_zhong_ji():
cmd = '\x68\x01\x0C'
num = 4
back = serial_Factory(cmd, num)
print back
#打开PTT
def open_ptt():
cmd = '\x68\x02\x09\x01'
num = 3
back = serial_Factory(cmd, num)
print back
if back == '680109':
print 'ptt打开'
#关闭PTT
def close_ptt():
cmd = '\x68\x02\x09\x00'
num = 3
back = serial_Factory(cmd, num)
print back
if back == '680109':
print '关闭'
#2018.01.24-设置目标地址
def set_mubiao_dizhi():
cmd = '\x68\x04\x05\xFF\xFF\xFF'#默认0xFFFFFF,id:300=00 01 4a
num = 3
back = serial_Factory(cmd,num)
print back
if back == '680105':
print '设置目标地址成功'
else:
print '设置目标地址失败'
#设置分组码
def set_FenZuMa():
cmd = '\x68\x03\x07\x00\x01'#分组码0001
num = 3
back = serial_Factory(cmd, num)
print back
if back == '680107':
print '设置分组码成功'
else:
print '设置分组码失败'
# 切换器
dicts = {'1': get_she_ping, '2': get_mo_kuai,'3':get_mu_biao,
'4':get_fen_zu,'5':get_yu_yin,'6':get_yin_pin,'7':get_zhong_ji,
'8':open_ptt,'9':close_ptt,'10':set_mubiao_dizhi,'11':set_FenZuMa}
if __name__ == '__main__':
while True:
os.system('cls')
num =ui()
dicts[num]()
python2.7串口操作接受发送16进制指令
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- python通过调用serial库函数发送指令,其中串口通信发送的数据需要是str格式字符串。当需要给下方发送16...
- PHP 操作串口或socket时以16进制发送"FD FF 01 0F"16进制字符串写法:"\xFD\xFF\x...