Search in sources :

Example 1 with ModbusTCPMaster

use of com.ghgande.j2mod.modbus.facade.ModbusTCPMaster in project openems by OpenEMS.

the class ModbusMaster method main.

public static void main(String[] args) {
    ModbusTCPMaster master = new ModbusTCPMaster("10.0.10.230", 502, 10000, true);
    try {
        master.connect();
        Register[] registers = master.readMultipleRegisters(40000, 1);
        for (Register register : registers) {
            System.out.println(register);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        master.disconnect();
    }
}
Also used : ModbusTCPMaster(com.ghgande.j2mod.modbus.facade.ModbusTCPMaster) Register(com.ghgande.j2mod.modbus.procimg.Register)

Example 2 with ModbusTCPMaster

use of com.ghgande.j2mod.modbus.facade.ModbusTCPMaster in project openems by OpenEMS.

the class StreetscooterTest method main.

public static void main(String[] args) {
    ModbusTCPMaster master = new ModbusTCPMaster("localhost", 502, 10000, true);
    try {
        master.connect();
        // Register[] registers = master.readMultipleRegisters(30011, 2);
        InputRegister[] registers = master.readInputRegisters(100, 6, 4);
        for (InputRegister register : registers) {
            System.out.println(register);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        master.disconnect();
    }
}
Also used : ModbusTCPMaster(com.ghgande.j2mod.modbus.facade.ModbusTCPMaster) InputRegister(com.ghgande.j2mod.modbus.procimg.InputRegister)

Example 3 with ModbusTCPMaster

use of com.ghgande.j2mod.modbus.facade.ModbusTCPMaster in project energy by nielsbasjes.

the class TestRealDeviceSolarEdge method verifyTheValues.

@Test
public void verifyTheValues() throws ModbusException, MissingMandatoryFieldException {
    try (SunSpecModbusDataReader dataReader = new SunSpecModbusDataReader(new ModbusTCPMaster(getHost(), getTestport()))) {
        SunSpecFetcher fetcher = new SunSpecFetcher(dataReader).useAllModels();
        fetcher.refresh();
        assertEquals("SolarEdge ", fetcher.model_1.getManufacturer());
        assertEquals("SE3000H-RW000BNN4", fetcher.model_1.getModel());
        assertEquals(509.20, fetcher.model_101.getWatts(), 0.0001);
        assertEquals(38.14, fetcher.model_101.getHeatSinkTemperature(), 0.0001);
    }
}
Also used : ModbusTCPMaster(com.ghgande.j2mod.modbus.facade.ModbusTCPMaster) Test(org.junit.Test)

Example 4 with ModbusTCPMaster

use of com.ghgande.j2mod.modbus.facade.ModbusTCPMaster in project energy by nielsbasjes.

the class TestSunSpecFetcher method getBlockListTest.

@Test
public void getBlockListTest() throws Exception {
    try (SunSpecModbusDataReader dataReader = new SunSpecModbusDataReader(new ModbusTCPMaster(getHost(), getTestport()))) {
        dataReader.connect();
        final Map<Integer, SunSpecModbusDataReader.ModelLocation> blockLocations = dataReader.getModelLocations(SUNSPEC_STANDARD_STARTBASE);
        int[][] expected = { { 1, 40004, 65 }, { 101, 40071, 50 }, { 120, 40123, 26 }, { 121, 40151, 30 }, { 122, 40183, 44 }, { 123, 40229, 24 }, { 126, 40255, 226 }, { 131, 40483, 226 }, { 132, 40711, 226 } };
        int exp = 0;
        for (Map.Entry<Integer, ModelLocation> entry : blockLocations.entrySet()) {
            Integer i = entry.getKey();
            SunSpecModbusDataReader.ModelLocation b = entry.getValue();
            assertEquals((int) i, b.id);
            assertEquals(expected[exp][0], b.id);
            assertEquals(expected[exp][1], b.registerBase);
            assertEquals(expected[exp][2], b.len);
            exp++;
        }
    }
}
Also used : ModbusTCPMaster(com.ghgande.j2mod.modbus.facade.ModbusTCPMaster) ModelLocation(nl.basjes.energy.sunspec.SunSpecModbusDataReader.ModelLocation) ModelLocation(nl.basjes.energy.sunspec.SunSpecModbusDataReader.ModelLocation) Map(java.util.Map) Test(org.junit.Test)

Example 5 with ModbusTCPMaster

use of com.ghgande.j2mod.modbus.facade.ModbusTCPMaster in project energy by nielsbasjes.

the class TestSunSpecFetcher method requestNonExistendModel.

@Test(expected = UnsupportedOperationException.class)
public void requestNonExistendModel() throws Exception {
    SunSpecModbusDataReader dataReader = new SunSpecModbusDataReader(new ModbusTCPMaster(getHost(), getTestport()));
    new SunSpecFetcher(dataReader).useModel(1).useModel(123456);
}
Also used : ModbusTCPMaster(com.ghgande.j2mod.modbus.facade.ModbusTCPMaster) Test(org.junit.Test)

Aggregations

ModbusTCPMaster (com.ghgande.j2mod.modbus.facade.ModbusTCPMaster)15 Test (org.junit.Test)12 ModbusException (com.ghgande.j2mod.modbus.ModbusException)2 Map (java.util.Map)2 SunSpecModbusDataReader (nl.basjes.energy.sunspec.SunSpecModbusDataReader)2 ModelLocation (nl.basjes.energy.sunspec.SunSpecModbusDataReader.ModelLocation)2 Ignore (org.junit.Ignore)2 InputRegister (com.ghgande.j2mod.modbus.procimg.InputRegister)1 Register (com.ghgande.j2mod.modbus.procimg.Register)1 SunSpecFetcher (nl.basjes.energy.sunspec.SunSpecFetcher)1 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)1 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)1