add comments to the field package
This commit is contained in:
parent
746f7f00be
commit
0234e90ea8
@ -19,6 +19,9 @@ public class BooleanRegister extends ModbusRegister{
|
|||||||
updateMapOfRegisters(label, address); //add the address to the map
|
updateMapOfRegisters(label, address); //add the address to the map
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
/**
|
||||||
|
* function to read a boolean datapoint from the modbus register
|
||||||
|
*/
|
||||||
public void read() {
|
public void read() {
|
||||||
if(bdp.isOutput()){
|
if(bdp.isOutput()){
|
||||||
return; //if it is an output datapoint, it is not read
|
return; //if it is an output datapoint, it is not read
|
||||||
@ -27,6 +30,9 @@ public class BooleanRegister extends ModbusRegister{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
/**
|
||||||
|
* function to write a boolean datapoint on the modbus register
|
||||||
|
*/
|
||||||
public void write(DataPoint dp) {
|
public void write(DataPoint dp) {
|
||||||
bdp = (BooleanDataPoint) dp; //make the empty datapoint to the desired datapoint, which is to be written on the address
|
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
|
value = bdp.getValue(); //store the value of the datapoint
|
||||||
|
@ -13,12 +13,17 @@ import java.util.Timer;
|
|||||||
public class FieldConnector implements DataPointListener {
|
public class FieldConnector implements DataPointListener {
|
||||||
private static FieldConnector mySelf = null;
|
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(){
|
private FieldConnector(){
|
||||||
initialize("LocalHost",1502, "src/main/resources/ModbusMap.csv");
|
initialize("LocalHost",1502, "src/main/resources/ModbusMap.csv");
|
||||||
|
|
||||||
|
|
||||||
// Subscribe to the update of DataPoints
|
// Subscribe to the update of DataPoints
|
||||||
|
|
||||||
DataPointListener.subscribeUpdate(this);
|
DataPointListener.subscribeUpdate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,10 +93,20 @@ public class FieldConnector implements DataPointListener {
|
|||||||
startPeriodicalPolling(); //start periodical reading of the values
|
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){
|
private void pushToField(String label, String value){
|
||||||
System.out.println("Field: " + label + " " + value);
|
System.out.println("Field: " + label + " " + value);
|
||||||
}
|
}
|
||||||
@Override
|
@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) {
|
public void onNewValue(DataPoint dp) {
|
||||||
ModbusRegister mR = ModbusRegister.getRegisterFromDatapoint(dp); //search the corresponding register to the datapoint
|
ModbusRegister mR = ModbusRegister.getRegisterFromDatapoint(dp); //search the corresponding register to the datapoint
|
||||||
if(dp.isOutput()){ //write only on the datapoints, which are outputs
|
if(dp.isOutput()){ //write only on the datapoints, which are outputs
|
||||||
|
@ -28,17 +28,23 @@ public class FloatRegister extends ModbusRegister{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
/**
|
||||||
|
* function to read a float datapoint from the modbus register
|
||||||
|
*/
|
||||||
public void read() {
|
public void read() {
|
||||||
if(fdp.isOutput()){
|
if(fdp.isOutput()){
|
||||||
return; //if it is an output datapoint, it is not read
|
return; //if it is an output datapoint, it is not read
|
||||||
}
|
}
|
||||||
Float value = ModbusAccessor.getMySelf().readFloat(this.getAddress()); //read the value
|
Float value = ModbusAccessor.getMySelf().readFloat(this.getAddress()); //read the value
|
||||||
value = value * range;
|
value = value * range; //calculate value
|
||||||
value = value + offset;
|
value = value + offset; //calculate value
|
||||||
fdp.setValue(value);
|
fdp.setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
/**
|
||||||
|
* function to write a boolean datapoint on the modbus register
|
||||||
|
*/
|
||||||
public void write(DataPoint dp) {
|
public void write(DataPoint dp) {
|
||||||
fdp = (FloatDataPoint) dp; //make the empty datapoint to the desired datapoint, which is to be written on the address
|
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
|
value = fdp.getValue(); //store the value of the datapoint
|
||||||
|
@ -14,7 +14,7 @@ public abstract class ModbusRegister {
|
|||||||
public int getAddress() {
|
public int getAddress() {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
private final static HashMap<String, ModbusRegister> mapOfRegisters = new HashMap<>();
|
private final static HashMap<String, ModbusRegister> mapOfRegisters = new HashMap<>(); //map to store the register
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the modbus register from the desired datapoint
|
* 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
|
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
|
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
|
public abstract void write(DataPoint dp); //abstract prototype of the method read
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user