1

I am using ModbusPal to create the Virtual modbus.

I am using the endpoint URI as:

plc4x:modbus-tcp://localhost:502?unitId=1&dataType=holding-register&addresses=1

Following is the screenshot of Modbus holding registers: enter image description here

But when starting camel context it throws NullPointerException.

java.lang.NullPointerException
    at org.apache.camel.component.plc4x.Plc4XConsumer.startUnTriggered(Plc4XConsumer.java:89)
    at org.apache.camel.component.plc4x.Plc4XConsumer.doStart(Plc4XConsumer.java:81)
    at org.apache.camel.support.service.BaseService.start(BaseService.java:119)

I debugged it and found the problem is with this line:

        for (Map.Entry<String, Object> tag : tags.entrySet()) {

Here tags is null, so basically I am not configuring the endpoint correctly.

How can I write the endpoint correctly?

Edit: Camel core version : 3.20.2 Camel-PLC4X version : 3.20.2

But when I am configuring the endpoint by creating an instance of Plc4XEndpoint and then configuring the tags there, it works like:

Map<String, Object> map = new HashMap<>();
            map.put("value-1", "holding-register:1");
            
            Plc4XEndpoint plc4xEndpoint = new Plc4XEndpoint("plc4x:modbus-tcp://localhost:502",
                    getContext().getComponent("plc4x"));
            plc4xEndpoint.setTags(map);
            from(plc4xEndpoint).log("value : ${body}");

But why it is not working if I configure the endpoint as just String?

mdanish98
  • 65
  • 8
  • What version of Camel do you use? And the NPE is something we should fix, at least give another exception explaining to the user if something must be configured. You are welcome to create a JIRA at ApacheCamel – Claus Ibsen Mar 25 '23 at 21:17
  • Camel core version : 3.20.2 Camel-PLC4X version : 3.20.2, actually I have tried using another endpoint configuration, like: plc4x:modbus-tcp://localhost:502?tags={unitId=1&dataType=holding-register&addresses=1} But still, the tags are null while debugging. Sure I will raise a ticket on Jira. – mdanish98 Mar 25 '23 at 23:11
  • Also it is working if I configure it by creating a new instance of Plc4xEndpoint and configuring the tags manually there like below: Map map = new HashMap<>(); map.put("value-1", "holding-register:1"); Plc4XEndpoint plc4xEndpoint = new Plc4XEndpoint("plc4x:modbus-tcp://localhost:502", getContext().getComponent("plc4x")); plc4xEndpoint.setTags(map); from(plc4xEndpoint).log("value : ${body}"); But why it is not working if I configure the endpoint as just String? – mdanish98 Mar 25 '23 at 23:17

0 Answers0