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

Bluetooth to serial interface not working on Windows #29

Open
digamesystems opened this issue Oct 12, 2011 · 7 comments
Open

Bluetooth to serial interface not working on Windows #29

digamesystems opened this issue Oct 12, 2011 · 7 comments

Comments

@digamesystems
Copy link

Hi.

I've been using your nice gem for a while now on different projects. Thanks!

Recently, I've been trying to connect to a serial device using a bluetooth tranceiver module to provide a wireless interface back to my laptop.

http://www.mdfly.com/index.php?main_page=product_info&cPath=8_47&products_id=769&zenid=h6pb9e47rc6klkvkiattb6uot4

(There are other, similar devices people have used to talk to Arduinos, etc...)

The module initiates a bluetooth connection with my laptop and creates a virtual serial port on my Windows system. I simply pair the device w/windows using a passkey and a new serial port is generated.

Using Hyperterm or Teraterm or other programs I've written in VB and C# I can open this port and communicate with my device as if the bluetooth link were just a serial connection.

I figured I could do the same thing with your library, but I'm having problems. (I've never had problems with standard serial or USB-Serial devices I've used, though)

Here's what's happening.

Standard com port on com1
Bluetooth serial port on com2
(Again, Hyperterminal, TeraTerm and other programs seem to connect to Com2 fine...)

C:>ruby --version
ruby 1.9.2p180 (2011-02-18) [i386-mingw32]

C:>gem list serialport

*** LOCAL GEMS ***

serialport (1.0.4)

C:>irb
irb(main):001:0> require 'serialport'
=> true
irb(main):003:0> sp0=SerialPort.new(0)
=> #<SerialPort:fd 3>
irb(main):004:0> sp0.get_modem_params
=> {"baud"=>115200, "data_bits"=>8, "stop_bits"=>1, "parity"=>0}
irb(main):005:0> sp1=SerialPort.new(1)
Errno::EINVAL: Invalid argument - .\COM2
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/serialport-1.0.4/lib/serialport.rb:16:in create' from c:/Ruby192/lib/ruby/gems/1.9.1/gems/serialport-1.0.4/lib/serialport.rb:16:innew'
from (irb):5
from c:/Ruby192/bin/irb:12:in `

'
irb(main):006:0>

Thanks for your help!

John.

@digamesystems
Copy link
Author

Checking in... Any thoughts on this?

@hparra
Copy link
Owner

hparra commented May 26, 2012

Sorry. I wasn't ignoring. I've been traveling for almost a year now. Took a quick look at code. This should work. Have you tried specifying that port using the string, "COM2"? Any different?

@dolzenko
Copy link

+1 with Huawei modem. Opening real serial port (COM1) works fine.

@digamesystems
Copy link
Author

I let this go a while ago and focused on using your gem on USB serial ports. I've got a project going now where I'm really going to have to figure out this Bluetooth thing...

I've upgraded to 1.1.0 and see the same behavior. "COM2" Shows the same error.

Windows 7 pro,

c:\users\john>ver

Microsoft Windows [Version 6.1.7601]

c:\users\john>ruby --version
ruby 1.9.3p125 (2012-02-16) [i386-mingw32]

c:\users\john>gem list serialport

*** LOCAL GEMS ***

serialport (1.1.0, 1.0.4)

c:\users\john>irb
irb(main):002:0> require 'serialport'
=> true
irb(main):003:0> sp2=SerialPort.new(2)
Errno::EINVAL: Invalid argument - .\COM3
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/serialport-1.1.0/lib/serialport.rb:16:in create' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/serialport-1.1.0/lib/serialport.rb:16:innew'
from (irb):3
from C:/Ruby193/bin/irb:12:in <main>' irb(main):004:0> sp2=SerialPort.new("COM3") Errno::EINVAL: Invalid argument - \\.\COM3 from C:/Ruby193/lib/ruby/gems/1.9.1/gems/serialport-1.1.0/lib/serialport.rb:16:increate'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/serialport-1.1.0/lib/serialport.rb:16:in new' from (irb):4 from C:/Ruby193/bin/irb:12:in

'

As in the earlier report, Hyperterminal, Teraterm, and code I've written in VB and C# all seem to be working fine with the device.

Driver details:
"Standard Serial over Bluetooth link (COM3)"
Driver provider: Microsoft
Driver Date: 6/21/2006
Driver Version: 6.1.7600.16385
Driver File: C:\Windows\System32\DRIVERS\bthmodem.sys

Any help would be greatly appreciated. -- I'd even be willing to lend one of these bluetooth modules to you for testing.

Regards,

John Price

@hparra
Copy link
Owner

hparra commented Jul 16, 2013

Hey guys. Unfortunately I haven't used Bluetooth devices with this gem on any OS. A half-baked attempt many years ago resulted in weirdness.

At first glance, I noticed that "Errno::EINVAL: Invalid argument - .\COM3" is missing a slash, but it's correctly stated some lines later. I thought it may have something to do with .\ (http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#win32_device_namespaces) as we explicitly prepended it to all values passed in to support COM values greater than 9.

The reason I bring that up is because the Errno::EINVAL error comes from the OS. I'm wondering if it doesn't like the .\ for bluetooth devices. The msdn doc above does mention it doesn't work for all APIs. It's the only idea I have at the moment.

@digamesystems
Copy link
Author

Thanks for getting back to me.

I'm wondering if there's a timeout happening in the API call to open the port. When I connect over Bluetooth in other languages, the unit spends a noticeable time (c.a. 3 seconds) negotiating with the host before I see the module's LED go from blinking (searching) to continuously on (locked), allowing me to send data to the device.

Thoughts?

@digamesystems
Copy link
Author

'Didn't mean to close. Sorry. (Wrong button).

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

3 participants