Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SerialPort on Galileo-io #1086

Closed
ortizvinicius opened this issue Apr 7, 2016 · 28 comments
Closed

SerialPort on Galileo-io #1086

ortizvinicius opened this issue Apr 7, 2016 · 28 comments

Comments

@ortizvinicius
Copy link

Hi, im using johnny-five with galileo-io in a galileo gen 2 running yocto, i am trying to set a serial communication with SerialPort module, but i am getting the error: "Illegal instruction"

The code:

var Serialport = require("serialport").SerialPort;
var five = require("johnny-five");
var Galileo = require("galileo-io");
var board = new Galileo();

board.on("ready", function() {
  var sp = new Serialport("/dev/ttyS0", {
    baudRate: 57600
  });

  sp.on("open", function() {
    console.log("Port is open!");

    // Once the port is open, you may read or write to it.
    sp.on("data", function(data) {
      console.log("Received: ", data);
    });

    setInterval(function(){ sp.write(new Buffer(["0120000003"])) }, 5000);
  });
});
@rwaldron
Copy link
Owner

rwaldron commented Apr 8, 2016

There are a couple issues with this code, let me help clarify some parts for you:

var Serialport = require("serialport").SerialPort;
var five = require("johnny-five");
var Galileo = require("galileo-io");
var board = new five.Board({
  io: new Galileo()
});

board.on("ready", function() {
  var sp = new Serialport("/dev/ttyS0", {
    baudRate: 57600
  });

  sp.on("open", function() {
    console.log("Port is open!");

    // Once the port is open, you may read or write to it.
    sp.on("data", function(data) {
      console.log("Received: ", data);
    });

    setInterval(function(){ sp.write(new Buffer(["0120000003"])) }, 5000);
  });
});

Note the changes to Board initialization.

Another issue is the call to new Buffer(["0120000003"]), which I'm not sure what you're trying to write, but that just results in the following: <Buffer 03>

Can you try the updated code and let me know what happens? Thanks!

@ortizvinicius
Copy link
Author

Same result:

1460118111287 Device(s) Intel Galileo Gen 2 
1460118111426 Connected Intel Galileo Gen 2 
1460118111444 Repl Initialized 
\>> Illegal instruction

About new Buffer(["0120000003"]) Im trying to write the string "0120000003", the correct way is new Buffer("0120000003") ?

@rwaldron
Copy link
Owner

rwaldron commented Apr 8, 2016

@ortizvinicius that depends, are you trying to send the string of characters "0120000003"? Or series of bytes that is comprised of those values?

> new Buffer("0120000003")
<Buffer 30 31 32 30 30 30 30 30 30 33>
> new Buffer([0,1,2,0,0,0,0,0,0,3])
<Buffer 00 01 02 00 00 00 00 00 00 03>

@ortizvinicius
Copy link
Author

string of characters

@rwaldron
Copy link
Owner

rwaldron commented Apr 8, 2016

Got it—then give that a try :)

@ortizvinicius
Copy link
Author

both have the same result :/

@rwaldron
Copy link
Owner

rwaldron commented Apr 8, 2016

Can you paste the entire output?

Then, try just this:

var Serialport = require("serialport").SerialPort;
var sp = new Serialport("/dev/ttyS0", {
  baudRate: 57600
});

sp.on("open", function() {
  console.log("Port is open!");

  // Once the port is open, you may read or write to it.
  sp.on("data", function(data) {
    console.log("Received: ", data);
  });

  sp.write(new Buffer("0120000003"));
});

And paste the result as well

@ortizvinicius
Copy link
Author

For the first the output is:

1460118111287 Device(s) Intel Galileo Gen 2 
1460118111426 Connected Intel Galileo Gen 2 
1460118111444 Repl Initialized 
\>> Illegal instruction

For the last is just illegal instruction

@rwaldron
Copy link
Owner

rwaldron commented Apr 8, 2016

Ok, so that means this bug isn't in Johnny-Five or Galileo-IO. Let's keep narrowing it down... try this:

var Serialport = require("serialport").SerialPort;
var sp = new Serialport("/dev/ttyS0", {
  baudRate: 57600
});

(and nothing else)

@ortizvinicius
Copy link
Author

illegal instruction

@ortizvinicius
Copy link
Author

with this last code i got illegal instruction too

@fivdi
Copy link
Contributor

fivdi commented Apr 8, 2016

It looks like there is something wrong with binaries somewhere. Perhaps Node.js binaries or serialport binaries.

@rwaldron
Copy link
Owner

rwaldron commented Apr 8, 2016

@ortizvinicius thanks for your patience, one last thing to try before we talk about refiling this over at node-serialport.

Try:

var Serialport = require("serialport").SerialPort;
var sp = new Serialport("/dev/ttyS0");

Then:

var Serialport = require("serialport").SerialPort;

Then, at the terminal, type:

node -e "console.log(require('fs').existsSync('/dev/ttyS0'))";

@ortizvinicius
Copy link
Author

Thank you.

Well, the first shows illegal instruction, the second shows nothing, and the last says only "true"

@rwaldron
Copy link
Owner

rwaldron commented Apr 8, 2016

This is very helpful, let's first ping @reconbot and have him read up on the thread and then help us figure out the move forward

@henricavalcante
Copy link
Contributor

I dont know if it can help but have you tried to run as root access with sudo?

@ortizvinicius
Copy link
Author

@henricavalcante sudo dont work in yocto

@reconbot
Copy link
Collaborator

reconbot commented Apr 8, 2016

Can you try something for me?

var Serialport = require("serialport").SerialPort;
var sp = new Serialport("/dev/ttyS0", console.log);

And give the output?

Also what version of yocto are you running on the Galileo?

@fivdi
Copy link
Contributor

fivdi commented Apr 8, 2016

@reconbot is it possible that it's happening because pre-compiled serialport binaries are being installed but that the binaries don't or can't work on a Galileo?

Is it possible to somehow force serialport to be compiled rather than have pre-compiled binaries installed when npm install serialport is called?

@ortizvinicius
Copy link
Author

Hi @reconbot the code outputs only "Illegal Instruction"

I'm not sure of how to see the version haha, but i think is 201409031130

@rwaldron
Copy link
Owner

rwaldron commented Apr 8, 2016

is it possible that it's happening because pre-compiled serialport binaries are being installed but that the binaries don't or can't work on a Galileo?

As far as I can tell this is exactly the problem. When I was telling @reconbot about this (he's about 3 feet away from me), I remembered when I wrote this, I was unable to use Serialport and ended up using fs.createReadStream.

@reconbot
Copy link
Collaborator

reconbot commented Apr 8, 2016

@ortizvinicius Now, please try the latest beta version of serialport, we've recently made some changes and it would be helpful to know if they change anything for you. See serialport/node-serialport#733 for more details.

serialport@2.0.7-beta5

@fivdi we don't yet have precompiled arm binaries so I don't think that would be the case, but the binary does seem to be compiled with unsupported cpu instructions. node-pre-gyp rebuild would rebuild the binary. (you might have to fish the command out of your node_modules/.bin/ directory)

@ortizvinicius
Copy link
Author

Instaled the beta and the outputs is illegal instruction again

@reconbot
Copy link
Collaborator

reconbot commented Apr 8, 2016

Alright, lets move this to the right project. Please open a new issue on node-seriaport and we'll debug there. I have a galileo at home that might still work. I know for sure we work on an edison, but you might have to do some tricks to get it to use the older system.

@fivdi
Copy link
Contributor

fivdi commented Apr 8, 2016

The Galileo 2 is from Intel so it's not going to have an ARM processor!!! It has an Intel Quark SoC X1000 processor which supports the Pentium instruction set. I'm unsure how compatible this processor is with the processors in PCs but would imagine that the serialport install process detects it as an Intel processor and installs pre-compiled Intel binaries.

@reconbot
Copy link
Collaborator

reconbot commented Apr 8, 2016

Ahh good point! That's a mistake on my part. We should still move the issue over to the right project, but Did the rebuild work?

@fivdi
Copy link
Contributor

fivdi commented Apr 8, 2016

I haven't tried yet. I haven't used a Galileo 2 since sometime early last year but will take a look and see.

@ortizvinicius
Copy link
Author

Moved to serialport/node-serialport#747
Thank you guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants