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 ignores bytes = 0x11 #34

Open
atimin opened this issue Jun 11, 2012 · 8 comments
Open

Serialport ignores bytes = 0x11 #34

atimin opened this issue Jun 11, 2012 · 8 comments

Comments

@atimin
Copy link

atimin commented Jun 11, 2012

Very strange behavior! Teh serial port doesn't receive bytes which equal 0x11. I have tried to receive same package with other tool (CuteCom) and I have had success. I don't have idea what it may be...

  #Device send: [0x10][0x11][0x12]
  sp.read.unpack('c*')  #=> [16,18] 

Ruby - 1.9.3
OS. Ubuntu 12.04-amd64

@willglynn
Copy link

0x11 is XON (see http://en.wikipedia.org/wiki/Software_flow_control). Is #flow_control set to SerialPort::NONE?

@atimin
Copy link
Author

atimin commented Jul 17, 2012

Yes it is!

  sp.flow_control #=> 2 (SOFT)

I have added `sp.flow_control = SerialPort::NONE' in my code and I have success. Thank you!
But I think this behavior is unexpected and the flow control must be disabled by default.

@trevorms
Copy link

Here is the fix for this issue...one character was missing:

diff --git a/ext/native/posix_serialport_impl.c b/ext/native/posix_serialport_impl.c
index 11294fa..7747969 100644
--- a/ext/native/posix_serialport_impl.c
+++ b/ext/native/posix_serialport_impl.c
@@ -157,7 +157,7 @@ VALUE sp_create_impl(class, _port)

    params.c_oflag = 0;
    params.c_lflag = 0;
-   params.c_iflag &= (IXON | IXOFF | IXANY);
+   params.c_iflag &= ~(IXON | IXOFF | IXANY);
    params.c_cflag |= CLOCAL | CREAD;
    params.c_cflag &= ~HUPCL;
  1. Clone this repo
  2. Apply the above patch
  3. gem build serialport.gemspec
  4. gem install serialport-1.1.0.gem --local

@ghost
Copy link

ghost commented Aug 22, 2013

@hparra : what do you think about this fix here?

@hparra
Copy link
Owner

hparra commented Aug 29, 2013

I'm not entirely sure. It seems the problem is just an unexpected default setting. In that case I'm reluctant to commit the line change because it could break existing systems dependent on this gem.

I welcome @FLIPBack and @trevorms to chime in.

@trevorms
Copy link

The original line of code that does not turn off XON/XOFF flow control (params.c_iflag &= (IXON | IXOFF | IXANY);), is clearing all the other bits in the params.c_iflag variable that perhaps should not be cleared. The original line of code will ensure that all the bits are cleared except the IXON, IXOFF and IXANY bits...unless of course this was the original intention. I have used this change successfully and the default is XON/XOFF flow control is disabled.

@trevorms
Copy link

BTW...thanks for the great gem @hparra...I use it a lot in my hardware development work.

@corecode
Copy link

corecode commented Dec 6, 2016

This looks pretty much like a bug in the original code. What will it take to fix this?

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