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

Parity Error Under Linux #219

Closed
ergousha opened this issue Sep 19, 2013 · 20 comments
Closed

Parity Error Under Linux #219

ergousha opened this issue Sep 19, 2013 · 20 comments
Labels

Comments

@ergousha
Copy link

I am using this simple code to send a byte through serialport. And I watch the result with a logic analyser hardware. As it seems below, same code produces expected correct result under Windows, but it gives a parity error under Linux (Raspberry Pi)
I intended to use 'even' parity which is apparently the problem. Windows version interprets correct, but Linux version fails and using default value 'none'.
When I use parity default value 'none' I got same result for both Windows and Linux.

var sp = new SerialPort('/dev/ttyAMA0', {
baudRate: 19200,
dataBits: 8,
parity: 'even',
stopBits: 1,
flowControl: false
});

var serialBuffer = new Buffer([0x01]);
sp.write(serialBuffer);

untitled-4

@JayBeavers
Copy link
Collaborator

Do you have a suggested patch?

What is the hardware environment you're using to monitor? Looks like you're using a protocol analyzer?

@ergousha
Copy link
Author

Yes, I hardwired to computer's serial port and I am using a protocol analyzer. I am pretty sure about the result. I am electronics engineer using such measurement tools long time. http://www.saleae.com/logic
I looked at source code and I saw there are two versions for Windows and Unix. (serialport_unix.cpp and serialport_win.cpp) First I suspected that 'even' parameter is interpreted wrong by unix code. There is a switch statement. But I do not have IDE to debug.
serialport_unix.cpp line 163:
switch (data->parity)
{
case SERIALPORT_PARITY_NONE:

I have also looked at tests included in source. They use parity 'none'. I think echo test will fail when 'even' parameter is selected.

@joshmh
Copy link
Contributor

joshmh commented Sep 28, 2013

This should fix it: #220

@voodootikigod
Copy link
Collaborator

Can you verify this with the latest 1.2.1 release?

@ergousha
Copy link
Author

ergousha commented Oct 3, 2013

I have got some unexpected results at first sight. I will share my feedback after further investigation.

@ergousha
Copy link
Author

ergousha commented Oct 8, 2013

Please find my latest test results below. This is latest version 1.2.2

I matched Windows version with Linux version. Windows version produces all results correctly. It looks like setting parity has effect on databits.

Before releasing a new version, if you need me to test, I would gladly contribute to the project.

untitled-1

@voodootikigod
Copy link
Collaborator

@ergousha how did you generate those graphs?

@ergousha
Copy link
Author

Results measured with logic analyser hardware connected to computer's serial port. Then this measurements interpereted when I enter expected parameters, so it tries data to split into frames and shows errors.
I am pretty sure about results. If you wish to see the process, I can record a video too..
Why I thought to use analyser, because I had an application working on Windows, when I ported it to Linux it did not worked. I looked into communication signals and I saw parity creates error.

@robinxc
Copy link

robinxc commented Oct 31, 2013

yes i find this bug last year.
you could alter the serialport_unix.cpp
switch (data->parity....

@voodootikigod
Copy link
Collaborator

We are aware of the issue, we are working on a fix that doesn't break
everything else. Someone proposed a change, but much like @qindl
suggestion, but it broke many other things. Working on it.

On Thu, Oct 31, 2013 at 10:49 AM, qindl [email protected] wrote:

yes i find this bug last year.
you could alter the serialport_unix.cpp

switch (data->parity....


Reply to this email directly or view it on GitHubhttps://github.com//issues/219#issuecomment-27491967
.

Chris Williams

@voodootikigod http://twitter.com/voodootikigod |
GitHubhttp://github.com/voodootikigod

The things I make that you should check out:
SaferAging http://www.saferaging.com/ | JSConf http://jsconf.com/ |
RobotsConf http://robotsconf.com/ | RobotsWeeklyhttp://robotsweekly.com/

Help me end the negativity on the internet, share
thishttp://jsconf.eu/2011/an_end_to_negativity.html
.

@voodootikigod
Copy link
Collaborator

@ergousha can you try out this branch: https://github.com/voodootikigod/node-serialport/tree/databits

Thank you,

@ergousha
Copy link
Author

ergousha commented Nov 3, 2013

The new branch gives an error at the serial port opening. (even with default opening parameters)

events.js:72
throw er; // Unhandled 'error' event
^
Error: Serialport not open.
at SerialPortFactory.SerialPort.close (/home/neo/www/node_modules/serialport/serialport.js:390:17)
at Object. (/home/neo/www/sertest.js:12:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3

@voodootikigod
Copy link
Collaborator

Can you please provide the code snippet you are using? I am not seeing
similar on my side.

Thank you,

On Sun, Nov 3, 2013 at 4:29 AM, Ergin Akin [email protected] wrote:

The new branch gives an error at the serial port opening. (even with
default opening parameters)

events.js:72
throw er; // Unhandled 'error' event
^
Error: Serialport not open.
at SerialPortFactory.SerialPort.close
(/home/neo/www/node_modules/serialport/serialport.js:390:17)
at Object. (/home/neo/www/sertest.js:12:4)
at Module.
_compile (module.js:456:26) at Object.Module._extensions..js
(module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3


Reply to this email directly or view it on GitHubhttps://github.com//issues/219#issuecomment-27641346
.

Chris Williams

@voodootikigod http://twitter.com/voodootikigod |
GitHubhttp://github.com/voodootikigod

The things I make that you should check out:
SaferAging http://www.saferaging.com/ | JSConf http://jsconf.com/ |
RobotsConf http://robotsconf.com/ | RobotsWeeklyhttp://robotsweekly.com/

Help me end the negativity on the internet, share
thishttp://jsconf.eu/2011/an_end_to_negativity.html
.

@ergousha
Copy link
Author

ergousha commented Nov 3, 2013

var serialport = require("serialport");
var serialBuffer = new Buffer([0x01, 0x02, 0x03]);

var SerialPort = serialport.SerialPort;

var sp = new SerialPort("/dev/ttyAMA0");

sp.on("open", function () {
var myVar=setInterval(function(){sp.write(serialBuffer)},1000);
});

sp.close();

Or

var serialport = require("serialport");
var serialBuffer = new Buffer([0x01, 0x02, 0x03]);

var SerialPort = serialport.SerialPort;

var sp = new SerialPort("/dev/ttyAMA0", {
baudRate: 19200,
dataBits: 8,
parity: 'none',
stopBits: 1,
flowControl: false
});

sp.on("open", function () {
var myVar=setInterval(function(){sp.write(serialBuffer)},1000);
});

sp.close();

@voodootikigod
Copy link
Collaborator

Move the close into the .on open callback and it will work fine

On Sunday, November 3, 2013, Ergin Akin wrote:

var serialport = require("serialport");
var serialBuffer = new Buffer([0x01, 0x02, 0x03]);

var SerialPort = serialport.SerialPort;

var sp = new SerialPort("/dev/ttyAMA0");

sp.on("open", function () {
var myVar=setInterval(function(){sp.write(serialBuffer)},1000);
});

sp.close();

Or

var serialport = require("serialport");
var serialBuffer = new Buffer([0x01, 0x02, 0x03]);

var SerialPort = serialport.SerialPort;

var sp = new SerialPort("/dev/ttyAMA0", {
baudRate: 19200,
dataBits: 8,
parity: 'none',
stopBits: 1,
flowControl: false
});

sp.on("open", function () {
var myVar=setInterval(function(){sp.write(serialBuffer)},1000);
});

sp.close();


Reply to this email directly or view it on GitHubhttps://github.com//issues/219#issuecomment-27648749
.

Chris Williams

@voodootikigod http://twitter.com/voodootikigod |
GitHubhttp://github.com/voodootikigod

The things I make that you should check out:
SaferAging http://www.saferaging.com/ | JSConf http://jsconf.com/ |
RobotsConf http://robotsconf.com/ | RobotsWeeklyhttp://robotsweekly.com/

Help me end the negativity on the internet, share
thishttp://jsconf.eu/2011/an_end_to_negativity.html
.

@ergousha
Copy link
Author

ergousha commented Nov 3, 2013

I confirm that problem is fixed 👍

Tested under Linux with 19600 baud rate.
Test parameters and results:
8N1 OK
8E1 OK
8O1 OK
7N1 OK
7E1 OK
7O1 OK

@robinxc
Copy link

robinxc commented Nov 4, 2013

parity: "even" ERROR ;could not used

log:
[root@router-cmcc tests]# node readtest.js
=>connected
writed all
/home/Router/test/serial/tests/readtest.js:1956: Uncaught ReferenceError: data is not defined

readtest.js code:

var portName = '/dev/ttyS3';
var serial_port = new SerialPort(portName, {
baudRate: 2400,
dataBits: 8,
parity: "even",
stopBits: 1,
flowControl: false
});
var buf5 = new Buffer(8);
buf5[0] = "0x1"
buf5[1] = "0x03"
buf5[2] = "0x00"
buf5[3] = "0x26"
buf5[4] = "0x00"
buf5[5] = "0x3"
buf5[6] = "0xe4"
buf5[7] = "0x0"

serial_port.on("open", function () {
console.log('connected');
serial_port.write(buf5);
console.log('writed all');
})

serial_port.on("data", function (data) {
console.log('data received: ' + data);
for(var i=0;i<data.length;i++){
console.log('-'+ data.slice(i,i+1).toString('hex').toUpperCase());
}
//util.puts("here: "+data);
})

serial_port.on("error", function (msg) {
util.puts("error: "+msg);
})
repl.start("=>")

@voodootikigod
Copy link
Collaborator

Merged in. @robinxc looks like an error in your code.

@robinxc
Copy link

robinxc commented Nov 6, 2013

what error? show me :)

@ergousha
Copy link
Author

My declared problem solved by databits branch.

@lock lock bot locked as resolved and limited conversation to collaborators May 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

5 participants