ruby-serialport on OS X?

G

Giles Bowkett

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

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
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::eek:pen(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 Bowkett

Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com/
 
P

Peter Cooper

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 Cooper
http://www.petercooper.co.uk/
 
G

Giles Bowkett

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 Bowkett

Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com/
 
T

tbuser

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".
 
G

Giles Bowkett

No dice:

/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).

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 Bowkett

Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com/
 
T

tbuser

No dice:
<macbook of doom:giles> [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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top