enter code here
var express = require('express');
var router = express.Router();
router.get('/', function(req, res, next) {
res.render('led', { title: 'LED Control' });
});
router.get('/:switch', function(req, res, next) {
var onoff = req.params.switch;
if (onoff == 'on') setLED(1);
if (onoff == 'off') setLED(0);
res.render('led', { title: 'LED Control : ' + req.params.switch });
});
module.exports = router;
// LED 제어 function
function setLED(flag) {
var fs = require('fs');
fs.open('/dev/ttyUSB0','a', 666, function(e, fd) {
fs.write(fd, flag ? '1' : '0', null, null, null, function() {
fs.close(fd, function() { });
});
});
}
Where do you fix it? OTLstrong text
return binding.writeString(fd, buffer, offset, length, req); ^
TypeError: First argument must be file descriptor at TypeError (native) at Object.fs.write (fs.js:652:18) at /home/pi/ardu/routes/led.js:23:6 at FSReqWrap.oncomplete (fs.js:82:15)
via 전태웅
No comments:
Post a Comment