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();
}
}
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);
}
}
Aggregations