DAAPI B (b02)
- Java ME Embedded 3.3 Release

Package com.oracle.deviceaccess.counter

Interfaces and classes for counting pulses (or events) on a digital input line.

See: Description

Package com.oracle.deviceaccess.counter Description

Interfaces and classes for counting pulses (or events) on a digital input line.

In order to access and control a specific pulse counter, an application should first open and obtain an PulseCounter instance for the pulse counter the application wants to access and control, using its numerical ID, name, type (interface) and/or properties:

Using its ID
 PulseCounter counter = (PulseCounter) PeripheralManager.open(8);
 
Using its name and interface
 PulseCounter counter = (PulseCounter) PeripheralManager.open("ENCODER", PulseCounter.class, null);
 
Once opened, an application can either start a pulse counting session using the startCounting() method and retrieve the current pulse count on-the-fly by calling the PulseCounter.getCount() method; or it can start a pulse counting session with a terminal count value and a counting time interval using the PulseCounter.startCounting(int, long, com.oracle.deviceaccess.counter.CountingListener) and get asynchronously notified once the terminal count value has been reached or the counting time interval has expired. In both cases, the application can retrieve the current pulse count value at any time (on-the-fly) by calling the PulseCounter.getCount().
 counter.startCounting(); // Start counting pulses
 // Perform some task...
 int count = counter.getCount(); // Retrieve the number of pulses that occurred while performing the task
 counter.stopCounting(); // Stop counting pulses
 
When done, the application should call the PulseCounter.close() method to release Pulse counter.
 counter.close();
 
The following sample codes give examples of using the counter/timer API:
 class PulseCounting implements CountingListener {
 
     private PulseCounter counter = null;
 
     public void start(int counterID) throws IOException, PeripheralNotAvailableException, PeripheralNotFoundException {
         counter = (PulseCounter) PeripheralManager.open(counterID);
         counter.startCounting(-1, 1000, this); // Count events occuring during 1 second (without terminal count value)
     }
 
     public void countValueAvailable(CountingEvent event) {
         int count = event.getValue();
         // Handle pulse count...
     }
 
     public void stop() throws IOException, PeripheralNotAvailableException {
         if (counter != null) {
             counter.stopCounting();
             counter.close();
         }
     }
 }
 
Because of performance issue, procedures handling pulse counting events, and especially event listeners, should be implemented to be as fast as possible.

Security

Pulse counters are opened by invoking one of the com.oracle.deviceaccess.PeripheralManager.open methods. The "com.oracle.deviceaccess.counter" permission allows access to be granted to pulse counter devices as a whole.
DAAPI B (b02)
5-February-2013 04:40

Copyright (c) 2012, Oracle and/or its affiliates. All Rights Reserved. Use of this specification is subject to license terms.