在Beaglebon上读取串行输入的Python代码

2024-06-25 23:23:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从我的Beaglebone上读取Geiger计数器的数据,但是当我打印结果时,没有包括我的计数器代码:

import Adafruit_BBIO.UART as UART
import serial
import time
UART.setup("UART4")

ser = serial.Serial(port = "/dev/ttyO4", baudrate=9600)

r = 0
d = 0
z = 0
minutes = 0
while True:
    timeout = time.time() + 60
    while True:
            x = ser.read()
            if ser.isOpen():
                    print "Serial is open!"
                    r = r +1
                    print r
                    print x

            elif x is '0':
                d=d+1
                #print '.'
            elif x is '1':
                d=d+1
                #print '.'

    time.sleep(1)
    z=z+d
    print "CPM %f " % d
    print "total %f" % z
    print "minutes %f" % minutes

我的输出结果是:

^{pr2}$

Tags: importtruetimeisserial计数器serbeaglebone