node.jsとnode-serialportを使用して、Arduinoとのシリアル通信を試みています。
VMwareにWindows8.1を入れ、「npm install -g serialport」でインストールを実行し、「node index.js」で実行すると以下のエラーが発生します。
C:\socket.io>node index.js
C:\socket.io\index.js:5
var serial = new SerialPort('COM2',{
^
TypeError: SerialPort is not a constructor
at Object.<anonymous> (C:\socket.io\index.js:5:14)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3
なお、VMware上のindex.jsでは以下のコードを記入しています。
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var SerialPort = require('serialport').SerialPort;
var serial = new SerialPort('COM2',{
baudrate:57600
});
app.get('/',function(req,res){
res.sendfile('index.html');
});
serial.on('open',function(){
console.log('open');
});
serial.on('data',function(data){
io.emit('recvmsg',data.toString());
});
io.on('connection',function(socket){
socket.on('message',function(msg){
serial.write(msg,function(err,results){
});
});
});
http.listen(3000,function(){
console.log('listen 3000 port');
});
「npm serialport --version」でバージョンを調べてみると、「3.10.10」と表示されますので、インストールは正しくできているものだと考えています。
他にインストールしておくべきものがあったりするのでしょうか?
調べても全く見当もつきませんので、ご教示いただければ幸いです。
よろしくお願い致します。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。