1
0
This repository has been archived on 2024-01-25. You can view files and clone it, but cannot push or open issues or pull requests.
2023-06-16 10:50:55 +02:00

42 lines
1.5 KiB
Java

package ch.hevs.isi.field;
import ch.hevs.isi.core.BooleanDataPoint;
import ch.hevs.isi.core.DataPoint;
public class BooleanRegister extends ModbusRegister{
private boolean value;
private BooleanDataPoint bdp;
/**
* public constructor of the booleanRegister
*
* @param label label of the datapoint
* @param isOutput true if it is an output datapoint
* @param address modbus address of the datapoint
*/
public BooleanRegister(String label, boolean isOutput, int address){
this.bdp = new BooleanDataPoint(label, isOutput); //create an empty datapoint for the NullPointerException
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
}
bdp.setValue(ModbusAccessor.getMySelf().readBoolean(this.getAddress())); //read the value
}
@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
ModbusAccessor.getMySelf().writeBoolean(this.getAddress(),bdp.getValue()); //write the desired value on the modbus address
}
}