示例#1
0
    def __init__(self, q):
        Process.__init__(self)
        self.q = q

        self.u = mraa.Uart(0)
        self.u.setBaudRate(9600)
        self.u.setMode(8, mraa.UART_PARITY_NONE, 1)
        self.u.setFlowcontrol(False, False)

        self.pm1_0_avg = move_avge.move_avg(1)
        self.pm2_5_avg = move_avge.move_avg(1)
        self.pm10_avg = move_avge.move_avg(1)
示例#2
0
    def __init__(self, q):
        Process.__init__(self)
        self.q = q

        self.u = mraa.Uart(0)
        self.u.setBaudRate(9600)
        self.u.setMode(8, mraa.UART_PARITY_NONE, 1)
        self.u.setFlowcontrol(False, False)
        self.u.flush()
        cmd = bytearray([0x68, 0x01, 0x02, 0x95])
        #cmd = bytearray([0x68,0x01,0x04,0x96])
        self.u.write(cmd)
        self.u.flush()
        time.sleep(0.1)
        if self.u.dataAvailable():
            ready = False
            while ready is False:
                getstr = self.u.readStr(2)
                bytedata = bytearray(getstr)
                if bytedata[0] == 165 and bytedata[1] == 165:
                    ready = True
                else:
                    time.sleep(0.1)
            self.u.flush()
        cmd = bytearray([0x68, 0x01, 0x01, 0x96])
        self.u.write(cmd)
        self.u.flush()
        time.sleep(0.1)
        if self.u.dataAvailable():
            ready = False
            while ready is False:
                getstr = self.u.readStr(2)
                bytedata = bytearray(getstr)
                for i in range(0, 2, 1):
                    print(int)(bytedata[i])
                if bytedata[0] == 165 and bytedata[1] == 165:
                    ready = True
                else:
                    time.sleep(0.1)
            self.u.flush()

        self.pm1_0_avg = move_avge.move_avg(1)
        self.pm2_5_avg = move_avge.move_avg(1)
        self.pm10_avg = move_avge.move_avg(1)