diff --git a/src/main/java/ch/hevs/isi/field/BooleanRegister.java b/src/main/java/ch/hevs/isi/field/BooleanRegister.java index 205f596..a2a343e 100644 --- a/src/main/java/ch/hevs/isi/field/BooleanRegister.java +++ b/src/main/java/ch/hevs/isi/field/BooleanRegister.java @@ -19,6 +19,9 @@ public class BooleanRegister extends ModbusRegister{ updateMapOfRegisters(label, address); //add the address to the map } @Override + /** + * function to read a boolean datapoint from the modbus register + */ public void read() { if(bdp.isOutput()){ return; //if it is an output datapoint, it is not read @@ -27,6 +30,9 @@ public class BooleanRegister extends ModbusRegister{ } @Override + /** + * function to write a boolean datapoint on the modbus register + */ public void write(DataPoint dp) { bdp = (BooleanDataPoint) dp; //make the empty datapoint to the desired datapoint, which is to be written on the address value = bdp.getValue(); //store the value of the datapoint diff --git a/src/main/java/ch/hevs/isi/field/FieldConnector.java b/src/main/java/ch/hevs/isi/field/FieldConnector.java index 23a372c..6eb438b 100644 --- a/src/main/java/ch/hevs/isi/field/FieldConnector.java +++ b/src/main/java/ch/hevs/isi/field/FieldConnector.java @@ -14,12 +14,17 @@ import java.util.Timer; public class FieldConnector implements DataPointListener { private static FieldConnector mySelf = null; + /** + * private constructor + * initialize the FieldConnector + * it connects the ModbusAccessor, reads the csv-file of the ModbusMap + * and starts the periodical polling of the modbus registers + */ private FieldConnector(){ initialize("LocalHost",1502, "src/main/resources/ModbusMap.csv"); // Subscribe to the update of DataPoints - DataPointListener.subscribeUpdate(this); } @@ -89,10 +94,20 @@ public class FieldConnector implements DataPointListener { startPeriodicalPolling(); //start periodical reading of the values } + + /** + * this function is only to show the datapoint, which is pushed to filed in the onNewValue function + * @param label label of the datapoint + * @param value value of the datapoint + */ private void pushToField(String label, String value){ Utility.pDebug("Field: " + label + " " + value); } @Override + /** + * everytime a new value should be writen by any connector, this function is called + * updates the value of the datapoint on the field + */ public void onNewValue(DataPoint dp) { ModbusRegister mR = ModbusRegister.getRegisterFromDatapoint(dp); //search the corresponding register to the datapoint if(mR == null) return; //if the register is not found, return diff --git a/src/main/java/ch/hevs/isi/field/FloatRegister.java b/src/main/java/ch/hevs/isi/field/FloatRegister.java index 56f5e03..09ae2be 100644 --- a/src/main/java/ch/hevs/isi/field/FloatRegister.java +++ b/src/main/java/ch/hevs/isi/field/FloatRegister.java @@ -28,17 +28,23 @@ public class FloatRegister extends ModbusRegister{ } @Override + /** + * function to read a float datapoint from the modbus register + */ public void read() { if(fdp.isOutput()){ return; //if it is an output datapoint, it is not read } Float value = ModbusAccessor.getMySelf().readFloat(this.getAddress()); //read the value - value = value * range; - value = value + offset; + value = value * range; //calculate value + value = value + offset; //calculate value fdp.setValue(value); } @Override + /** + * function to write a boolean datapoint on the modbus register + */ public void write(DataPoint dp) { fdp = (FloatDataPoint) dp; //make the empty datapoint to the desired datapoint, which is to be written on the address value = fdp.getValue(); //store the value of the datapoint diff --git a/src/main/java/ch/hevs/isi/field/ModbusRegister.java b/src/main/java/ch/hevs/isi/field/ModbusRegister.java index 6c87cff..4fbc915 100644 --- a/src/main/java/ch/hevs/isi/field/ModbusRegister.java +++ b/src/main/java/ch/hevs/isi/field/ModbusRegister.java @@ -14,7 +14,7 @@ public abstract class ModbusRegister { public int getAddress() { return address; } - private final static HashMap mapOfRegisters = new HashMap<>(); + private final static HashMap mapOfRegisters = new HashMap<>(); //map to store the register /** * get the modbus register from the desired datapoint @@ -43,6 +43,15 @@ public abstract class ModbusRegister { mr.read(); //read each datapoint, which address is stored in the map } } + + /** + * function to read a datapoint from the modbus register + */ public abstract void read(); //abstract prototype of the method read + + /** + * function to write datapoint on the modbus register + * @param dp datapoint to write on the address + */ public abstract void write(DataPoint dp); //abstract prototype of the method read }