### Start Simulator with Template and Serial Number Increment Source: https://github.com/gurux/gurux.dlms.java/blob/master/gurux.dlms.simulator.java/README.md This command starts the simulator with a template, specifying a TCP/IP port and detailed output. The '-N 10000' parameter sets a high number of simulated devices, and '-X' enables serial number incrementing for meters using the same TCP/IP port. ```bash java -jar target/gurux.dlms.simulator.java-0.0.1-SNAPSHOT.jar -p 1000 -x simulator_template.xml -t Verbose -N 10000 -X ``` -------------------------------- ### Handle Action Requests Source: https://github.com/gurux/gurux.dlms.java/blob/master/gurux.dlms.server.example.java/README.md Implement the action method to handle client-initiated actions, such as resets. This example provides an empty implementation. ```java @Override public void action(ValueEventArgs e) { } ``` -------------------------------- ### Initialize Server Objects Source: https://github.com/gurux/gurux.dlms.java/blob/master/gurux.dlms.server.example.java/README.md Initialize the objects that the meter will offer. This example adds a data object for the device name and sets its access rights to read-only. ```java public void Initialize(int port) throws IOException { /////////////////////////////////////////////////////////////////////// //Add Logical Device Name. 123456 is meter serial number. GXDLMSData d = new GXDLMSData("0.0.42.0.0.255"); d.setValue("Gurux123456"); //Set access right. Client can't change Device name. d.setAccess(2, AccessMode.READ); getItems().add(d); } ``` -------------------------------- ### Start Simulator with Template Source: https://github.com/gurux/gurux.dlms.java/blob/master/gurux.dlms.simulator.java/README.md Launch the simulator using a previously created template file. '-p 1000' sets the TCP/IP port, '-x simulator_template.xml' specifies the template, '-t Verbose' enables detailed output, and '-N 10' sets the number of simulated devices. ```bash java -jar target/gurux.dlms.simulator.java-0.0.1-SNAPSHOT.jar -p 1000 -x simulator_template.xml -t Verbose -N 10 ``` -------------------------------- ### Handle Write Requests Source: https://github.com/gurux/gurux.dlms.java/blob/master/gurux.dlms.server.example.java/README.md Implement the write method to handle client requests to write data. This example simply prints the new value and the target object's name to the console. ```java @Override public void write(ValueEventArgs e) { System.out.println(String.format("Client Write new value %1$s to object: %2$s.", e.getValue(), e.getTarget().getName())); } ``` -------------------------------- ### Create Simulator Template Source: https://github.com/gurux/gurux.dlms.java/blob/master/gurux.dlms.simulator.java/README.md Use this command to create a simulator template XML file by reading values from a real meter connected to a serial port. The '-t Verbose' option provides detailed output. ```bash java -jar target/gurux.dlms.simulator.java-0.0.1-SNAPSHOT.jar -S COM8 -o simulator_template.xml -t Verbose ``` -------------------------------- ### Handle Media Errors Source: https://github.com/gurux/gurux.dlms.java/blob/master/gurux.dlms.server.example.java/README.md The onError method is called when the media component encounters an error. This example provides an empty implementation. ```java @Override ``` -------------------------------- ### Read Association View and Objects Source: https://github.com/gurux/gurux.dlms.java/blob/master/gurux.dlms.client.example.java/README.md Retrieve the Association View from the meter to discover available objects. This involves reading a data block and then parsing the response to get a collection of GXDLMSObject. ```Java /// Read Association View from the meter. byte[] reply = readDataBlock(client.getObjects()); GXDLMSObjectCollection objects = client.parseObjects(reply, true); ``` -------------------------------- ### Configure GXDLMSClient Parameters Source: https://github.com/gurux/gurux.dlms.java/blob/master/gurux.dlms.client.example.java/README.md Set up essential parameters for the GXDLMSClient, including referencing type, interface type, client ID, and server ID. These parameters are manufacturer-specific. ```Java GXDLMSClient client = new GXDLMSClient(); // Is used Logical Name or Short Name referencing. client.setUseLogicalNameReferencing(true); // Is used HDLC or COSEM transport layers for IPv4 networks (WRAPPER). client.setInterfaceType(InterfaceType.HDLC); // Read http://www.gurux.org/dlmsAddress // to find out how Client and Server addresses are counted. // Some manufacturers might use own Server and Client addresses. client.setClientID(16); client.setServerID(1); ``` -------------------------------- ### Update and Write Complex Data Type (Object Property) Source: https://github.com/gurux/gurux.dlms.java/blob/master/gurux.dlms.client.example.java/README.md To write complex data types like arrays, first update the object's property in memory, then use the write method. This example updates the listening window of a GXDLMSAutoAnswer object. ```Java //Read Association view and find GXDLMSAutoAnswer object first. GXDLMSAutoAnswer item = Client.Object.findByLN("0.0.2.2.0.255", ObjectType.AUTOANSWER); //Window time is from 6am to 8am. item.getListeningWindow().add(new AbstractMap.SimpleEntry(new GXDateTime(-1, -1, -1, 6, -1, -1, -1), new GXDateTime(-1, -1, -1, 8, -1, -1, -1))); readDLMSPacket(Client.write(item, 3)); ``` -------------------------------- ### Server Class Declaration Source: https://github.com/gurux/gurux.dlms.java/blob/master/gurux.dlms.server.example.java/README.md Declare your server class by extending GXDLMSServerBase and implementing IGXMediaListener and gurux.net.yourself to support the DLMS/COSEM protocol and network communication. ```java public class GXDLMSExampleServer extends GXDLMS ServerBase implements IGXMediaListener, gurux.net.yourself ```