Python plugin: Modbus RTU / ASCII / TCP/IP Topic is solved

Python and python framework

Moderator: leecollings

Post Reply
bonebuster
Posts: 13
Joined: Saturday 25 November 2017 20:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by bonebuster »

Hi

Great job
works fine for me with Unitronics V350 PLC

i can read memory intger in TCP mode thanks !
is it possible to read multiple registers with only one command and have them in multiple custom sensors ?

or i have to read 1 register by command ?

thanks
JackWolfskind
Posts: 5
Joined: Wednesday 14 February 2018 9:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by JackWolfskind »

Unfortunately Domoticz doesn't start at all , after installation of the new true TCP plugin version. Maybe because I'm already on the Domo beta?
Will there be eventually a new plugin Version also supporting the latest Domo, then I can test reading and writing some TCP_modbus Devices :D
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

JackWolfskind wrote: Tuesday 06 March 2018 20:01 Unfortunately Domoticz doesn't start at all , after installation of the new true TCP plugin version. Maybe because I'm already on the Domo beta?
Will there be eventually a new plugin Version also supporting the latest Domo, then I can test reading and writing some TCP_modbus Devices :D
Bonebuster got it working with domoticz beta 3.8975

Have you installed pymodbusTCP correctly ?? (you also need the normal "serial" pymodbus)
Last edited by Domoticx on Tuesday 06 March 2018 20:50, edited 1 time in total.
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

bonebuster wrote: Tuesday 06 March 2018 7:06 Hi

Great job
works fine for me with Unitronics V350 PLC

i can read memory intger in TCP mode thanks !
is it possible to read multiple registers with only one command and have them in multiple custom sensors ?

or i have to read 1 register by command ?

thanks
1 register by command
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
JackWolfskind
Posts: 5
Joined: Wednesday 14 February 2018 9:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by JackWolfskind »

Strange, it doesn't work anymore for me after replacing the plugin.py with the new 1.1.0 Version, although the older version was ok :?

Before I got the old version working by following the installation manual:
Install for python 3.x with: sudo pip3 install -U six
copy the py file to v3.x python
sudo cp six.py /usr/lib/python3.5
Install for python 3.x with: sudo pip3 install -U pymodbus
Install for python 3.x with: sudo pip3 install -U pymodbusTCP
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

JackWolfskind wrote: Tuesday 06 March 2018 22:01 Strange, it doesn't work anymore for me after replacing the plugin.py with the new 1.1.0 Version, although the older version was ok :?

Before I got the old version working by following the installation manual:
Install for python 3.x with: sudo pip3 install -U six
copy the py file to v3.x python
sudo cp six.py /usr/lib/python3.5
Install for python 3.x with: sudo pip3 install -U pymodbus
Install for python 3.x with: sudo pip3 install -U pymodbusTCP
What does the LOG say?
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

Hi all,

Programmed some more hours on the plugin! :geek:

Released READ v1.1.1, notable changes:
- Can also decode STRING 2/4/6/8 bytes (not tested)
- Code cleanup, Fixed widths
- Added timeouts (5 sec)

Released WRITE v1.0.7, notable changes:
- TCP/IP support
- Code cleanup, Fixed widths
NOTE: RTU = HEX, TCP/IP = INT value
TODO: Option wich datatype to send (using stringbuilder)

Overall TODO: To cleanup plugin option space combine IP with port, like: 192.168.1.1:502 (and if only IP, port is 502 by default)

Updated readme, please read!

DL @ https://github.com/DomoticX/domoticz-modbus

Enjoy!
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
JackWolfskind
Posts: 5
Joined: Wednesday 14 February 2018 9:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by JackWolfskind »

Domoticx wrote: Tuesday 06 March 2018 22:51
JackWolfskind wrote: Tuesday 06 March 2018 22:01 Strange, it doesn't work anymore for me after replacing the plugin.py with the new 1.1.0 Version, although the older version was ok :?

Before I got the old version working by following the installation manual:
Install for python 3.x with: sudo pip3 install -U six
copy the py file to v3.x python
sudo cp six.py /usr/lib/python3.5
Install for python 3.x with: sudo pip3 install -U pymodbus
Install for python 3.x with: sudo pip3 install -U pymodbusTCP
What does the LOG say?
Unfortunately I couldn't find out where the log is. So far domoticz pretends to be running but I can't access the domoticz GUI via Browser, as soon as I install the new TCP Modbus. With the old one its running fine.
Unfortunately it's the same fault with V1.11...
Gonna have find out where Domo hides its logs....
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by McMelloW »

JackWolfskind wrote: Tuesday 06 March 2018 23:55 Unfortunately I couldn't find out where the log is. So far domoticz pretends to be running but I can't access the domoticz GUI via Browser, as soon as I install the new TCP Modbus. With the old one its running fine.
Unfortunately it's the same fault with V1.11...
Gonna have find out where Domo hides its logs....
I had the same kind of problem. Got on my Rpi with Putty or WinSCP and did the following steps
stopped domoticz with

Code: Select all

sudo service domoticz stop
Removed the /plugin/modbus-read and the /plugin/modbus-write folders.
Started domoticz again with

Code: Select all

sudo service domoticz start
In the browser, go to hardware and remove all the modbus hardware and look for log entries

Perhaps it is a quick and dirty trick, but it worked in my situation.
Greetings McMelloW
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

@JackWolfskind

New version also requires pymodbusTCP, have you installed it?

Also the plugin is for the stable version atm (not tested on beta)
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
bonebuster
Posts: 13
Joined: Saturday 25 November 2017 20:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by bonebuster »

@Domoticx

Hi write command works fine with Domoticz beta V3.8975 TCP/IP modbus fonction 6 to write 1 register in Unitronics PLC in MI memory

Many thanks !
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Jan Jansen »

@ Domoticx,

After a lot of trial and error I now can use function 6 (write single holding registor). Using the example as described on your website (http://domoticx.com/arduino-modbus-rs485-rtu-slave/), I learned to switch a LED on and off via modbus RS485. Thanks for stimulating my brain.

Jan
Last edited by Jan Jansen on Sunday 11 March 2018 7:52, edited 2 times in total.
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by McMelloW »

@ Domoticx

Tried it again with the 06-03-2018 update.
Installed the plugin dicrectorie from github in /home/pi/domoticz/plugins
Restarted Domoticz.
Add a Mobus Read for TCP/IP
As soon as I add the hardware domoticz hangs.
After removed the mudbus pligin directories and restarted Domomticz I received the following errors

Code: Select all

2018-03-08 16:43:05.691 Error: (Modbus) failed to load 'plugin.py', Python Path used was ':/usr/lib/python35.zip:/usr/lib/python3.5:/usr/lib/python3.5/plat-arm-linux-gnueabihf:/usr/lib/python3.5/lib-dynload'.
2018-03-08 16:43:05.699 Error: (ModbusTCP) Module Import failed, exception: 'ImportError'
2018-03-08 16:43:05.699 Error: (ModbusTCP) Module Import failed: ' Name: plugin'
2018-03-08 16:43:05.699 Error: (ModbusTCP) Error Line details not available.
2018-03-08 16:44:30.971 Error: ModbusTCP hardware (9) thread seems to have ended unexpectedly
2018-03-08 16:45:01.544 Error: ModbusTCP hardware (9) thread seems to have ended unexpectedly
2018-03-08 16:45:30.558 Error: ModbusTCP hardware (9) thread seems to have ended unexpectedly
The mesaages are different from the previous trial
Greetings McMelloW
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Jan Jansen »

@Mc Mellow,

Suddenly I could no longer reach Domoticz via the web interface. Today I read viewtopic.php?f=65&t=22339&start=20#p173424.

I followed the instructions and was able to reach Domoticz (Stretch, V3.8976) again. I also can use the write function again.
Last edited by Jan Jansen on Sunday 11 March 2018 11:39, edited 2 times in total.
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by McMelloW »

Jan Jansen wrote: Saturday 10 March 2018 19:38 @Mc Mellow,

Suddenly I could no longer reach Domoticz via the web interface. Today I read viewtopic.php?f=65&t=22339&start=20#p173424.

I followed the instructions and was able to reach Domoticz (V3.8976) again. I also can use the write function again.
@Jan Jansen.
Thanks for your support.

On my system this plugin is a total disaster.
After removing python3.5 the plugins did not show up in the hardware list.
Installing pymodbus pymodbusTCP with pip3 Python 3.5 was installed again. Aaaarghhh
After reboot Modbus plugins showed up in the hardware list.
Adding and activating a modbus-read hardware freese domoticz and has errors in retreiving devices.
Deleting the plugin modbus-xx directories bring Domoticz to live again.
This is not going to work for me.
This are the errors in the log

Code: Select all

2018-03-10 21:15:44.185 Error: (Modbus) failed to load 'plugin.py', Python Path used was ':/usr/lib/python35.zip:/usr/lib/python3.5:/usr/lib/python3.5/plat-arm-linux-gnueabihf:/usr/lib/python3.5/lib-dynload'.
2018-03-10 21:15:44.186 Error: (Modbus read test) Module Import failed, exception: 'ImportError'
2018-03-10 21:15:44.186 Error: (Modbus read test) Module Import failed: ' Name: plugin'
2018-03-10 21:15:44.186 Error: (Modbus read test) Error Line details not available.
2018-03-10 21:15:44.212 Error: (Rpi) 'onStart' failed 'KeyError'.
2018-03-10 21:15:44.212 Error: (Rpi) ----> Line 162 in /home/pi/domoticz/plugins/PiMonitor/plugin.py, function onStart
2018-03-10 21:15:44.212 Error: (Rpi) ----> Line 56 in /home/pi/domoticz/plugins/PiMonitor/plugin.py, function onStart
Greetings McMelloW
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Jan Jansen »

@Mc Mellow,

I am certainly not an expert, I learn from a lot of trial and error. Perhaps you know a lot more than me, but still. Before Domoticz broke, I had similar problems as you still have. I followed the instructions as described in the WIKI (Using Python plugins, Installing Python on Raspberry Pi with Raspbian). Maybe you have not seen that. At that moment those problems were over.
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

@McMelloW,

Seems like a possible python conflict on your raspbian somewhere :roll: , maybe because you are using a very old (jessie or first stretch) rasbian image? have you installed six (or maybe you can check)?

six was already installed on (latest) stretch but not on some jessie images, maybe you can update to the latest stretch mage? (don't know of there is export/import function in domoticz that could save time)
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
McMelloW
Posts: 434
Joined: Monday 20 November 2017 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.1
Location: Harderwijk, NL
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by McMelloW »

Domoticx wrote: Sunday 11 March 2018 13:41 @McMelloW,

Seems like a possible python conflict on your raspbian somewhere :roll: , maybe because you are using a very old (jessie or first stretch) rasbian image? have you installed six (or maybe you can check)?

six was already installed on (latest) stretch but not on some jessie images, maybe you can update to the latest stretch mage? (don't know of there is export/import function in domoticz that could save time)
Thanks for your reaction.
Two python plugins are running fine. PiMonitor and Disc-usage.
So I did compgen -c python and removed python3.5
After that no modbus plugins were in the hardware list.
I tried to install six but pip3 was gone.
Installing pip3 caused an automatic install of python3.5 again. Back to square 1

Code: Select all

compgen -c python  ==> shows now the following python installed

python3.5m
python3.4m
python
python2-config
python3m
python3
python2.7
python3.5
python2.7-config
python3.4
python-config
python2

lsb_release -a   ==> shows the following version.
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 9.3 (stretch)
Release:        9.3
Codename:       stretch


This is my current situation.
Greetings McMelloW
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

@McMelloW,

So.... have you installed six too?... after pip3 installed 3.5 again? (just to be sure)

My environment:

Code: Select all

compgen -c python

Code: Select all

python3.5m-config
python3.5m
python
python2-config
python3m
python3-config
python3
python2.7
python3.5
python3m-config
python3.5-config
python2.7-config
python-config
python2
-------------------------

Code: Select all

lsb_release -a

Code: Select all

No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 9.3 (stretch)
Release:        9.3
Codename:       stretch
-------------------------

Seems i don't have Python 3.4 installed, only Python 2.7 and 3.5 (and more -config listings)... :?

Maybe you can try to remove the 3.4 version (instead of 3.5) :?
Last edited by Domoticx on Monday 12 March 2018 6:47, edited 2 times in total.
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
User avatar
Domoticx
Posts: 90
Joined: Sunday 07 January 2018 21:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Marienheem / The Netherlands
Contact:

Re: [Released] Python plugin: Modbus RS485 RTU/ASCII/TCP

Post by Domoticx »

Updated OP!! with lots off goodies and links on Modbus to test stuff out! :ugeek: http://www.domoticz.com/forum/viewtopic ... 65&t=21297

You can even install modbus SLAVE on a ESP8266 Wireless!: http://domoticx.com/esp8266-wifi-modbus-tcp-ip-slave/
My Domoticz plugins:
- Modbus RS485 RTU/ASCII/TCP

Maatwerk in: Domotica - Automatisering - Elektronica - 3D printing - Software ontwikkeling
Website / Webshop / Knowledge Center / Facebook (like de pagina en blijf op de hoogte!)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest