use of org.openmuc.framework.config.ScanException in project OpenMUC by isc-konstanz.
the class DataManager method scanForChannels.
@Override
public List<ChannelScanInfo> scanForChannels(String deviceId, String settings) throws DriverNotAvailableException, UnsupportedOperationException, ArgumentSyntaxException, ScanException {
// TODO this function is probably not thread safe
DeviceConfigImpl config = (DeviceConfigImpl) this.rootConfig.getDevice(deviceId);
if (config == null) {
throw new ScanException("No device with ID \"" + deviceId + "\" found.");
}
DriverService activeDriver = activeDrivers.get(config.driverParent.id);
if (activeDriver == null) {
throw new DriverNotAvailableException();
}
waitTilDeviceIsConnected(config.device);
try {
return config.device.connection.scanForChannels(settings);
} catch (ConnectionException e) {
config.device.disconnectedSignal();
throw new ScanException(e.getMessage(), e);
}
}
use of org.openmuc.framework.config.ScanException in project OpenMUC by isc-konstanz.
the class Driver method scanForDevices.
@Override
public void scanForDevices(String settingsString, DriverDeviceScanListener listener) throws ArgumentSyntaxException, ScanException, ScanInterruptedException {
interruptScan = false;
Settings settings = new Settings(settingsString, true);
MBusConnection mBusConnection;
if (!interfaces.containsKey(settings.scanConnectionAddress)) {
try {
if (settings.host.isEmpty()) {
mBusConnection = MBusConnection.newSerialBuilder(settings.scanConnectionAddress).setBaudrate(settings.baudRate).setTimeout(settings.timeout).build();
} else {
mBusConnection = MBusConnection.newTcpBuilder(settings.host, settings.port).setTimeout(settings.timeout).setConnectionTimeout(settings.connectionTimeout).build();
}
} catch (IOException e) {
throw new ScanException(e);
}
if (logger.isTraceEnabled()) {
mBusConnection.setVerboseMessageListener(new VerboseMessageListenerImpl());
}
} else {
mBusConnection = interfaces.get(settings.scanConnectionAddress).getMBusConnection();
}
ConnectionInterface connectionInterface = interfaces.get(settings.scanConnectionAddress);
if (connectionInterface != null && connectionInterface.isOpen()) {
throw new ScanException("Device is already connected. Disable device which uses port " + settings.scanConnectionAddress + ", before scan.");
}
try {
if (settings.scanSecondary) {
SecondaryAddressListenerImplementation secondaryAddressListenerImplementation = new SecondaryAddressListenerImplementation(listener, settings.scanConnectionAddress);
mBusConnection.scan("ffffffff", secondaryAddressListenerImplementation, settings.delay);
} else {
scanPrimaryAddress(listener, settings, mBusConnection);
}
} catch (IOException e) {
logger.error("Failed to scan for devices.", e);
} finally {
mBusConnection.close();
}
}
use of org.openmuc.framework.config.ScanException in project OpenMUC by isc-konstanz.
the class ColumnScanner method scan.
@Override
public void scan(List<ChannelScanInfo> channels) throws ArgumentSyntaxException, ScanException, ConnectionException {
logger.info("Scan for columns in {}.{}", database, table);
try (Connection connection = source.getConnection()) {
try (Statement statement = connection.createStatement()) {
try (ResultSet result = statement.executeQuery(String.format("SELECT * FROM %s LIMIT 1", table))) {
if (result.first()) {
ResultSetMetaData metaData = result.getMetaData();
for (int i = 1; i <= metaData.getColumnCount(); i++) {
String column = metaData.getColumnName(i);
Integer typeLength = null;
ValueType type;
switch(metaData.getColumnTypeName(i)) {
case "BIT":
type = ValueType.BOOLEAN;
break;
case "TINYINT":
type = ValueType.BYTE;
break;
case "SMALLINT":
type = ValueType.SHORT;
break;
case "INTEGER":
type = ValueType.INTEGER;
break;
case "BIGINT":
type = ValueType.LONG;
break;
case "REAL":
type = ValueType.FLOAT;
break;
case "DOUBLE":
case "NUMERIC":
type = ValueType.DOUBLE;
break;
case "VARBINARY":
case "LONGVARBINARY":
typeLength = metaData.getColumnDisplaySize(i);
type = ValueType.BYTE_ARRAY;
break;
case "VARCHAR":
case "LONGVARCHAR":
default:
typeLength = metaData.getColumnDisplaySize(i);
type = ValueType.STRING;
}
channels.add(new ChannelScanInfo(column, column, type, typeLength));
}
}
} catch (SQLException e) {
throw new ScanException(e);
}
}
} catch (SQLException e) {
throw new ConnectionException(e);
}
}
use of org.openmuc.framework.config.ScanException 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.ScanException in project OpenMUC by isc-konstanz.
the class CsvScanDeviceTest method testChannelScan.
@Test
public void testChannelScan() {
CsvDriver csvDriver = new CsvDriver();
String deviceAddress = dir + "/src/test/resources/test_data.csv";
try {
String settings = "SAMPLINGMODE=hhmmss";
CsvFile csvConnection = (CsvFile) csvDriver.connect(deviceAddress, settings);
List<ChannelScanInfo> channelsScanInfos = csvConnection.scanForChannels("");
for (ChannelScanInfo info : channelsScanInfos) {
System.out.println("Channel: " + info.getChannelAddress());
}
} catch (ArgumentSyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ConnectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ScanException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations