hparra / ruby-serialport

ruby-serialport is a Ruby library that provides a class for using RS-232 serial ports
http://rubygems.org/gems/serialport
GNU General Public License v2.0
246 stars 58 forks source link

XON is always activated #58

Open jvalrog opened 9 years ago

jvalrog commented 9 years ago

I'm trying to control an Arduino board with serialport, but I'm having difficulties. I'm calling "readbyte" several times to retrieve binary data, but it triggers a timeout at random intervals.

I found that the solution was to open the Arduino IDE, open the Serial Monitor, and close it. By doing this, the Arduino IDE changed some parameters in the serial port and all the errors were gone after that.

Arduino requires no xon/xoff protocol.

So I investigated a bit and found that "serialport" disables xoff but not xon, while the arduino ide disabled both.

The output of "stty --file=/dev/ttyUSB0 -a" after opening the serial port with "serialport" is this (only interesting lines):

werase = ^W; lnext = ^V; flush = ^O; min = 0; time = 10;
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl ixon -ixoff

And the output after opening it with the Arduino IDE is this:

werase = ^W; lnext = ^V; flush = ^O; min = 0; time = 0;
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff

The only differences are the "time = 0" and "-ixon". I'm opening the port with this code:

@serial = SerialPort.new(port, BAUDRATE, 8, 1, SerialPort::NONE)

I don't understand why XON is not disabled.

Also wanted to thank you for coding this gem!

jvalrog commented 9 years ago

This issue is related to this one: https://github.com/hparra/ruby-serialport/issues/34

Same problem/bug. I had to add "@serial.flow_control = SerialPort::NONE" by hand to fix my problem.