hybridgroup / rubyserial

FFI Ruby library for RS-232 serial port communication
https://rubygems.org/gems/rubyserial
Other
154 stars 27 forks source link

Enhancement Request: Allow for easier opening of COMx (x>=10) on Windows #22

Closed swabianeagle closed 9 years ago

swabianeagle commented 9 years ago

I'm using rubyserial 0.2.1.

Currently, when using rubyserial on Windows I get the following results when opening a serial port:

irb(main):001:0> require 'rubyserial'
=> true
irb(main):002:0> ser1=Serial.new("COM8")
=> #<Serial:0x000000024ecc88 @fd=#<FFI::Pointer address=0x00000000000098>, @open=true>
irb(main):003:0> ser2=Serial.new("COM17")
RubySerial::Exception: ERROR_FILE_NOT_FOUND
        from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rubyserial-0.2.1/lib/rubyserial/windows.rb:10:in `initialize'
        from (irb):3:in `new'
        from (irb):3
        from C:/Ruby21-x64/bin/irb:11:in `<main>'
irb(main):004:0> ser2=Serial.new("\\\\.\\COM17")
=> #<Serial:0x0000000329a448 @fd=#<FFI::Pointer address=0x0000000000009c>, @open=true>

Arguably it is my mistake that opening COM17 fails the first time, but it seems asymmetric to me that it works with COM8.

I added the following line to windows.rb and this seems to work: added this to Serial#initialize (windows.rb, line 5) address = "\\\\.\\#{address}" # needed for com-ports >= COM10

Now the behavior is symmetric:

irb(main):001:0> require 'rubyserial'
=> true
irb(main):002:0> ser1=Serial.new( "COM8" )
=> #<Serial:0x00000002dd7640 @fd=#<FFI::Pointer address=0x00000000000098>, @open=true>
irb(main):003:0> ser2=Serial.new( "COM17" )
=> #<Serial:0x0000000341a2f0 @fd=#<FFI::Pointer address=0x0000000000009c>, @open=true>

Adding the prefix multiple times doesn't seem to matter (I've tried it), so it should be safe to blindly add the prefix by default as I did.

Maybe this could be added in the next release.

zankich commented 9 years ago

@swabianeagle good catch, I would accept a pull request from you with this change, if you'd be so kind!

swabianeagle commented 9 years ago

Hi Adrian,

sorry for my ignorance as I don't know git very well. What exactly do I have to do to create a pull request.

Armin

On January 20, 2015 at 2:50 PM Adrian Zankich notifications@github.com wrote:

@swabianeagle good catch, I would accept a pull request from you with this change, if you'd be so kind!


Reply to this email directly or view it on GitHub: https://github.com/hybridgroup/rubyserial/issues/22#issuecomment-70720136

zankich commented 9 years ago

First you'll want to fork this repo, https://help.github.com/articles/fork-a-repo/, and make the appropriate changes in your fork of rubyserial. Once you have your changes in place, you will see a pull request button, which is a green square with two arrows pointing towards each other. Hit that button and you're good to go! Here's github's help docs too about pull requests https://help.github.com/articles/using-pull-requests/#initiating-the-pull-request

f3rno commented 9 years ago

Can you please tag a new release with this fix? It's a fairly serious problem on windows systems. Also, keeping the issue open is sure to cause some confusion, given that the issue is fixed in master (but not in the latest release).

deadprogram commented 9 years ago

Ulp! You are right, let me see if we can fix that today.

deadprogram commented 9 years ago

I just released version 0.2.3 please make sure this corrects your issue, and reopen if not. Thanks!