Modbus TCP: Connection refused

Hey everyone, I’m using Modbus TCP to connect to my inverter. However, I’m receiving message about refused connection.
My debug log:

Execute failed FC3ReadHoldingRegisters [batteryInverter0;unitid=1;priority=HIGH;ref=0/0x0;length=28] OpenemsException: Connection to [192.168.1.121] failed: Connection refused

The channels I have declared in my inverter:

@Override
    protected ModbusProtocol defineModbusProtocol() {
        return new ModbusProtocol(this, //
                new FC3ReadRegistersTask(0, Priority.HIGH, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.GRID_VOLTAGE_L1, new FloatDoublewordElement(0)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.GRID_VOLTAGE_L2, new FloatDoublewordElement(2)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.GRID_VOLTAGE_L3, new FloatDoublewordElement(4)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.GRID_CURRENT_L1, new FloatDoublewordElement(6)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.GRID_CURRENT_L2, new FloatDoublewordElement(8)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.GRID_CURRENT_L3, new FloatDoublewordElement(10)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.FREQUENCY, new FloatDoublewordElement(12)), //
                        m(SymmetricBatteryInverter.ChannelId.ACTIVE_POWER, new FloatDoublewordElement(14)), //
                        m(SymmetricBatteryInverter.ChannelId.REACTIVE_POWER, new FloatDoublewordElement(16)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.APPARENT_POWER_TOTAL, new FloatDoublewordElement(18)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.COS_PHI, new FloatDoublewordElement(20)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.TEMPERATURE_OF_AC_HEAT_SINK, new FloatDoublewordElement(22)), //                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.FREQUENCY, new FloatDoublewordElement(12)), //

                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DC_VOLTAGE, new FloatDoublewordElement(24)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DC_CURRENT, new FloatDoublewordElement(26))), //


                new FC3ReadRegistersTask(28, Priority.LOW, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CHARGE_MAX_CURRENT_READ, new FloatDoublewordElement(28)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DISCHARGE_MAX_CURRENT_READ, new FloatDoublewordElement(30)) //

                ),


                new FC3ReadRegistersTask(300, Priority.LOW, //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CHARGE_MAX_CURRENT, new FloatDoublewordElement(306)), //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DISCHARGE_MAX_CURRENT, new FloatDoublewordElement(308)), //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DISCHARGE_MIN_VOLTAGE, new FloatDoublewordElement(310)), //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CHARGE_MAX_VOLTAGE, new FloatDoublewordElement(312)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_ACTIVE_POWER, new FloatDoublewordElement(300)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_REACTIVE_POWER, new FloatDoublewordElement(302)), //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_OFF_GRID_FREQUENCY, new FloatDoublewordElement(318)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.START_INVERTER, new UnsignedWordElement(304)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.STOP_INVERTER, new UnsignedWordElement(305)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CLEAR_FAILURE, new UnsignedWordElement(306)) //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_ON_GRID_MODE, new UnsignedWordElement(323)), //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_OFF_GRID_MODE, new UnsignedWordElement(324), INVERT_BOOLEAN) //
                ),

                new FC3ReadRegistersTask(308, Priority.LOW, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CHARGE_MAX_CURRENT, new FloatDoublewordElement(308)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DISCHARGE_MAX_CURRENT, new FloatDoublewordElement(310)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DISCHARGE_MIN_VOLTAGE, new FloatDoublewordElement(312)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CHARGE_MAX_VOLTAGE, new FloatDoublewordElement(314)) //
                ),


                new FC3ReadRegistersTask(318, Priority.LOW, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_OFF_GRID_FREQUENCY, new FloatDoublewordElement(318))
                ),

                new FC3ReadRegistersTask(323, Priority.LOW, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_ON_GRID_MODE, new UnsignedWordElement(323)),
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_OFF_GRID_MODE, new UnsignedWordElement(324), INVERT_BOOLEAN) //
                ),



                new FC16WriteRegistersTask(300, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_ACTIVE_POWER, new FloatDoublewordElement(300))),
                new FC16WriteRegistersTask(302, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_REACTIVE_POWER, new FloatDoublewordElement(302))),
                new FC16WriteRegistersTask(304, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.START_INVERTER, new UnsignedWordElement(304))),
                new FC16WriteRegistersTask(305, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.STOP_INVERTER, new UnsignedWordElement(305))),
                new FC16WriteRegistersTask(306, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CLEAR_FAILURE, new UnsignedWordElement(306))),
                new FC16WriteRegistersTask(307, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.HEART_BEAT, new UnsignedWordElement(307))),
                new FC16WriteRegistersTask(308, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CHARGE_MAX_CURRENT, new SignedWordElement(308))),
                new FC16WriteRegistersTask(310, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DISCHARGE_MAX_CURRENT, new SignedWordElement(310))),
                new FC16WriteRegistersTask(312, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DISCHARGE_MIN_VOLTAGE, new SignedWordElement(312))),
                new FC16WriteRegistersTask(314, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CHARGE_MAX_VOLTAGE, new SignedWordElement(314))),
                new FC16WriteRegistersTask(318, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_OFF_GRID_FREQUENCY, new SignedWordElement(318))),
                new FC16WriteRegistersTask(323, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_ON_GRID_MODE, new UnsignedWordElement(323))),
                new FC16WriteRegistersTask(324, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_OFF_GRID_MODE, new UnsignedWordElement(324), INVERT_BOOLEAN)),
                new FC16WriteRegistersTask(325, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.OFF_GRID_BLACKSTART_MODE, new UnsignedWordElement(325)))
        ); //

    }

If I get rid of some of them the connection works. Could it be that there is something wrong with the declaration?
Following declartion works without a problem:

protected ModbusProtocol defineModbusProtocol() {
        return new ModbusProtocol(this, //
                new FC3ReadRegistersTask(0, Priority.HIGH, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.GRID_VOLTAGE_L1, new FloatDoublewordElement(0)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.GRID_VOLTAGE_L2, new FloatDoublewordElement(2)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.GRID_VOLTAGE_L3, new FloatDoublewordElement(4)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.GRID_CURRENT_L1, new FloatDoublewordElement(6)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.GRID_CURRENT_L2, new FloatDoublewordElement(8)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.GRID_CURRENT_L3, new FloatDoublewordElement(10)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.FREQUENCY, new FloatDoublewordElement(12)), //
                        m(SymmetricBatteryInverter.ChannelId.ACTIVE_POWER, new FloatDoublewordElement(14)), //
                        m(SymmetricBatteryInverter.ChannelId.REACTIVE_POWER, new FloatDoublewordElement(16)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.APPARENT_POWER_TOTAL, new FloatDoublewordElement(18)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.COS_PHI, new FloatDoublewordElement(20)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.TEMPERATURE_OF_AC_HEAT_SINK, new FloatDoublewordElement(22)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DC_VOLTAGE, new FloatDoublewordElement(24)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DC_CURRENT, new FloatDoublewordElement(26))), //


                new FC3ReadRegistersTask(28, Priority.LOW, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CHARGE_MAX_CURRENT_READ, new FloatDoublewordElement(28)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DISCHARGE_MAX_CURRENT_READ, new FloatDoublewordElement(30)) //

                ),


                new FC3ReadRegistersTask(300, Priority.LOW, //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CHARGE_MAX_CURRENT, new FloatDoublewordElement(306)), //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DISCHARGE_MAX_CURRENT, new FloatDoublewordElement(308)), //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DISCHARGE_MIN_VOLTAGE, new FloatDoublewordElement(310)), //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CHARGE_MAX_VOLTAGE, new FloatDoublewordElement(312)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_ACTIVE_POWER, new FloatDoublewordElement(300)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_REACTIVE_POWER, new FloatDoublewordElement(302)), //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_OFF_GRID_FREQUENCY, new FloatDoublewordElement(318)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.START_INVERTER, new UnsignedWordElement(304)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.STOP_INVERTER, new UnsignedWordElement(305)), //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CLEAR_FAILURE, new UnsignedWordElement(306)) //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_ON_GRID_MODE, new UnsignedWordElement(323)), //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_OFF_GRID_MODE, new UnsignedWordElement(324), INVERT_BOOLEAN) //
                ),


//                new FC16WriteRegistersTask(306, //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CHARGE_MAX_CURRENT, new SignedWordElement(306))),
//                new FC16WriteRegistersTask(308, //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DISCHARGE_MAX_CURRENT, new SignedWordElement(308))),
//                new FC16WriteRegistersTask(310, //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.DISCHARGE_MIN_VOLTAGE, new SignedWordElement(310))),
//                new FC16WriteRegistersTask(312, //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CHARGE_MAX_VOLTAGE, new SignedWordElement(312))),

                new FC16WriteRegistersTask(300, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_ACTIVE_POWER, new FloatDoublewordElement(300))),
                new FC16WriteRegistersTask(302, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_REACTIVE_POWER, new FloatDoublewordElement(302))),
//                new FC16WriteRegistersTask(318, //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_OFF_GRID_FREQUENCY, new SignedWordElement(318))),
                new FC16WriteRegistersTask(304, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.START_INVERTER, new UnsignedWordElement(304))),
                new FC16WriteRegistersTask(305, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.STOP_INVERTER, new UnsignedWordElement(305))),
                new FC16WriteRegistersTask(306, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.CLEAR_FAILURE, new UnsignedWordElement(306))),
                new FC16WriteRegistersTask(307, //
                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.HEART_BEAT, new UnsignedWordElement(307)))
//                new FC16WriteRegistersTask(323, //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_ON_GRID_MODE, new UnsignedWordElement(323))),
//                new FC16WriteRegistersTask(324, //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.SET_OFF_GRID_MODE, new UnsignedWordElement(324), INVERT_BOOLEAN)),
//                new FC16WriteRegistersTask(325, //
//                        m(BatteryInverterApsEnergiaBfi2z.ChannelId.OFF_GRID_BLACKSTART_MODE, new UnsignedWordElement(325)))
        ); //

    }

Hi Julian,

i guess it is about this Product:

Do you mind to join the OpenEMS Association if you use OpenEMS Commercially? :slight_smile:

My guess is, that your Inverter has a Connection Limit?

Greetings

Thanks for fast response. What kind of connection limit do you have in mind?
I can talk with my higher ups about association, I’m just a dev here :wink:

The Connection Limit of the Inverter.

Also you have defined:

m(BatteryInverterApsEnergiaBfi2z.ChannelId.FREQUENCY, new FloatDoublewordElement(12)),
m(BatteryInverterApsEnergiaBfi2z.ChannelId.FREQUENCY, new FloatDoublewordElement(12)),

2 times !

Basically this is not an OpenEMS Issue but an Device Communication Problem between the Device and OpenEMS. Without more Hardware Knowledge from the Device (which we need) it is not really possible to help further.

We all would appreciate it, if companies which use the OpenSource Software and make money out of it also Support it in some kind of way you know :wink:

Greetings

Thanks, you were right. The problem was with my modbus device, the map was incorrectly defined