简体   繁体   中英

node.js serial port get sourcer and avoid npm

I want to use node.js serialport so my unix running in a browser can access the serial port(uart). I'm sure serialport is a marvellous module but I can't get it. node.js is marvellous, but npm is disgraceful. I'm constrained to Windows8(sorry), npm fails in cygwin because of \\r chars, npm fails after I configured Python, env variables with "weird error 1". That is not helpful.

But I don't want to npm anyway. I did download a mime.js and just require it directly. My list of requires below. I would like to do the same with serial port. This means I can deliver my entire source tar, and users only have to install vanilla node.js, and no messing around with npm/python

So how can I get the source code of serialport require it as my own module like mime, sprintv below.

http = require('http'),
url = require('url'),
path = require('path'),
fs = require('fs'),
proc = require('child_process'),
mime = require('./mime.js'), // mime is not intrinsic
stdio = require('./sprintv.js'), // sprintf type function via dummy stdio

You can not do that for serialport because serialport has C/C++ source code.

npm install not only download the source but also download dependencies and compile them for each platform.

Anyway, if you can compile C/C++ using node-gyp you can download serialport here:

goto https://github.com/voodootikigod/node-serialport

then click Download ZIP

I made another run at installing serial port. According to instructions at voodootikigod I downloaded python 2.7.6, and Visual Studio Express 2013 for Windows Desktop.

I executed the following script:

set path=%path%;C:\Python27
npm install node-gyp -g
git clone https://github.com/voodootikigod/node-serialport.git
cd node-serialport
node-gyp configure
node-gyp build

It finished succesfully announcing the it had built to .\\node-serial\\build\\Release\\serialport.node

The node executable in c:\\program files\\nodejs is unchanged and cannot require "serialport"

If I try to execute to script in .\\node-serial\\bin\\serialportList.js

#!/usr/bin/env node

var serialport = require('../');
var sf = require('sf');

serialport.list(function (err, results) {
  if (err) {
    throw err;
  }

  for (var i = 0; i < results.length; i++) {
    var item = results[i];
    console.log(sf('{comName,-15} {pnpId,-20} {manufacturer}', item));
  }
});

It fails with: Cannot find module 'bindings'. I installed that and then 'async', 'sf'

I also don't understand what require('../'); should do. Require everything from previous directory?

That executes but unfortunately I haven't got a serial port connected right now :( So it displays nothing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM