我正在尝试从传感器打印值,但传感器正在运行而没有显示错误但是它没有打印值,我无法理解问题
这是代码:
from usbiss.spi import SPI
import numpy
import serial
import opc
import time
import csv
import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt
from drawnow import *
spi = SPI("/dev/ttyACM0")
spi.mode = 1
spi.max_speed_hz = 500000
alpha = opc.OPCN2(spi)
time.sleep(2)
alpha.on()
a1 = alpha.pm()
op_sensor = serial.Serial(
port = '/dev/ttyACM0',
baudrate = 500000,
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE,
bytesize = serial.EIGHTBITS,
timeout=1 # add this
)
count = 0
while(count<=20):
while(op_sensor.inWaiting()==0):
pass
a = op_sensor.readline()
print(a)
答案 0 :(得分:0)
我没有你的传感器,但考虑到这个来解决你的问题:
op_sensor.inWaiting()
?您可能需要out_waiting
or outWaiting()
- 您做想要查询传感器是否有适合您的数据此外:
count