1
0

field not finished, connection works

This commit is contained in:
Nils Ritler 2023-05-26 16:11:02 +02:00
parent c3f15804b6
commit 0d105fb64e
6 changed files with 59 additions and 23 deletions

View File

@ -36,8 +36,6 @@ public abstract class DataPoint{
}
/**
* Just get the label of this DataPoint
* @return the label in a string

View File

@ -8,16 +8,17 @@ public class BooleanRegister extends ModbusRegister{
public BooleanRegister(String label, boolean isOutput, int address){
this.bdp = new BooleanDataPoint(label, isOutput);
value = bdp.getValue();
updateMapOfRegisters(bdp, address);
}
@Override
public void read() {
bdp.setValue(ModbusAccessor.getMySelf().readBoolean(address));
bdp.setValue(ModbusAccessor.getMySelf().readBoolean(this.getAddress()));
}
@Override
public void write() {
ModbusAccessor.getMySelf().writeBoolean(address, bdp.getValue());
ModbusAccessor.getMySelf().writeBoolean(this.getAddress(), bdp.getValue());
}
}

View File

@ -16,21 +16,22 @@ public class FieldConnector implements DataPointListener {
}
return mySelf;
}
public void initialize(String host, int port){
ModbusAccessor mbA = ModbusAccessor.getMySelf();
mbA.connect(host, port);
}
private void pushToField(DataPoint dp){
ModbusRegister mr = ModbusRegister.getRegisterFromDatapoint(dp);
mr.write();
}
@Override
public void onNewValue(DataPoint dp) {
pushToField(dp);
ModbusRegister mr = ModbusRegister.getRegisterFromDatapoint(dp);
mr.write();
}
public void periodicalPolling(){
public void startPeriodicalPolling(){
Timer pollTimer = new Timer();
PollTask pollTask = new PollTask();
pollTimer.scheduleAtFixedRate(pollTask,0,2000);
pollTimer.scheduleAtFixedRate(pollTask,0,100);
}
}

View File

@ -4,20 +4,21 @@ import ch.hevs.isi.core.FloatDataPoint;
public class FloatRegister extends ModbusRegister{
private Float value;
private FloatDataPoint dataPoint;
private FloatDataPoint fdp;
public FloatRegister(String label, boolean isOutPut, int address) {
this.dataPoint = new FloatDataPoint(label, isOutPut);
updateMapOfRegisters(dataPoint,address);
this.fdp = new FloatDataPoint(label, isOutPut);
value = fdp.getValue();
updateMapOfRegisters(fdp,address);
}
@Override
public void read() {
dataPoint.setValue(ModbusAccessor.getMySelf().readFloat(address));
fdp.setValue(ModbusAccessor.getMySelf().readFloat(this.getAddress()));
}
@Override
public void write() {
ModbusAccessor.getMySelf().writeFloat(address, dataPoint.getValue());
ModbusAccessor.getMySelf().writeFloat(this.getAddress(), fdp.getValue());
}
}

View File

@ -3,24 +3,25 @@ package ch.hevs.isi.field;
import ch.hevs.isi.core.DataPoint;
import java.util.HashMap;
import java.util.Map;
public abstract class ModbusRegister {
protected int address;
public static HashMap<DataPoint, ModbusRegister> map = new HashMap<>();
private int address;
public static HashMap<DataPoint, ModbusRegister> mapOfRegisters = new HashMap<>();
public void updateMapOfRegisters(DataPoint dp, int address){
this.address = address;
map.put(dp,this);
}
public static ModbusRegister getRegisterFromDatapoint(DataPoint dp){
return map.get(dp);
mapOfRegisters.put(dp,this);
}
public int getAddress() {
return address;
}
public static ModbusRegister getRegisterFromDatapoint(DataPoint dp){
return mapOfRegisters.get(dp);
}
public static void poll(){
for (ModbusRegister mr : map.values()){
for (ModbusRegister mr : mapOfRegisters.values()){
mr.read(); //read all values (registers) of the map
}
}

34
src/test/java/Field.java Normal file
View File

@ -0,0 +1,34 @@
import ch.hevs.isi.core.BooleanDataPoint;
import ch.hevs.isi.core.FloatDataPoint;
import ch.hevs.isi.field.BooleanRegister;
import ch.hevs.isi.field.FieldConnector;
import ch.hevs.isi.field.FloatRegister;
public class Field {
public static void main(String[] args) {
FloatRegister fRI = new FloatRegister("GRID_U_FLOAT",false,89);
BooleanRegister bRI = new BooleanRegister("SOLAR_CONNECT_ST", false ,609);
FieldConnector.getMySelf().startPeriodicalPolling();
FloatRegister fRO = new FloatRegister("REMOTE_FACTORY_SP",true,205);
BooleanRegister bRO = new BooleanRegister("REMOTE_SOLAR_SW", true ,401);
/*
fRO.fdp.setValue(0.8F);
bRO.bdp.setValue(true);
*/
while(true)
{
/*
float value = fRI.dataPoint.getValue()*1000;
System.out.println(value);
*/
/*
System.out.println(bRI.bdp.getValue());
*/
}
}
}