Autor Thema: Need help modbus specific  (Gelesen 144 mal)

Offline smarthacker

  • New Member
  • *
  • Beiträge: 18
Need help modbus specific
« am: 31 Januar 2019, 17:21:54 »
Moved the post from here,96588.0.html

Hi All,

I am building writing a custom module to read values from 2 different devices both device communicate over Modbus TCP.

But the problem is both devices have different IP and port I need to write them into one module since I need to achieve PID regulation between these two devices. I need to set values based on the value of the first device.
Here are my conf and module code.

My question is for the first device I want to read only "h40499"  and for the second device only "h1000" and "h1001".

But with the current config, I am getting the temperature, power and power meter values for both devices. I want to separate them.
Once I call the ModbusLD_Initialize it just takes the control to parent module.

can someone please help me with this.

I am following the guidelines from the following link

Additional info :-

I have one power device that gives me the realtime power consumption .
Other device has tempreture and power but based on other devices tempreture value I need to set values for 1st device.
I am not sure how to do it using conf itself and how to fetch current values in conf.
additional how to include the sub routine in conf itself. Hence decided to write everyting in module.
can some one help me with it

defmod powermeter ACT 1 1 TCP
define serial dummy
set serial 1438503

def powermeter1 ACT 1 1 TCP

package  main ;
use strict ;
use warnings ;
use Data::Dumper;

my %parseInfo = (
    "h40499"  =>  {
        reading => "powermeter",
        poll => 1,
        unpack => 'N',
        len => 2,
        expr => 'int($val - Value(\'serial\')'
    "h1000"  =>  {
        reading => "power",
        poll => 1,
    "h1001"  =>  {
        reading => "tempreture",
        poll => 1,
        expr => '$val/10',
        format => '%.1f'

sub ACT_Initialize ($)  {
    my ($modHash) = @_;

    LoadModule "Modbus";
    require "$attr{global}{modpath}/FHEM/";

    $modHash->{parseInfo}  = \%parseInfo;


sub ACT_Define ($$) {
    my  ( $hash,$def)  =  @_ ;
    print Dumper @_;