package org.openmuc.openiec61850.app; import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; import javax.swing.JCheckBox; import org.openmuc.openiec61850.BdaFloat32; import org.openmuc.openiec61850.BdaBoolean; import org.openmuc.openiec61850.ClientAssociation; import org.openmuc.openiec61850.ClientSap; import org.openmuc.openiec61850.DataSet; import org.openmuc.openiec61850.Fc; import org.openmuc.openiec61850.FcModelNode; import org.openmuc.openiec61850.ServerModel; import org.openmuc.openiec61850.ServiceError; import org.openmuc.openiec61850.clientgui.BasicDataBind; import org.openmuc.openiec61850.internal.cli.CliParameter; import org.openmuc.openiec61850.internal.cli.CliParameterBuilder; import org.openmuc.openiec61850.internal.cli.CliParseException; import org.openmuc.openiec61850.internal.cli.CliParser; import org.openmuc.openiec61850.internal.cli.IntCliParameter; import org.openmuc.openiec61850.internal.cli.StringCliParameter; import org.openmuc.openiec61850.clientgui.databind.BooleanDataBind; /** * * @author Stefan Feuerhahn * */ public class ConsoleClient_1 { private static final StringCliParameter hostParam = new CliParameterBuilder("-h") .setDescription("The IP/domain address of the server you want to access.") .setMandatory() .buildStringParameter("host"); private static final IntCliParameter portParam = new CliParameterBuilder("-p") .setDescription("The port to connect to.") .buildIntParameter("port", 102); private static final StringCliParameter modelFileParam = new CliParameterBuilder("-m").setDescription( "The file name of the SCL file to read the model from. If this parameter is omitted the model will be read from the server device after connection.") .buildStringParameter("model-file"); private static volatile ClientAssociation association; private static ServerModel serverModel; public static void writeNodeData(String reference, String fc_str) { FcModelNode fcModelNode = (FcModelNode)serverModel.findModelNode(reference, Fc.fromString(fc_str)); if(null == fcModelNode) { System.err.println("error, no modenode was found....."); return; } System.out.println("Sending SetDataValues request..."); try { /* BasicDataBind data = new Float32DataBind((BdaFloat32)fcModelNode); JTextField tf_t = (JTextField)data.getValueField(); tf_t.setText("12.0"); */ BasicDataBind data = new BooleanDataBind((BdaBoolean)fcModelNode.getChild("ctlVal")); JCheckBox ckb_t = (JCheckBox)data.getValueField(); ckb_t.setSelected(false); data.write(); association.setDataValues(fcModelNode); } catch (ServiceError e) { System.out.println("Service error: " + e.getMessage()); return; } catch (IOException e) { System.out.println("Fatal error: " + e.getMessage()); return; } System.out.println("Successfully write data."); } public static void readNodeData(String reference, String fc_str) { FcModelNode fcModelNode = (FcModelNode)serverModel.findModelNode(reference, Fc.fromString(fc_str)); if(null == fcModelNode) { System.err.println("error, no modenode was found....."); return; } System.out.println("Sending GetDataValues request..."); try { association.getDataValues(fcModelNode); } catch (ServiceError e) { System.out.println("Service error: " + e.getMessage()); return; } catch (IOException e) { System.out.println("Fatal error: " + e.getMessage()); return; } System.out.println("Successfully read data."); /* BasicDataBind data = new Float32DataBind((BdaFloat32)fcModelNode); JTextField tf_t = (JTextField)data.getValueField(); System.out.println("The modelnode is:" + fcModelNode.getReference() + ", the value is: " + tf_t.getText()); */ BasicDataBind data = new BooleanDataBind((BdaBoolean)fcModelNode.getChild("ctlVal")); JCheckBox ckb_t = (JCheckBox)data.getValueField(); System.out.println("The modelnode is:" + fcModelNode.getChild("ctlVal").getReference() + ", the value is: " + ckb_t.isSelected()); } public static void main(String[] args) { List cliParameters = new ArrayList<>(); cliParameters.add(hostParam); cliParameters.add(portParam); cliParameters.add(modelFileParam); CliParser cliParser = new CliParser("openiec61850-console-client", "A client application to access IEC 61850 MMS servers."); cliParser.addParameters(cliParameters); try { cliParser.parseArguments(args); } catch (CliParseException e1) { System.err.println("Error parsing command line parameters: " + e1.getMessage()); System.out.println(cliParser.getUsageString()); System.exit(1); } InetAddress address; try { address = InetAddress.getByName(hostParam.getValue()); } catch (UnknownHostException e) { System.out.println("Unknown host: " + hostParam.getValue()); return; } ClientSap clientSap = new ClientSap(); while(true) { try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { association = clientSap.associate(address, portParam.getValue(), null, null); } catch (IOException e) { System.out.println("Unable to connect to remote host."); continue; } System.out.println("successfully connected"); System.out.println("retrieving model..."); try { serverModel = association.retrieveModel(); } catch (ServiceError e) { System.out.println("Service error: " + e.getMessage()); continue; } catch (IOException e) { System.out.println("Fatal error: " + e.getMessage()); continue; } System.out.println("successfully read model"); /* writeNodeData("ZJDYBTSE/ncdGGIO1.Para6.setMag.f", "SP"); readNodeData("ZJDYBTSE/ncdGGIO1.Para6.setMag.f", "SP"); */ //DataSet ds_pm = serverModel.getDataSet("ZJDYBTSE/LLN0.dsParameter"); //int size_cnt = ds_pm.getMembers().size(); //m_Association.getDataSetValues(ds_pm); /* for(int n=0; n data = new Float32DataBind((BdaFloat32)fc_mode); JTextField tf_t = (JTextField)data.getValueField(); tf_t.setText(String.valueOf(n+1)); data.write(); } try { association.setDataSetValues(ds_pm); } catch (ServiceError e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("done"); */ writeNodeData("ZJDYBTSE/ncdGGIO1.SPCSO1.Oper", "CO"); readNodeData("ZJDYBTSE/ncdGGIO1.SPCSO1.Oper", "CO"); while(true) { DataSet ds = serverModel.getDataSet("ZJDYBTSE/LLN0.dsMeasure"); int size_cnt1 = ds.getMembers().size(); try { association.getDataSetValues(ds); String str_out = ""; for(int n=0; n data = new Float32DataBind((BdaFloat32)fc_mode); //((BdaFloat32)fc_mode).getFloat(); //JTextField tf_t = (JTextField)data.getValueField(); str_out += String.format("#%02d: %1.3f ", n+1, ((BdaFloat32)fc_mode).getFloat()); //System.out.println(fc_mode.getReference() + ", the value is: " + tf_t.getText()); //System.out.println(fc_mode.getChild("setMag").getChild("f").getReference()); } System.out.println(str_out); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); break; } finally { try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } } }