python转化串⼝中的数据,并分组判断
# -*- coding: utf-8 -*-
import binascii
def split_1(data,split_sign):
data2=[]
for i in data:
data3 = i.split(split_sign)
for n in data3:
n=n.strip()
data2.append(n)
return data2
def com_data(data1,*val):
data1 = place("","")
data2 = binascii.unhexlify(data1)
print data2
data2 = data2.split("\r\n")
data5=split_1(data2,",")
data6=split_1(data5,"{")
data=split_1(data6,"}")
data4=split_1(data,"\r")
print"-----------"
print data4
print"-----------"
num=0
if type(val) is tuple:
val=list(val)
val2=[]
for i in val:
val1 = i.encode('gbk')
#print val1
#print type(val1)
val1 = val1.split(",")
for n in val1:
n=n.strip()
val2.append(n)
print"-----------"
print val2
print"-----------"
for i in val2:
print i
if i in data4:
num = data4.index(i)
print"%s is ok."%i
else:
return"not_ok",None
return"ok",num
def com_read(data2):
data2 = place("","")
data = binascii.unhexlify(data2)
#data = de('gbk')
#print data
#data = data.split("\r\n")
#print data
return data
def com_read_contain(data2,val2):
python怎么读取串口数据data2 = place("","")
data = binascii.unhexlify(data2)
#data = de('gbk')
val2 = de('gbk')
#print data
#data = data.split("\r\n")
#print data
return data,val2
if__name__ == "__main__":
s = "62 72 63 74 6C 20 73 68 6F 77 6C 65 64 3D 39 2C 20 6F 6E 3D 31 2C 20 6F 66 66 3D 34 30 30 30 2C 20 62 6C 69 6E 6B 73 2C 3D 31 2C 20 72 65 73 65 74 3D 31 2C 20 74 69 6D 65 3D 34 30 30 30 0D 0A 6C 65 64 3D 39 2C 20 6F 6E 3 a,b=com_data(s,"eth3")
#a,b=com_data(s,'root@OpenWrt:~#')
print a,b
#c = com_read(s)
#print c
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论