Oracle Java Wireless Client

com.oracle.deviceaccess.gpio
Interface GPIOPort

All Superinterfaces:
Peripheral

public interface GPIOPort
extends Peripheral

Interface for GPIO Port.
Port is distinguished by its ID.
Platform provide GPIOPort to bind multiple GPIO pins as one data port and perform read/write operation for several pins at a time. Port provide convenient way to access multiple pins simultaneously.

GPIO Port is configured by OEM and implemented during porting period. Applications get port instance by using getPort()method and use port for data read/write. and GPIO Port has maximum and minimum data range that can be written or read.Application can check maximum value by calling getMaxValue() method and minimum value is zero. If value which exceeds its range is written to GPIO port then Exception will be thrown.

 int data = 1; //data to write
 GPIOPort port1;
 GPIOPort port2;
 
 port1 = GPIO.getPort(1);
 port2 = GPIO.getPort(2);
 port1.setValue(data); //write to first port
 data = port2.getValue(); //read from second port
 System.out.println("result = "+ data);
 port1.release();
 port2.release();
 
 
Application can register listener for receive notification for interrupt for specific GPIO port. If application try to register listener to GPIO port which is not configured to support listener then it will be thrown InvalidOperationException.


Field Summary
static int INPUT
           
static int OUTPUT
           
 
Method Summary
 int getDirection()
          Returns the current direction of port.
 int getMaxValue()
          Returns maximum value of this port
 int getValue()
          Get data from GPIO port.
 void setDirection(int direction)
          Change current port's direction.
 void setInputListener(PortListener listener)
          Start notification from GPIO port and register listener.
 void setValue(int value)
          Set value to the GPIO port.
 
Methods inherited from interface com.oracle.deviceaccess.Peripheral
close, getID, getName
 

Field Detail

INPUT

static final int INPUT
See Also:
Constant Field Values

OUTPUT

static final int OUTPUT
See Also:
Constant Field Values
Method Detail

getMaxValue

int getMaxValue()
Returns maximum value of this port

Returns:
Maximum value that this port can handle.

setValue

void setValue(int value)
              throws java.io.IOException,
                     PeripheralNotAvailableException
Set value to the GPIO port.

Parameters:
value - value to be written to the port.
Throws:
java.io.IOException - error occured while writing data to port.
InvalidOperationException - throws when try to write value to input port.
java.lang.SecurityException - throws when application has not enough permission.
java.lang.IllegalArgumentException - throws when application try to set value which exceeds device's value range.
PeripheralNotAvailableException

getValue

int getValue()
             throws java.io.IOException,
                    PeripheralNotAvailableException
Get data from GPIO port.

Returns:
value of GPIO port.
Throws:
java.io.IOException - error occured while reading data from port.
java.lang.SecurityException - throws when application has not enough permission.
PeripheralNotAvailableException

getDirection

int getDirection()
                 throws java.io.IOException,
                        PeripheralNotAvailableException
Returns the current direction of port. Check whether current port is output port or input port.

Returns:
OUTPUT if port is currently set as output.
Throws:
java.io.IOException
PeripheralNotAvailableException

setDirection

void setDirection(int direction)
                  throws java.io.IOException,
                         PeripheralNotAvailableException
Change current port's direction.

Parameters:
direction - OUTPUT for output port and INPUT for input port.
Throws:
InvalidOperationException - throws when try to change direction to invalid one.
java.lang.SecurityException - throws when application has not enough permission.
java.io.IOException
PeripheralNotAvailableException

setInputListener

void setInputListener(PortListener listener)
                      throws PeripheralNotAvailableException
Start notification from GPIO port and register listener. Notify when port value is changed. InvalidOperationException will be thrown if try to set listener to output port. If try to register listener when another listener is already registered then the second call for this method will override first one.

Parameters:
listener - Listener for input event.
Throws:
InvalidOperationException - when adding listener to unsupporting or output port.
java.lang.SecurityException - throws when application has not enough permission.
PeripheralNotAvailableException

Oracle Java Wireless Client

Copyright (c) 1990, 2012, Oracle and/or its affiliates. All rights reserved.