Forum: Ruby Ruby on Android - usb/serialport

Posted by Scott Macri (hacktorious)
on 2013-01-07 20:17
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 by Wayne Brisette (Guest)
on 2013-01-07 23:59
(Received via mailing list)
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
Posted by Harry Kakueki (Guest)
on 2013-01-08 08:14
(Received via mailing list)
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



Harry
Posted by Wayne Brissette (Guest)
on 2013-01-08 12:09
(Received via mailing list)
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 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
Posted by Wayne Brissette (Guest)
on 2013-01-08 12:38
(Received via mailing list)
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
Posted by Eric Christopherson (echristopherson)
on 2013-01-09 18:36
(Received via mailing list)
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 by Scott Macri (hacktorious)
on 2013-01-09 18:48
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 by Scott Macri (hacktorious)
on 2013-01-09 18:49
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 by Uwe Kubosch (donv)
on 2013-01-09 19:52
(Received via mailing list)
On 2013-01-07, at 20:18, Scott Macri <lists@ruby-forum.com> 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
Posted by Scott Macri (hacktorious)
on 2013-01-09 23:55
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 by Harry Kakueki (Guest)
on 2013-01-10 08:23
(Received via mailing list)
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 by Scott Macri (hacktorious)
on 2013-01-10 14:37
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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.