Handshake Issue on Windows Machines
Closed this issue · 5 comments
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
0.11.3 (currently master) should fix this. Would appreciate the feedback if you try it. I'm not able to test it.
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?
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:
- Try explicitly specifying the COM port your arduino is connected to like:
Dino::TxRx::Serial.new(device: "COM5")
- Play around with the
sleep
parameter and see what happens. Anything less than ~2 seconds and mine raises.
I fixed this issue. Please see #71 . Thanks.
As of 7fcf387, 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.