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
Java SE and OpenJDK Device I/O GPIOLEDSample problem

Hi,
I am toying around with my Raspberry Pi B Rev 2, Java ME, Java SE and Device I/O. I've come a long way, but I stumble upon an inexplicable exception in GPIOLEDSample.java.
To build and install Device I/) on my Raspberry Pi, I follo0wed the instructions given at https://wiki.openjdk.java.net/display/dio/Getting+Started
The sample program (located in dio-samples.jar) lets an LED blink for a while by "opening" it via two alternative ways:
a) By using an ad-hoc GPIOPinConfig in the DeviceManager.open() method, and
b) By using a device id in the DeviceManager.open(int id) method.
By figuring out how to supply the java.policy and dio.properties file, I managed to run the program to let the LED blink through method (a).
Unfortunately, the program exits with an AccessControl exception as follows:
Exception in thread "main" java.security.AccessControlException: access denied ("jdk.dio.DeviceMgmtPermission" "*:18" "open")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:457)
at java.security.AccessController.checkPermission(AccessController.java:884)
at jdk.dio.DeviceManager.open(DeviceManager.java:469)
at jdk.dio.DeviceManager.open(DeviceManager.java:410)
at jdk.dio.DeviceManager.open(DeviceManager.java:362)
at GPIOLEDSample.blinkLEDByDeviceId(GPIOLEDSample.java:82)
my java.policy section for the samples file is this:
grant codeBase "file:./dio-samples.jar" {
permission jdk.dio.DeviceMgmtPermission "*:*";
permission jdk.dio.gpio.GPIOPinPermission "*:*";
};
and the dio.properties file is this:
# RPi rev2 P1 header pins
1 = deviceType: gpio.GPIOPin, pinNumber:4, name:GPIO4, predefined:true
2 = deviceType: gpio.GPIOPin, pinNumber:7, name:GPIO7, mode:4, direction:1, predefined:true
3 = deviceType: gpio.GPIOPin, pinNumber:17, name:GPIO17, predefined:true
4 = deviceType: gpio.GPIOPin, pinNumber:18, name:GPIO18, mode:4, direction:1, predefined:true
5 = deviceType: gpio.GPIOPin, pinNumber:22, name:GPIO22, predefined:true
6 = deviceType: gpio.GPIOPin, pinNumber:23, name:GPIO23, mode:4, direction:1, predefined:true
7 = deviceType: gpio.GPIOPin, pinNumber:24, name:GPIO24, mode:4, direction:1, predefined:true
8 = deviceType: gpio.GPIOPin, pinNumber:25, name:GPIO25, mode:4, direction:1, predefined:true
9 = deviceType: gpio.GPIOPin, pinNumber:27, name:GPIO27, predefined:true
300 = deviceType: spibus.SPIDevice, name:SPI0.0, controllerNumber:0, address:0, csActive:1, wordLength:8, clockFrequency:500000, clockMode:1, bitOrdering:1, predefined:true
100 = deviceType: uart.UART, controllerName:ttyAMA0, name:ttyAMA0, baudRate:19200, dataBits:8, parity:0, stopBits:1, flowControl:0, predefined:true
gpio.GPIOPin = initValue:0, controllerNumber:0, direction:0, mode:1, trigger:0, predefined:true
uart.UART = baudRate:19200, parity:0, dataBits:8, stopBits:1, flowControl:0, predefined:true
I have two questions:
(a) Can you explain the access control exception for the DeviceManager.open(int id) method call?
(b) Why does the sample code use "18" as a device id, where the dio.properties file declares the device id for GPIO pin 18 to be "4"? When I run a cross-check programm via Java ME 8.2 with DeviceManager..open(int id), I have to use device id 4 to get the same GPIO pin to glink the LED?
(c) When modifying the sample program to use the device id 4, it seem to make no difference, except for the access control exception to refer to "*:4" instead :-(
Answers
-
Hi,
Can say only about Java ME.
a) On Java ME you also need to ask permissions in .jad or in manifest file. If you use Netbeans it is enough to open project properties -> Application Descriptor -> API Permissions. Click Add button, select necessary permissions. In _polixy.txt file for Java it is described only permissions for clients. During the installation, your application is assigned for some client(if it is not signed, client will be untrusted) and ONLY requested permissions intersected with clients permissions will be granted. More detailed information is in MEEP specification: Security for Applications
b) All GPIO device ids are listed in Getting Started guide: https://docs.oracle.com/javame/8.2/get-started-rpi/piportsapdx.htm#sthref36
Also all Java ME related samples are delivered with Netbeans. New Project -> Samples -> Java ME SDK 8.2
c) See a), you still need to request permission to have an access to GPIO in Java ME 8.2 on RPi.
Regards,
Alex
-
Hi
Be sure to remove all Midlets from RPi. otherwise the pin is locked already. Have a look in the JAD file by starting the Projects -> Properties in the API Permission and make sure you have set the entries correct.
1 = deviceType: gpio.GPIOPin, pinNumber:4, name:GPIO4, predefined:true
this is really confusing. This is an input pin. Trying to use it as output gives you an exception.
Have a look in
https://docs.oracle.com/javame/8.2/get-started-rpi/piportsapdx.htm
an you see
1 GPIO4 GPIO 4 controllerNumber = 0
pinNumber = 4
direction = GPIOPinConfig.DIR_INPUT_ONLY
mode = DeviceConfig.DEFAULT
trigger = GPIOPinConfig.TRIGGER_BOTH_EDGES
initValue
- ignoredThe pin number is not correct. have a look in the picture underneath the list. Look for GPIO4 and you will see that the RPi Pin number is 7
But using an output the first option is device 2
2 GPIO7 GPIO 7 controllerNumber = 0
pinNumber = 7
direction = GPIOPinConfig.DIR_OUTPUT_ONLY
mode = GPIOPinConfig.MODE_OUTPUT_PUSH_PULL
trigger = GPIOPinConfig.TRIGGER_BOTH_EDGES
initValue = false
PinNumber again is not correct. use RPi PinNumber 26 instead. Use DeviceManager.Open(2) this is the device number.
the exception you get is with that info easy to make clear.
Exception in thread "main" java.security.AccessControlException: access denied ("jdk.dio.DeviceMgmtPermission" "*:18" "open")
You are trying to open GPIO18:18 but the permission you have to add si java.util.PropertyPermission "microedition.platform" "read"
4 GPIO18 GPIO 18 controllerNumber = 0
pinNumber = 18
direction = GPIOPinConfig.DIR_OUTPUT_ONLY
mode = GPIOPinConfig.MODE_OUTPUT_PUSH_PULL
trigger
- ignoredinitValue = false
with this it should blink on RPi Pin 12
regards, harald