Ruby on Android - usb/serialport


#1

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


#2

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 registers 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


#3

On Tue, Jan 8, 2013 at 7:58 AM, Wayne B. removed_email_address@domain.invalid 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

Harry


#4

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

On Tue, Jan 8, 2013 at 7:58 AM, Wayne B. removed_email_address@domain.invalid 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 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


#5

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


#6

On Mon, Jan 7, 2013 at 1:18 PM, Scott M. removed_email_address@domain.invalid
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.


#7

How is this relevant to my post?

Wayne B. 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


#8

On 2013-01-07, at 20:18, Scott M. removed_email_address@domain.invalid wrote:

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
https://github.com/ruboto/ruboto/issues


#9

Thanks.

Eric C. wrote in post #1091622:

On Mon, Jan 7, 2013 at 1:18 PM, Scott M. removed_email_address@domain.invalid
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.


#10

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

Uwe K. wrote in post #1091626:

On 2013-01-07, at 20:18, Scott M. removed_email_address@domain.invalid wrote:


#11

On Thu, Jan 10, 2013 at 2:48 AM, Scott M. removed_email_address@domain.invalid
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


#12

LOL

Harry K. wrote in post #1091691:

On Thu, Jan 10, 2013 at 2:48 AM, Scott M. removed_email_address@domain.invalid
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