Python python simple test script for PMS7003 dust sensor by irmus 2017. 6. 14. #!/usr/bin/python # -*- coding: utf-8 -*- ''' Read outputs of PMS7003 particle sensor via USB2UART. Print out results on screen. https://irmus.tistory.com/ irmusy@gmail.com ''' import serial import struct COM_PORT = 'COM7' # index of list PMS7003_FRAME_LENGTH = 0 PMS7003_PM1P0 = 1 PMS7003_PM2P5 = 2 PMS7003_PM10P0 = 3 PMS7003_PM1P0_ATM = 4 PMS7003_PM2P5_ATM = 5 PMS7003_PM10P0_ATM = 6 PMS7003_PCNT_0P3 = 7 PMS7003_PCNT_0P5 = 8 PMS7003_PCNT_1P0 = 9 PMS7003_PCNT_2P5 = 10 PMS7003_PCNT_5P0 = 11 PMS7003_PCNT_10P0 = 12 PMS7003_VER = 13 PMS7003_ERR_CODE = 14 PMS7003_CHECK_CODE = 15 ser = serial.Serial(COM_PORT, 9600, timeout=0.1) i = 0 while i < 10: # print 10 packets while True: c = ser.read(1) # 1st header if len(c) >= 1: if ord(c[0]) == 0x42: c = ser.read(1) # 2nd header if len(c) >= 1: if ord(c[0]) == 0x4d: break; buff = ser.read(30) # packet remaining. fixed length packet structure # calculate check code. Sum every byte from HEADER to ERR_CODE check = 0x42 + 0x4d for c in buff[0:28]: check += ord(c) # parsing pms7003_data = struct.unpack('!HHHHHHHHHHHHHBBH', buff) # compare check code if check != pms7003_data[PMS7003_CHECK_CODE]: print 'Incorrect check code.' print ' received : 0x%04X' % (pms7003_data[PMS7003_CHECK_CODE]) print ' calculated : 0x%04X' % (check) continue # print results print '-----------------------' print 'Frame len [byte] :', str(pms7003_data[PMS7003_FRAME_LENGTH]) print 'PM 1.0 [ug/m^3] :', str(pms7003_data[PMS7003_PM1P0]) print 'PM 2.5 [ug/m^3] :', str(pms7003_data[PMS7003_PM2P5]) print 'PM 10 [ug/m^3] :', str(pms7003_data[PMS7003_PM10P0]) print 'PM 1.0 atm [ug/m^3] :', str(pms7003_data[PMS7003_PM1P0_ATM]) print 'PM 2.5 atm [ug/m^3] :', str(pms7003_data[PMS7003_PM2P5_ATM]) print 'PM 10 atm [ug/m^3] :', str(pms7003_data[PMS7003_PM10P0_ATM]) print 'Particle cnt 0.3um [count] :', str(pms7003_data[PMS7003_PCNT_0P3]) print 'Particle cnt 0.5um [count] :', str(pms7003_data[PMS7003_PCNT_0P5]) print 'Particle cnt 1.0um [count] :', str(pms7003_data[PMS7003_PCNT_1P0]) print 'Particle cnt 2.5um [count] :', str(pms7003_data[PMS7003_PCNT_2P5]) print 'Particle cnt 5.0um [count] :', str(pms7003_data[PMS7003_PCNT_5P0]) print 'Particle cnt 10.0um [count] :', str(pms7003_data[PMS7003_PCNT_10P0]) print 'Version :', str(pms7003_data[PMS7003_VER]) print 'Error code :', str(pms7003_data[PMS7003_ERR_CODE]) print 'Check code : 0x%04X' % (pms7003_data[PMS7003_CHECK_CODE]) i += 1 공유하기 게시글 관리 cafe irmus 저작자표시 동일조건 관련글 Windows registry 사용하기 GUI2EXE를 이용해 pylab 사용하기 error: MSVCP90.dll: No such file or directory python에서 MATLAB .mat 파일을 읽어오자