use of com.beanit.iec61850bean.ServerModel in project OpenMUC by isc-konstanz.
the class Iec61850ConnectionTest method testWrite.
@Test
public void testWrite() throws IOException, ServiceError, ConfigurationException, javax.naming.ConfigurationException, SclParseException, InterruptedException, UnsupportedOperationException, ConnectionException {
System.out.println("Attempting to connect to server " + host + " on port " + port);
clientAssociation = clientSap.associate(InetAddress.getByName(host), port, null, this);
ServerModel serverModel = SclParser.parse("src/test/resources/testOpenmuc.icd").get(0);
clientAssociation.setServerModel(serverModel);
getAllBdas(serverModel, clientAssociation);
// ------------SCAN FOR CHANNELS-------------------
Iec61850Connection testIec61850Connection = new Iec61850Connection(clientAssociation, serverModel);
List<ChannelScanInfo> testChannelScanList = testIec61850Connection.scanForChannels("");
// ----------WRITE-----------------
List<ChannelValueContainer> testChannelValueContainers = new ArrayList<>();
byte[] newValue = { 0x44 };
testChannelValueContainers.add(new ChannelValueContainerImpl(testChannelScanList.get(14).getChannelAddress(), new ByteArrayValue(newValue)));
testChannelValueContainers.add(new ChannelValueContainerImpl(testChannelScanList.get(25).getChannelAddress(), new FloatValue((float) 12.5)));
testChannelValueContainers.add(new ChannelValueContainerImpl(testChannelScanList.get(24).getChannelAddress(), new BooleanValue(true)));
testIec61850Connection.write(testChannelValueContainers, null);
// Create record container to read the changes made by "write"
List<ChannelRecordContainer> testRecordContainers = new ArrayList<>();
for (int i = 0; i < 34; i++) {
testRecordContainers.add(new ChannelRecordContainerImpl(testChannelScanList.get(i).getChannelAddress()));
}
testIec61850Connection.read(testRecordContainers, null, "");
Assert.assertEquals("[68]", testRecordContainers.get(14).getRecord().getValue().toString());
Assert.assertEquals("12.5", testRecordContainers.get(25).getRecord().getValue().toString());
Assert.assertEquals("true", testRecordContainers.get(24).getRecord().getValue().toString());
}
use of com.beanit.iec61850bean.ServerModel in project OpenMUC by isc-konstanz.
the class Iec61850ConnectionTest method testScanForChannels.
@Test
public void testScanForChannels() throws IOException, ServiceError, ConfigurationException, javax.naming.ConfigurationException, SclParseException, InterruptedException, UnsupportedOperationException, ConnectionException {
System.out.println("Attempting to connect to server " + host + " on port " + port);
clientAssociation = clientSap.associate(InetAddress.getByName(host), port, null, this);
ServerModel serverModel = SclParser.parse("src/test/resources/testOpenmuc.icd").get(0);
clientAssociation.setServerModel(serverModel);
getAllBdas(serverModel, clientAssociation);
Iec61850Connection testConnection = new Iec61850Connection(clientAssociation, serverModel);
List<ChannelScanInfo> testChannelScanList = testConnection.scanForChannels("");
for (int i = 14; i < 23; i++) {
System.out.print(testChannelScanList.get(i).getChannelAddress() + "\n");
Assert.assertEquals("BYTE_ARRAY", testChannelScanList.get(i).getValueType().toString());
}
Assert.assertEquals("LONG", testChannelScanList.get(23).getValueType().toString());
Assert.assertEquals("BOOLEAN", testChannelScanList.get(24).getValueType().toString());
Assert.assertEquals("FLOAT", testChannelScanList.get(25).getValueType().toString());
Assert.assertEquals("DOUBLE", testChannelScanList.get(26).getValueType().toString());
Assert.assertEquals("BYTE", testChannelScanList.get(27).getValueType().toString());
Assert.assertEquals("SHORT", testChannelScanList.get(28).getValueType().toString());
Assert.assertEquals("SHORT", testChannelScanList.get(29).getValueType().toString());
Assert.assertEquals("INTEGER", testChannelScanList.get(30).getValueType().toString());
Assert.assertEquals("INTEGER", testChannelScanList.get(31).getValueType().toString());
Assert.assertEquals("LONG", testChannelScanList.get(32).getValueType().toString());
Assert.assertEquals("LONG", testChannelScanList.get(33).getValueType().toString());
Assert.assertEquals("BYTE_ARRAY", testChannelScanList.get(34).getValueType().toString());
}
use of com.beanit.iec61850bean.ServerModel in project OpenMUC by isc-konstanz.
the class Iec61850ConnectionTest method testRead.
@Test
public void testRead() throws IOException, ServiceError, ConfigurationException, javax.naming.ConfigurationException, SclParseException, InterruptedException, UnsupportedOperationException, ConnectionException {
System.out.println("Attempting to connect to server " + host + " on port " + port);
clientAssociation = clientSap.associate(InetAddress.getByName(host), port, null, this);
ServerModel serverModel = SclParser.parse("src/test/resources/testOpenmuc.icd").get(0);
clientAssociation.setServerModel(serverModel);
getAllBdas(serverModel, clientAssociation);
// ------------SCAN FOR CHANNELS-------------------
Iec61850Connection testIec61850Connection = new Iec61850Connection(clientAssociation, serverModel);
List<ChannelRecordContainer> testRecordContainers = new ArrayList<>();
List<ChannelScanInfo> testChannelScanList = testIec61850Connection.scanForChannels("");
for (int i = 14; i < 34; i++) {
testRecordContainers.add(new ChannelRecordContainerImpl(testChannelScanList.get(i).getChannelAddress()));
}
// ----------READ-------------------
testIec61850Connection.read(testRecordContainers, null, "");
System.out.print("recordContainer:" + testRecordContainers.get(0).getRecord() + "\n");
Assert.assertEquals("[64]", testRecordContainers.get(0).getRecord().getValue().toString());
System.out.print("recordContainer:" + testRecordContainers.get(0).getRecord() + "\n");
Assert.assertEquals("[64]", testRecordContainers.get(0).getRecord().getValue().toString());
}
use of com.beanit.iec61850bean.ServerModel in project OpenMUC by isc-konstanz.
the class Iec61850Driver method connect.
@Override
public Connection connect(String deviceAddress, String settings) throws ArgumentSyntaxException, ConnectionException {
DeviceAddress deviceAdress = new DeviceAddress(deviceAddress);
DeviceSettings deviceSettings = new DeviceSettings(settings);
ClientSap clientSap = new ClientSap();
clientSap.setTSelLocal(deviceSettings.getTSelLocal());
clientSap.setTSelLocal(deviceSettings.getTSelRemote());
ClientAssociation clientAssociation;
try {
clientAssociation = clientSap.associate(deviceAdress.getAdress(), deviceAdress.getRemotePort(), deviceSettings.getAuthentication(), null);
} catch (IOException e) {
throw new ConnectionException(e);
}
ServerModel serverModel;
try {
serverModel = clientAssociation.retrieveModel();
} catch (ServiceError e) {
clientAssociation.close();
throw new ConnectionException("Service error retrieving server model" + e.getMessage(), e);
} catch (IOException e) {
clientAssociation.close();
throw new ConnectionException("IOException retrieving server model: " + e.getMessage(), e);
}
return new Iec61850Connection(clientAssociation, serverModel);
}
Aggregations