# Ruby-serialport on OS X?

**URL:** <https://www.ruby-forum.com/t/ruby-serialport-on-os-x/113685>\
**Category:** Ruby\
**Created:** [September 3, 2007, 10:50pm UTC](https://www.ruby-forum.com/t/ruby-serialport-on-os-x/113685 "2007-09-03T22:50:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [September 3, 2007, 10:50pm UTC](https://www.ruby-forum.com/t/ruby-serialport-on-os-x/113685/1 "2007-09-03T22:50:17Z")

</div>

has anyone run into any gotchas compiling ruby-serialport on OS X? I  
get the weirdest error message.

> > require “serialport.so”

NameError: (eval):1:in `private_class_method': undefined method `create’ for class `Class' from (eval):1 from (eval):1 from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:28:in `require’  
from (irb):1

> > x

there’s a .bundle file which is created when you compile, I’m guessing  
that’s a way to use Ruby with C. the bundle file has lots of binary  
stuff in there but you can also see Ruby code, with the create  
statement that Ruby’s objecting to here. I’m running Ruby 1.8.6.

This is the actual Ruby code in the bundle file:

class SerialPort  
private\_class\_method(:create)  
def SerialPort::new(port, \*params)  
sp = create(port)  
begin  
sp.set\_modem\_params(\*params)  
rescue  
sp.close  
raise  
end  
return sp  
end  
def SerialPort::open(port, \*params)  
sp = create(port)  
begin  
sp.set\_modem\_params(\*params)  
if (block\_given?)  
yield sp  
sp.close  
return nil  
end  
rescue  
sp.close  
raise  
end  
return sp  
end  
end

(with indentation added.)

ruby-serialport hasn’t seen active development since 2003, but all the  
blogs I’ve found say setting it up on OS X was a piece of cake. the  
Lego Mindstorms Bluetooth library ruby-nxt uses it and I’ve seen  
people use that with no problems. (or at least, no significant  
problems.) I’m totally stumped on this.

–  
Giles B.

Blog: [http://gilesbowkett.blogspot.com](http://gilesbowkett.blogspot.com)  
Portfolio: [http://www.gilesgoatboy.org](http://www.gilesgoatboy.org)  
Tumblelog: [http://giles.tumblr.com/](http://giles.tumblr.com/)

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [September 3, 2007, 10:57pm UTC](https://www.ruby-forum.com/t/ruby-serialport-on-os-x/113685/2 "2007-09-03T22:57:18Z")

</div>

Update: I went inside the bundle file and commented out the  
private\_class\_method line. Result was this error:

! irb

> > require “serialport”  
> > dyld: NSLinkModule() error  
> > dyld: bad local relocation length  
> > Trace/BPT trap

–  
Giles B.

Blog: [http://gilesbowkett.blogspot.com](http://gilesbowkett.blogspot.com)  
Portfolio: [http://www.gilesgoatboy.org](http://www.gilesgoatboy.org)  
Tumblelog: [http://giles.tumblr.com/](http://giles.tumblr.com/)

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [September 3, 2007, 10:59pm UTC](https://www.ruby-forum.com/t/ruby-serialport-on-os-x/113685/3 "2007-09-03T22:59:18Z")

</div>

Another update: Tried adding a blank create method - figured the  
private\_class\_method call might be trying to hit something defined in  
C. No dice:

! irb

> > require :serialport  
> > /opt/local/lib/ruby/site\_ruby/1.8/i686-darwin8.10.1/serialport.bundle:  
> > [BUG] Segmentation fault  
> > ruby 1.8.6 (2007-03-13) [i686-darwin8.10.1]

Abort trap

–  
Giles B.

Blog: [http://gilesbowkett.blogspot.com](http://gilesbowkett.blogspot.com)  
Portfolio: [http://www.gilesgoatboy.org](http://www.gilesgoatboy.org)  
Tumblelog: [http://giles.tumblr.com/](http://giles.tumblr.com/)

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [September 4, 2007, 9:58pm UTC](https://www.ruby-forum.com/t/ruby-serialport-on-os-x/113685/4 "2007-09-04T21:58:19Z")

</div>

> Don’t edit .bundle files. It won’t achieve anything and just give you  
> nasty errors (as you’ve found) 🙂 It’s /sort of/ the equivalent of .so  
> files like you’d find on Linux, so any code in there is basically just  
> debugging stuff.

The code in the .bundle file definitely did _something_, as the errors  
I got changed when I edited the .bundle file.

I don’t know what .so files are, though. I do know you can require  
serialport with a .so extension, though, even though the file doesn’t  
really have one. that’s a bit odd.

> I can’t really help though. I use ruby-serialport for interacting with  
> a GPRS / SMS modem and it compiled fine. I had to change the  
> references to /dev/ttyS etc to the device names of my modem, but it  
> all went okay. This was on PowerPC at the time though… I haven’t  
> tried on Intel since.

I know it compiles on Intel. according to various blogs most people  
have seen it compile more or less effortlessly. I don’t get it - my  
system’s pretty standard. I’ll look into changing the device names,  
though, that’s probably key. a lot of blogs mention that. I don’t  
really know how that should work, though.

I might not need the serial port library anyway. this is all supposed  
to enable the Bluetooth component of the ruby-nxt library for  
remote-controlling Lego Mindstorms robots, and I hate to say this, but  
I’ll probably have to use Java to program my robot, and/or modify  
ruby-nxt. ruby-nxt _only_ does remote control - if you want to compile  
a program and download it to the robot, no dice. not only is  
compilation more effective for this kind of thing, but  
remote-controlling something by Bluetooth is inherently fragile when  
that thing has the ability to drive itself out of Bluetooth’s limited  
range.

–  
Giles B.

Blog: [http://gilesbowkett.blogspot.com](http://gilesbowkett.blogspot.com)  
Portfolio: [http://www.gilesgoatboy.org](http://www.gilesgoatboy.org)  
Tumblelog: [http://giles.tumblr.com/](http://giles.tumblr.com/)

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [September 3, 2007, 11:10pm UTC](https://www.ruby-forum.com/t/ruby-serialport-on-os-x/113685/5 "2007-09-03T23:10:19Z")

</div>

On 9/3/07, Giles B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Another update: Tried adding a blank create method - figured the  
> private\_class\_method call might be trying to hit something defined in  
> C. No dice:

Don’t edit .bundle files. It won’t achieve anything and just give you  
nasty errors (as you’ve found) 🙂 It’s /sort of/ the equivalent of .so  
files like you’d find on Linux, so any code in there is basically just  
debugging stuff.

I can’t really help though. I use ruby-serialport for interacting with  
a GPRS / SMS modem and it compiled fine. I had to change the  
references to /dev/ttyS etc to the device names of my modem, but it  
all went okay. This was on PowerPC at the time though… I haven’t  
tried on Intel since.

Cheers,  
Peter C.  
[http://www.petercooper.co.uk/](http://www.petercooper.co.uk/)

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [September 9, 2007, 11:02pm UTC](https://www.ruby-forum.com/t/ruby-serialport-on-os-x/113685/6 "2007-09-09T23:02:13Z")

</div>

On Sep 3, 4:49 pm, “Giles B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > require “serialport.so”  
> > > NameError: (eval):1:in `private_class_method': undefined method `create’ for class `Class' from (eval):1 from (eval):1 from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:28:in `require’  
> > > from (irb):1

I wrote ruby-nxt… there’s something wrong with ruby serialport when  
you are also loading rubygems. I got around it by not doing a require  
‘serialport’, instead do Kernel::require “serialport”.

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [September 10, 2007, 7:22am UTC](https://www.ruby-forum.com/t/ruby-serialport-on-os-x/113685/7 "2007-09-10T07:22:56Z")

</div>

No dice:

[09-09 22:14] ~  
! irb

> > Kernel::require “serialport”  
> > /opt/local/lib/ruby/site\_ruby/1.8/i686-darwin8.10.1/serialport.bundle:  
> > [BUG] Segmentation fault  
> > ruby 1.8.6 (2007-03-13) [i686-darwin8.10.1]

Abort trap

ruby-nxt is cool but leJOS is crazy well-specified. subsumption  
architecture, navigation, LCD graphics, sound, low-level connection  
libraries for Bluetooth and USB - probably I’ll use leJOS with JRuby,  
depending on whether or not it can compile to bytecodes without  
involving any JRuby stuff in the actual compilation output (which  
would undoubtedly overwhelm the tiny NXT brain).

On 9/9/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I wrote ruby-nxt… there’s something wrong with ruby serialport when  
> you are also loading rubygems. I got around it by not doing a require  
> ‘serialport’, instead do Kernel::require “serialport”.

–  
Giles B.

Blog: [http://gilesbowkett.blogspot.com](http://gilesbowkett.blogspot.com)  
Portfolio: [http://www.gilesgoatboy.org](http://www.gilesgoatboy.org)  
Tumblelog: [http://giles.tumblr.com/](http://giles.tumblr.com/)

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [September 10, 2007, 3:56pm UTC](https://www.ruby-forum.com/t/ruby-serialport-on-os-x/113685/8 "2007-09-10T15:56:34Z")

</div>

On Sep 10, 1:21 am, “Giles B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> No dice:  
> [09-09 22:14] ~  
> ! irb\>\> Kernel::require “serialport”  
> /opt/local/lib/ruby/site\_ruby/1.8/i686-darwin8.10.1/serialport.bundle:  
> [BUG] Segmentation fault  
> ruby 1.8.6 (2007-03-13) [i686-darwin8.10.1]  
> Abort trap

Hm, not sure what to tell you then, it works for me. I’m on a  
macbookpro, same version of ruby, and using ruby-serialport-0.6. Only  
possible difference, I compiled ruby from source, but it looks like  
you’re using ruby from darwin ports? Not sure why that would cause a  
problem…

> ruby-nxt is cool but leJOS is crazy well-specified. subsumption  
> architecture, navigation, LCD graphics, sound, low-level connection  
> libraries for Bluetooth and USB - probably I’ll use leJOS with JRuby,  
> depending on whether or not it can compile to bytecodes without  
> involving any JRuby stuff in the actual compilation output (which  
> would undoubtedly overwhelm the tiny NXT brain).

ruby-nxt is sort of a mess at the moment as I don’t have much time to  
work on it, but I do have usb support done in the svn repository. I  
really wish I didn’t have to deal with ruby-serialport, but there’s no  
native bluetooth for ruby. Someone is working on a bluetooth gem, but  
he doesn’t have a mac so it’s windows/linux only and incomplete. I  
had thought of accessing the serialport /dev directly instead of using  
ruby-serialport, but then it wouldn’t work in windows.

I had wondered if you could use jruby with lejos somehow, but I know  
next to nothing about java. I wish I had the time and knowledge to  
figure out a way to run ruby code directly on the NXT. I have a few  
ideas on ways to parse ruby code into NXT bytecode, but again, I just  
don’t have the time.
