curious_guy
curious_guy

Reputation: 91

Install node-serialport module on arm-linux

I have been using node-serialport on my linux X86 machine and it works great. Now I am trying to install node-serialport on an embedded platform running arm linux. I managed to cross compile the node itself and able to run node/npm on the target platform.

However, simply running npm install serialport does not work:

binary not available for your platform 

and then npm launches the build using node-gyp. Unfortunately the build requires Python which is not available on my embedded platform (tried to cross compile python without success :( )

Can anyone please help me to cross-compile serial port on my linux machine? I have tried a lot of methods on the web but all of them failed for one reason or the other

Upvotes: 5

Views: 2956

Answers (2)

niczak
niczak

Reputation: 3917

For anybody who comes across this post (I know it's old) as of version 5.x you CAN build for ARM directly on the device, say a Raspberry Pi for example.

I just don't want developers who want to use this library to be turned off by the notion of having to cross compile because as we all know, it's a pain!

Upvotes: 1

curious_guy
curious_guy

Reputation: 91

I managed to do the cross-compile serial port finally, using ugliest of methods :) Following is the method that worked:

On native x86 linux box, cd <your work area>

Setup the cross_compiler tool environment variables:

export AR=arm-marvell-linux-gnueabi-ar
export CC=arm-marvell-linux-gnueabi-gcc
export CXX=arm-marvell-linux-gnueabi-g++
export LINK=arm-marvell-linux-gnueabi-g++
export npm_config_arch=arm
export npm_config_nodedir=/home/ysoni/node

Now run npm install. Please note that since npm install insisted that I should compile 64bit package,so I had to provide manually --package_name, --hosted_path etc. I got those params from serialport website.

npm install serialport --arch=x64 --target_arch=arm  --remote_path=./serialport/v1.4.0/Release/ --package_name=node-v11-linux-ia32.tar.gz --staged_tarball=build/stage/serialport/v1.4.0/Release/node-v11-linux-ia32.tar.gz --hosted_path=https://node-serialport.s3.amazonaws.com/serialport/v1.4.0/Release/ --hosted_tarball=https://node-serialport.s3.amazonaws.com/serialport/v1.4.0/Release/node-v11-linux-ia32.tar.gz

A node_modules directory will be generated that contains .bin and serialport folders. Now, copy the contents of node_modules to your target_platform. I wrote a sample .js script to test if serial device could be opened. The script has to be in the same directory as node_modules.

Expectedly there has to be one last roadblock !! Weird enough, I had to do some renaming. This may not be necessary for your platform:

busybox mv node_modules/serialport/build/serialport/v1.4.2/Release/node-v11-linux-arm/ node_modules/serialport/build/serialport/v1.4.2/Release/v8-3.11-linux-arm/

In the end, I am able to open the serialport and ready contents. I really hope that there is easier way out there !

Happy hacking !!

Upvotes: 2

Related Questions