我正在尝试使用wx.Timer
通过串行端口开发gui。但是我需要使用串行端口资源并发来始终保存数据和绘制图形。为此,我使用了import serial
ser = serial.Serial('COM9',9600)
def update(self, event):
global ser
timerId = event.GetId()
if timerId == TIMER_ID1:
print("hello")
for line in ser:
print(line)
print("world")
else:
x=[]
x1=[]
x2=[]
y=[]
y1=[]
y2=[]
i=0
#fig = plt.figure()
def sV_sat(i):
for line in ser:
data=line.split(b",")
if data[0] == b"$GPGSV":
print("c")
sView_GP = data[3]
sNumber_GP = data[4]
i=i+1
x.append(i)
#x=[i]
y.append(float(sView_GP))
ax.set_title("GPS")
ax1.set_title("GPS-GLO")
ax1.set_ylim(0,20)
ax.bar(i,y,color='green') #only GPS #option 2
ax1.plot(x,y,'g') #GPS ve ...
#time.sleep(0.1)
ani8 = animation.FuncAnimation(fig,sV_sat)
plt.legend()
#pyplot.show()
plt.show()
print (time.ctime())
,但未能成功。下面的代码只是示例:
print(line)
上面的代码给了我图形,但不能给出print("hello")
for line in ser:
print(line)
print("world")
:(第9行)
hello
只需打印:world
和hello
world
并带有图形
{{1}}
第二条串行线(第21行)显示图形。没关系。为什么第一个(第8行)被跳过?任何帮助将不胜感激。非常感谢。
答案 0 :(得分:0)
只需阅读pySerial的文档,建议您必须$Upload -match 'https://sitename.com/csv/v1/status/\d*'
$Matches[0]
串行端口。
即
在“ 19200,8,N,1”处打开命名端口,超时时间为1s:
read
打开端口“ 38400,8,E,1”,不阻止硬件握手:
>>> import serial
>>> with serial.Serial('/dev/ttyS1', 19200, timeout=1) as ser:
... x = ser.read() # read one byte
... s = ser.read(10) # read up to ten bytes (timeout)
... line = ser.readline() # read a '\n' terminated line