Discussions
Categories
- 385.5K All Categories
- 5.1K Data
- 2.5K Big Data Appliance
- 2.5K Data Science
- 453.4K Databases
- 223.2K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 47 Multilingual Engine
- 606 MySQL Community Space
- 486 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.2K ORDS, SODA & JSON in the Database
- 585 SQLcl
- 4K SQL Developer Data Modeler
- 188K SQL & PL/SQL
- 21.5K SQL Developer
- 46 Data Integration
- 46 GoldenGate
- 298.4K Development
- 4 Application Development
- 20 Developer Projects
- 166 Programming Languages
- 295K Development Tools
- 150 DevOps
- 3.1K QA/Testing
- 646.7K Java
- 37 Java Learning Subscription
- 37.1K Database Connectivity
- 201 Java Community Process
- 108 Java 25
- 22.2K Java APIs
- 138.3K Java Development Tools
- 165.4K Java EE (Java Enterprise Edition)
- 22 Java Essentials
- 176 Java 8 Questions
- 86K Java Programming
- 82 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 208 Java User Groups
- 25 JavaScript - Nashorn
- Programs
- 667 LiveLabs
- 41 Workshops
- 10.3K Software
- 6.7K Berkeley DB Family
- 3.6K JHeadstart
- 6K Other Languages
- 2.3K Chinese
- 207 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 474 Portuguese
Software servo control from JAVA ME on Raspberry PI with /dev/servoblaster

prw-rw-rw- 1 root root 0 Feb 8 16:55 /dev/servoblaster
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.
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
and
javax.microedition.io.Connector.file.write
javax.microedition.io.Connector.file.read
but I found that JAVA ME also does not support the runtime exec command so I cannot do that.
Best Answer
-
Hi Willem,
that's correct, JavaME can open only regular files (link, pipe, block, char, FIFO and socket is not supported).
/Sergey
Answers
-
Hi Willem,
It's sad to hear that you decided to abandon Java ME. I could only wish you've asked as soon as you've met the problems without waiting for them to stack up and frustration to increase. May I suggest you to fix the permission for nio.File and check whether this makes your code working? As a fact "/*" means all files in the root directory, but that's not recursive! This is clearly articulated the FilePermission javadoc. So you either have to use "/dev/*" or "/-" (recursive version) or just "<<ALL FILES>>"
I'll let DIO guys to comment about installation of the library
Thanks,
Andrey
-
Ah... that's something I did not realize or try. I will certainly give it a try tonight. I have only just started to convert to SE and PI4J and can still come back to JAVA ME :-) It seems this is clearly a better place to ask these kind of ME questions, I asked on the PI forums before.
The connector.file.write permission should still have worked in the second method, i.e. not affected by my error ?
Thanks
Willem
-
Hi Willem,
to run DIO on SE (i assume you've compiled the binaries, and they in the same folder as your app) you can try following
java -Djava.library.path=dio.so -cp dio.jar,your_app.jar your_app_main_class
/Sergey
-
I managed to add the DIO libraries to my project in netbeans but my problem was on the Raspberry side, to avoid the error message when compiling my project using Netbeans on the remote Raspberry in SE but still relying on jdk.dio.
The jdk.dio instructions list the following commands to install:
hg clone http://hg.openjdk.java.net/dio/dev
cd dev
export PI_TOOLS=<path to raspberry pi toolchain>
export JAVA_HOME=<path to JDK8>
make
And already on the hg command I get an error message that it does not know the command. I assumed I had to type those commands on the Raspberry?
Forgive me, my last UNIX experience is from 20 years ago :-( and I am new to Raspberry, JAVA, Netbeans. Some more details on the installation would certainly be helpfull. I liked working with JAVA ME so far, following the MOOCourse and applying that learning to my robot.
-
Hi Willem,
Your Connector.file permissions are good and actually should have given you access through Connector.open even with your error in FilePermission. So if you still have problem of just curious could you please paste here the respective lines from your .jad file with all the permissions, it might happen that there is some problem which is not obvious from the text description
Regarding DIO for SE. AFAIK you should be able to compile it on RPi itself. In this case you should have there:
1. mercurial, to get the source code. And that's what "hg" is about and that's what apparently you're missing
2. the gcc toolchain
3, JDK8, either from Oracle or OpenJDK
Regards,
Andrey
-
Hi Willem,
both mercurial and gcc can be installed with "apt-get install". Oracle JDK has to be downloaded manually
/Sergey
-
If you have Raspbian on your RPi you should already have Oracle JDK already installed. It's there by default unless you removed it or have very old Raspbian image
Andrey
-
Hi Andrey,
I tried both option, so /- and <<ALL FILES>> and I now seem to get one step further, no access error on that line but a null pointer exception on the next line that creates the writer. here is part of the error trail including my own print messages:
new servos
start
path defined /dev/servoblaster
file name servoblaster
outstream created
TRACE: <at java.lang.NullPointerException>, startApp threw an Exception
- com/sun/cldc/i18n/Helper.getStreamWriter(), bci=8
- com/sun/cldc/i18n/Helper.getStreamWriter(), bci=11
- java/io/OutputStreamWriter.<init>(), bci=6
The code is until that point is:
public class Servos {
OutputStream outStream;
Writer outWriter;public Servos() {
}public void start() {
Path servoPath = FileSystems.getDefault().getPath("/dev", "servoblaster");
System.out.println("path defined " + servoPath.toString());
System.out.println("file name " + servoPath.getFileName());
try {
outStream = Files.newOutputStream(servoPath, WRITE);
} catch (IOException ex) {
Logger.getLogger(Servos.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("outstream created");
outWriter = new OutputStreamWriter(outStream);
System.out.println("outwriter createde");also when I try to print outStream.tostring() I get the null pointer exception.,
The JAD file contains:
MIDlet-Name: SearchAndRescueRobotV1
MIDlet-Permission-1: jdk.dio.gpio.GPIOPinPermission "*:*"
MIDlet-Permission-2: jdk.dio.DeviceMgmtPermission "*:*" "open"
MIDlet-Permission-3: java.io.FilePermission "<<ALL FILES>>" "write"
MIDlet-Permissions:
javax.microedition.io.Connector.file.write,
javax.microedition.io.Connector.file.read
MIDlet-Vendor: wd
MIDlet-Version: 1.0
MicroEdition-Configuration: CLDC-1.8
MicroEdition-Profile: MEEP-8.0
-
Hi Willem,
Apparently your outStream is null, that's why you get NPE from OutputStreamWriter constructor. So it looks like you've got an exception from Files.newOutputStream but for some reason it's not in the log. Could you please add ex.printStackTrace() into your catch block so we can check what's going on
Thanks,
Andrey
-
When I include that statement I also get error messages on the OutStream creation, as follows:
java.io.IOException
- com/oracle/cldc/file/FileSystemImpl.throwIOException(), bci=4
- com/oracle/cldc/file/FileChannelImpl.<init>(), bci=215
- java/nio/channels/FileChannel.open(), bci=7
- java/nio/channels/FileChannel.open(), bci=23
- java/nio/file/Files.newByteChannel(), bci=3
- java/nio/file/Files.newOutputStream(), bci=100