Last active
October 19, 2017 09:47
-
-
Save lsongdev/db9fc625f409e387ed66adb9a8ef55e4 to your computer and use it in GitHub Desktop.
微创联合 空气质量检测仪
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const headers = [ | |
'TEMP', 'HUMI', | |
'PM1.0','PM2.5','PM10','PM1.0_US','PM2.5_US','PM10_US', | |
'>0.3um', '>0.5um', '>1.0um', '>2.5um', '>5.0um', '>10um', | |
'HCHO', 'TVOC' | |
]; | |
const readWCLH = (fd, done) => { | |
let buffer = ''; | |
fs.createReadStream(fd).on('data', chunk => { | |
buffer += chunk; | |
const lines = buffer.split('\r\n'); | |
buffer = lines.pop(); | |
lines.forEach(line => done(line | |
.split(/\s+/g) | |
.filter(Boolean) | |
.reduce((data, value, i) => { | |
data[ headers[i] ] = value; | |
return data; | |
}, {}))); | |
}); | |
}; | |
readWCLH('/dev/cu.wchusbserial1420', data => { | |
console.log(data); | |
}); |
Author
lsongdev
commented
Oct 19, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment