Ruby on Android - usb/serialport

Hello,

I'm new to ruby and android. I come from a Java background. I'm going
to attempt to create an android/ruby application to interface with my
microcontroller (Adruino Uno). Is this even possible with Ruby? I
recently discovered Ruboto, but not sure if it has the capability to
access the usb/serialport on the android device (mobile phone).

I also found the serialport gem, which I think can be used to access
serialports on my computer, but not sure if it would work on my android
device.

Any information is greatly appreciated. Thanks.

Scott

···

--
Posted via http://www.ruby-forum.com/.

I'm running into a problem trying to read a line of text that has some multibyte
characters gsub is failing. Is there a trick to finding and replacing multibyte
characters?

The multibyte characters look like this in a text editor:

When simple_soft_en = 1, this registerís contents are transmitted to the remote
PHY in DME format.

When I put this into irb, this is what that text looks like:

1.9.3-p194 :001 > theText = "When simple_soft_en = 1, this
register\U+FFC3\U+FFADs contents are transmitted to the remote PHY in DME
format."
=> "When simple_soft_en = 1, this registers contents are transmitted to the
remote PHY in DME format."

When I run gsub on it, I see this error:

/Users/wayneb/LSI_Scripts/RPG Scripts/ruby/axx5500/LSI_RPG_parse_55.rb:117:
invalid multibyte char (US-ASCII)

I'm using: File.open(fileNameString,"rb"){|io|io.read}

to read the files. I found that when I used

File.open(fileNameString,"r:UTF-8"){|io|io.read}

I would get some failures opening up files, so I switched to ready the file in a
binary form.

I'm a bit stumped at this point.

Wayne

You might want to ask on the JRuby list or a Ruboto list (if there is
one). My understanding though is that Ruboto gives you access to most
of the features Java gives you access to in Android. If not, you might
have more luck with Mirah (created by the creator of JRuby), which has
Ruby-like syntax but is static and compiles directly down to Java
bytecode.

···

On Mon, Jan 7, 2013 at 1:18 PM, Scott Macri <lists@ruby-forum.com> wrote:

Hello,

I'm new to ruby and android. I come from a Java background. I'm going
to attempt to create an android/ruby application to interface with my
microcontroller (Adruino Uno). Is this even possible with Ruby? I
recently discovered Ruboto, but not sure if it has the capability to
access the usb/serialport on the android device (mobile phone).

I also found the serialport gem, which I think can be used to access
serialports on my computer, but not sure if it would work on my android
device.

Any information is greatly appreciated. Thanks.

I'm new to ruby and android. I come from a Java background. I'm going
to attempt to create an android/ruby application to interface with my
microcontroller (Adruino Uno). Is this even possible with Ruby? I
recently discovered Ruboto, but not sure if it has the capability to
access the usb/serialport on the android device (mobile phone).

Ruboto gives you access to the complete Android API, so if a Java Android app can access the serial port, so can a Ruboto Android app.

A bit of googling gave me this project:

http://code.google.com/p/android-serialport-api/

You should give it a try.

I also found the serialport gem, which I think can be used to access
serialports on my computer, but not sure if it would work on my android
device.

Probably not.

Any information is greatly appreciated. Thanks.

You can get more information about Ruboto at http://ruboto.org/ and ask questions on the mailing list, IRC channel, or file an issue in the tracker:

https://groups.google.com/forum/#!forum/ruboto
irc://irc.freenode.net/ruboto

···

On 2013-01-07, at 20:18, Scott Macri <lists@ruby-forum.com> wrote:

--
Uwe Kubosch
http://ruboto.org/

Do you have something like this as the first line of your code?

# encoding: UTF-8

Harry

···

On Tue, Jan 8, 2013 at 7:58 AM, Wayne Brisette <wbrisett@att.net> wrote:

I'm running into a problem trying to read a line of text that has some multibyte
characters gsub is failing. Is there a trick to finding and replacing multibyte
characters?

How is this relevant to my post?

Wayne Brisette wrote in post #1091375:

···

I'm running into a problem trying to read a line of text that has some
multibyte
characters gsub is failing. Is there a trick to finding and replacing
multibyte
characters?

.....

Wayne

--
Posted via http://www.ruby-forum.com/.

Thanks.

Eric Christopherson wrote in post #1091622:

···

On Mon, Jan 7, 2013 at 1:18 PM, Scott Macri <lists@ruby-forum.com> > wrote:

device.

Any information is greatly appreciated. Thanks.

You might want to ask on the JRuby list or a Ruboto list (if there is
one). My understanding though is that Ruboto gives you access to most
of the features Java gives you access to in Android. If not, you might
have more luck with Mirah (created by the creator of JRuby), which has
Ruby-like syntax but is static and compiles directly down to Java
bytecode.

--
Posted via http://www.ruby-forum.com/.

That could possibly be exactly what I was looking for. Thanks.

Uwe Kubosch wrote in post #1091626:

···

On 2013-01-07, at 20:18, Scott Macri <lists@ruby-forum.com> wrote:

--
Posted via http://www.ruby-forum.com/.

I have added this but when I do, I end up with
'gsub!: Invalid byte sequence in UTF-8 (ArgumentError).

Ironically if I use macruby's irb, I can do the gsub without any problems.

Why would macruby allow this, but not the MRI version of Ruby?

Wayne

···

On Jan 8, 2013, at 1:13 AM, Harry Kakueki wrote:

On Tue, Jan 8, 2013 at 7:58 AM, Wayne Brisette <wbrisett@att.net> wrote:

I'm running into a problem trying to read a line of text that has some multibyte
characters gsub is failing. Is there a trick to finding and replacing multibyte
characters?

Do you have something like this as the first line of your code?

# encoding: UTF-8

I fixed it!

I found an interesting trick on stack-overflow.

What I ended up doing was

mystr.force_encoding("BINARY").gsub!(0x92.chr, "'")

I did have to open the problem file in a hex editor to verify the hex character that was causing issues, but forcing the encoding in the MRI seemed to do the trick.

I wonder why macruby didn't have this sort of issue though.

Wayne

It isn't. But in the mailing list, these were 2 separate threads.
In ruby-forum it looks like they got mixed together.

Harry

···

On Thu, Jan 10, 2013 at 2:48 AM, Scott Macri <lists@ruby-forum.com> wrote:

How is this relevant to my post?

Wayne Brisette wrote in post #1091375:

I'm running into a problem trying to read a line of text that has some
multibyte
characters gsub is failing. Is there a trick to finding and replacing
multibyte
characters?

.....

Wayne

--
Posted via http://www.ruby-forum.com/.

LOL

Harry Kakueki wrote in post #1091691:

···

On Thu, Jan 10, 2013 at 2:48 AM, Scott Macri <lists@ruby-forum.com> > wrote:

Wayne

--
Posted via http://www.ruby-forum.com/.

It isn't. But in the mailing list, these were 2 separate threads.
In ruby-forum it looks like they got mixed together.

Harry

--
Posted via http://www.ruby-forum.com/.