austinbv / dino

Dino is a ruby gem that helps you bootstrap prototyping with an Arduino
MIT License
388 stars 84 forks source link

Handshake Issue on Windows Machines #66

Closed wengzilla closed 9 years ago

wengzilla commented 10 years ago

Running into a handshake issue on Windows machines for the 0.11.2 gem version.

board = Dino::Board.new(Dino::TxRx::Serial.new) seems to be timing out. Gem version 0.10.0 still works well...

See backtrace here: https://gist.github.com/wengzilla/7d473529139c6d904b87

vickash commented 10 years ago

0.11.3 (currently master) should fix this. Would appreciate the feedback if you try it. I'm not able to test it.

wengzilla commented 10 years ago

I pulled from master, built the gem locally and installed. Same problem. Anything you want me to try?

Also, just of curiosity... What happened in the 0.10 to 0.11 upgrade that would make something like this happen?

vickash commented 10 years ago

Try editing lib/dino/txrx/base.rb. Replace #handshake with the following: (for 0.11.3)

def handshake
  io
  sleep 5

  write("!9000000.")
  line = gets(1)
  if line && line.match(/ACK:/)
    flush_read
    return line.chop.split(/:/)[1]
  end
  raise BoardNotFound
end

I'm not 100% sure what causes it, but the board just doesn't respond for the first 2 or 3 seconds on Windows. I've noticed this on my machine, even when using the Arduino serial monitor.

In 0.10, if you had a line right after Board#new, without sleeping for a few seconds, you would end up sending commands that never got to the board. If you just want to blink an LED or read a sensor it would start eventually but this is a problem if your code needs to initialize hardware to some known state.

In 0.11 I added the handshake to make sure the board was ready before anything else happens.

The replacement for #handshake above, initializes the SerialPort object in ruby (by calling io), and then sleeps for 5 seconds before trying to send anything. If this is reliable we'll have to modify the handshake to be platform specific, so as to not keep *nix users waiting around.

Other things to try:

takaokouji commented 10 years ago

I fixed this issue. Please see #71 . Thanks.

vickash commented 9 years ago

As of https://github.com/austinbv/dino/commit/7fcf387132dbda80f7ae34d203e71cb113da7e9e, we are using the rubyserial gem, I have made the handshake routine better, and there are a couple other fixes for enumerating the callbacks hash that raised exceptions in Windows.

I have tested that commit extensively on Windows XP and 7 for both input and output and it's more reliable than anything previously done with the serialport gem. However, you must still explicitly specify the COM port. Enumeration doesn't work like in *nix yet.