Skip to content

Instantly share code, notes, and snippets.

@lsongdev
Last active October 19, 2017 09:47
Show Gist options
  • Save lsongdev/db9fc625f409e387ed66adb9a8ef55e4 to your computer and use it in GitHub Desktop.
Save lsongdev/db9fc625f409e387ed66adb9a8ef55e4 to your computer and use it in GitHub Desktop.
微创联合 空气质量检测仪
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);
});
@lsongdev
Copy link
Author

7439c2cd058605de715f7497d44e32d2
screen shot 2017-10-19 at 5 47 29 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment