Need help modbus specific

Begonnen von smarthacker, 31 Januar 2019, 17:21:54

Vorheriges Thema - Nächstes Thema

smarthacker

Moved the post from here
https://forum.fhem.de/index.php/topic,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
https://wiki.fhem.de/wiki/DevelopmentModuleIntro

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 192.168.101.1:502 TCP
define serial dummy
set serial 1438503

def powermeter1 ACT 1 1 192.168.101.1:503 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/DevIo.pm";

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

    ModbusLD_Initialize($modHash);
}

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

1;

strategy

Hey smarthacker,

to be honest I'm not an expert in Modbus and especially not in Modbus TCP.
But I do have an environment using Modbus RS485. I do have a single dongle attached to my FHEM system but two clients attached to the bus.
I'm using the module Modbus combined with two instances of the module ModbusAttr. Where Modbus handles the communication via my RS485 dongle and each ModbusAttr instance communicates with one of the attached devices.

Looking into the wiki (https://wiki.fhem.de/wiki/Modbus) Modbus TCP doesn't require the modbus module. Instead you can define 2 instances of the  ModbusAttr and assign the matching IP-addresses.

When you say you want to combine the data I would suggest to use custom logic in 99_myUtils.pm and a dummy.
This seems to be more supportable than building a custom module just for your specific use case.

Regards,
Matthias