Python-解析串行数据并查找特定字符串
我目前正在连接一个设备,正在读取串行线上的x个字符。我想在读回序列内容后查找特定字符串 我已经能够成功连接到设备,并且可以读回序列号的内容Python-解析串行数据并查找特定字符串,python,serial-port,pyserial,Python,Serial Port,Pyserial,我目前正在连接一个设备,正在读取串行线上的x个字符。我想在读回序列内容后查找特定字符串 我已经能够成功连接到设备,并且可以读回序列号的内容 import serial import sys # connect to com port ser = serial.Serial('COM1', 115200, timeout=0) #read serial data data = ser.read(1000) #output serial data data #step needed to
import serial
import sys
# connect to com port
ser = serial.Serial('COM1', 115200, timeout=0)
#read serial data
data = ser.read(1000)
#output serial data
data
#step needed to parse through serial data and look for specific string -
e.g. Hello
还没有错误消息如果要搜索模式,请使用以下正则表达式-
import re
if re.search(r'<pattern>', data, re.MULTILINE):
print "string found"
如果要搜索模式,请使用正则表达式,如下所示-
import re
if re.search(r'<pattern>', data, re.MULTILINE):
print "string found"
if specific_string in data:
print "string present"