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);
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)
fileWriter = new PrintStream(connection.openOutputStream());
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"
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.