Device I/O API 1.1

Package jdk.dio.adc

Interfaces and classes for reading analog inputs using an Analog to Digital Converter (ADC).

See: Description

Package jdk.dio.adc Description

Interfaces and classes for reading analog inputs using an Analog to Digital Converter (ADC).

One ADC converter can have several channels. Each channel can sample a continuous input voltage and convert it to a numeric value.

In order to access and control a specific ADC channel, an application should first open and obtain an ADCChannel instance for the ADC channel the application wants to access and control, using its numeric ID, name, type (interface) and/or properties:

Using its ID
 ADCChannel channel = DeviceManager.open(8);
 
Using its name and interface
 ADCChannel channel = DeviceManager.open("TEMPERATURE", ADCChannel.class, null);
 
Once the device opened, the application can read or monitor sampled input values using methods of the ADCChannel interface such as the acquire method.
 int temp = channel.acquire();
 
When done, the application should call the ADCChannel.close method to close ADC channel.
 channel.close();
 
The following sample codes give examples of using the ADC API:
 class ADCAcquisition implements AcquisitionRoundListener {
 
     private ADCChannel channel = null;
 
     public void start(int channelID) throws IOException, NonAvailableDeviceException, DeviceNotFoundException {
         channel = (ADCChannel) DeviceManager.open(channelID);
         channel.setSamplingInterval(100); // every 100 milliseconds
         int[] values = new int[10];
         channel.startAcquisition(IntBuffer.wrap(values), this);
     }
 
     public void inputRoundCompleted(RoundCompletionEvent<ADCChannel, IntBuffer> event) {
         IntBuffer buffer = event.getBuffer();
         while (buffer.hasRemaining()) {
             int value = buffer.get();
             // Handle value...
         }
     }
 
     public void stop() throws IOException {
         if (channel != null) {
             channel.stopAcquisition();
             channel.close();
         }
     }
 
     public void failed(Throwable exception, ADCChannel source) {
          // Ignored
     }
 }
 
 class ADCThreshold implements MonitoringListener {
 
     private ADCChannel channel = null;
 
     public void start(int channelID, int low, int high) throws IOException, NonAvailableDeviceException,
             DeviceNotFoundException {
         channel = (ADCChannel) DeviceManager.open(channelID);
         channel.setSamplingInterval(100); // every 100 milliseconds
         channel.startMonitoring(low, high, this);
     }
 
     public void thresholdReached(MonitoringEvent event) {
         if (event.getType() == MonitoringEvent.OUT_OF_RANGE) {
             int value = event.acquire();
             // Handle condition...
         }
     }
 
     public void stop() throws IOException {
         if (channel != null) {
             channel.stopMonitoring();
             channel.close();
         }
     }
 
     public void failed(Throwable exception, ADCChannel source) {
          // Ignored
     }
 }
 

Because of performance issue, procedures handling analog inputs, and especially event listeners, should be implemented to be as fast as possible.

Unless otherwise noted, permission and security checks that may cause a SecurityException to be thrown must be performed in priority to any other checks or operations once performed the checking of the input parameters from which the permission target names and action lists are retrieved and assembled.

Unless otherwise noted, passing a null argument to a constructor or method in any class or interface in this package will cause a NullPointerException to be thrown.

Since:
1.0
Device I/O API 1.1