Search in sources :

Example 1 with ScanInterruptedException

use of org.openmuc.framework.config.ScanInterruptedException in project OpenMUC by isc-konstanz.

the class SnmpScannerExample method main.

/**
 * @param args
 */
public static void main(String[] args) {
    SnmpDriver myDriver = new SnmpDriver();
    String settings = SnmpDriverSettingVariableNames.AUTHENTICATIONPASSPHRASE + "=adminadmin:" + SnmpDriverScanSettingVariableNames.STARTIP + "=192.168.1.0:" + SnmpDriverScanSettingVariableNames.ENDIP + "=192.168.10.0";
    class TestListener implements DriverDeviceScanListener {

        @Override
        public void scanProgressUpdate(int progress) {
        }

        @Override
        public void deviceFound(DeviceScanInfo device) {
            System.out.println("-----------------------------");
            System.out.println("New device found: ");
            System.out.println("Address: " + device.getAddress());
            System.out.println("Description: " + device.getDescription());
            System.out.println("-----------------------------");
        }
    }
    ;
    TestListener listener = new TestListener();
    try {
        myDriver.scanForDevices(settings, listener);
        Thread.sleep(100);
    } catch (InterruptedException iex) {
        System.out.println("Request cancelled: " + iex.getMessage());
    } catch (ArgumentSyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ScanException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ScanInterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) SnmpDriver(org.openmuc.framework.driver.snmp.SnmpDriver) ScanException(org.openmuc.framework.config.ScanException) DriverDeviceScanListener(org.openmuc.framework.driver.spi.DriverDeviceScanListener) ScanInterruptedException(org.openmuc.framework.config.ScanInterruptedException) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException) ScanInterruptedException(org.openmuc.framework.config.ScanInterruptedException)

Example 2 with ScanInterruptedException

use of org.openmuc.framework.config.ScanInterruptedException in project OpenMUC by isc-konstanz.

the class Driver method scanPrimaryAddress.

private void scanPrimaryAddress(DriverDeviceScanListener listener, Settings settings, MBusConnection mBusConnection) throws ScanInterruptedException, ScanException {
    VariableDataStructure dataStructure = null;
    for (int i = 0; i <= 250; i++) {
        if (interruptScan) {
            throw new ScanInterruptedException();
        }
        if (i % 5 == 0) {
            listener.scanProgressUpdate(i * 100 / 250);
        }
        logger.debug("scanning for meter with primary address {}", i);
        try {
            dataStructure = mBusConnection.read(i);
            sleep(settings.delay);
        } catch (InterruptedIOException e) {
            logger.debug("No meter found on address {}", i);
            continue;
        } catch (IOException e) {
            throw new ScanException(e);
        } catch (ConnectionException e) {
            throw new ScanException(e);
        }
        String description = "";
        if (dataStructure != null) {
            SecondaryAddress secondaryAddress = dataStructure.getSecondaryAddress();
            description = getScanDescription(secondaryAddress);
        }
        listener.deviceFound(new DeviceScanInfo(settings.scanConnectionAddress + ':' + i, "", description));
        logger.debug("Meter found on address {}", i);
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) ScanException(org.openmuc.framework.config.ScanException) SecondaryAddress(org.openmuc.jmbus.SecondaryAddress) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) VariableDataStructure(org.openmuc.jmbus.VariableDataStructure) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) ScanInterruptedException(org.openmuc.framework.config.ScanInterruptedException)

Aggregations

DeviceScanInfo (org.openmuc.framework.config.DeviceScanInfo)2 ScanException (org.openmuc.framework.config.ScanException)2 ScanInterruptedException (org.openmuc.framework.config.ScanInterruptedException)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 ArgumentSyntaxException (org.openmuc.framework.config.ArgumentSyntaxException)1 SnmpDriver (org.openmuc.framework.driver.snmp.SnmpDriver)1 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)1 DriverDeviceScanListener (org.openmuc.framework.driver.spi.DriverDeviceScanListener)1 SecondaryAddress (org.openmuc.jmbus.SecondaryAddress)1 VariableDataStructure (org.openmuc.jmbus.VariableDataStructure)1