Skip to Main Content

Embedded Technologies

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Software servo control from JAVA ME on Raspberry PI with /dev/servoblaster

WillemDFeb 10 2015 — edited Feb 25 2015
Long post:
I am using JAVA ME on Raspberry PI to drive various motors and sensors of a robot, all works fine, but also wanted to do servocontrol from software. Apparently I cannot do that directly by controlling puls length from software on an OS like the Raspberry PI, too inaccurate. So I tried to switch to servoblaster usage which uses DMA access to control pulse length.This works fine when called from python or from a command line, but now I want to call it from within a JAVA ME program.
For this I need to write simple settings to /dev/servoblaster.
After startup ls -l /dev/servoblaster shows:
prw-rw-rw- 1 root root 0 Feb 8 16:55 /dev/servoblaster
I tried to use the following code, with some print statements in between, to open servoblaster so I then can send values to it to drive the servos:

Path servoPath = FileSystems.getDefault().getPath("/dev","servoblaster");
System.out.println("path defined "+servoPath.toString());
outStream = Files.newOutputStream(servoPath,WRITE);
System.out.println("outstream created");

Also I have tried an alternative method in JAVA ME 8 with the following code. Both options are from the MOOC course on JAVA ME.
connection = (FileConnection)
Connector.open("file:///rootfs/dev/servoblaster", Connector.WRITE);
System.out.println("connection opened");
fileWriter = new PrintStream(connection.openOutputStream());
System.out.println("filewriter started");

In both cases the statements fail on the 3rd line, i.e. the opening of the OutputStream. I get an error message on the raspberry Pi:

[CRITICAL] [SECURITY] iso=2:Permission check failed: java.io.FilePermission "/dev/servoblaster" "write"
TRACE: <at java.security.AccessControlException: >, startApp threw an Exception
Although I did set the following permissions
java.io.FilePermission "/*" "write"
and
javax.microedition.io.Connector.file.write
javax.microedition.io.Connector.file.read

My conclusion so far is that this fails because JAVA ME8 does not support a PipedOutputStream
My other option would be to escape to the command line,echo the settings to /dev/servoblaster and then return to the JAVA ME program
but I found that JAVA ME also does not support the runtime exec command so I cannot do that.

So my only option now seems to be to switch to JAVA SE. I tried servoblaster from JAVA SE and that works fine, I just open it and send data to it, servo reacts, no problem. But then I still need to control the other motors and sensors.
I then tried to install the open jdk.dio libraries on the PI so I can still use what I have done so far, but the installation instructions are unclear to me and don't work.

So now I am moving away from JAVA ME and moving to JAVA SE with PI4J, unless someone here can help me out.
Thanks,
Willem
This post has been answered by Sergey.N-Oracle on Feb 25 2015
Jump to Answer

Comments

BarryB

I didn't figure it out, (didn't get any help on SO either).
So I made a workaround by saving it to a table.

It probably looks horrible to a Java programmer but seems to work.

//Save the message to 
           ByteArrayOutputStream bos = new ByteArrayOutputStream();
           ByteArrayInputStream bis = null;
           //memory = new MemoryStream ();
           try  {
                msg.writeTo(bos);
                int i = bos.toByteArray().length;
                byte[] array = new byte[i];
                array = bos.toByteArray();
                
                
                
                //insertIntoProducts(desBlob);
                Connection conn = DriverManager.getConnection("jdbc:default:connection:");
                Blob desBlob = conn.createBlob();
                desBlob.setBytes(1, array);
                //PreparedStatement ps2 = conn.prepareStatement("insert into mytable values (hextoraw(?))");
                PreparedStatement ps2 = conn.prepareStatement("insert into barry_testtable(blobcolumn) values (?)");
                ps2.setBytes(1,array);
                try{
                int rowsAffected = ps2.executeUpdate();
                System.out.println(rowsAffected); //1
                } catch (SQLException e) {
                    System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                
           }catch(Exception exp){
               exp.printStackTrace();}
1 - 1
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 25 2015
Added on Feb 10 2015
16 comments
4,234 views