sdm_modbus
sdm_modbus copied to clipboard
RASPBERRY PI 4 using Python last version don't work
I did a fresh installation of my Raspberry pi 4, with Debian. I wrote the program in Python and I can't get a connection.
ONLY VERSION 0.4.3 WORK. CAN YOU SOLVE ?
i'm using a USB TO RS485 converter.
import sdm_modbus device = sdm_modbus.SDM230(device="/dev/serial0", baud=9600) print(device)
if device.connected(): print("Working") else: print("NOT Working")
Regards George
Does one of the example scripts work? What output do you get? Have you tried reading any values or are you just getting an unexpected value on connected()?
The example don't get connection. But if I install version 0.4.3 it does work.
Regards
Obter o BlueMail para Android
Em 9/06/2022, 20:32, em 20:32, niels @.***> escreveu:
Does one of the example scripts work? What output do you get? Have you tried reading any values or are you just getting an unexpected value on
connected()?-- Reply to this email directly or view it on GitHub: https://github.com/nmakel/sdm_modbus/issues/14#issuecomment-1151535689 You are receiving this because you authored the thread.
Message ID: @.***>
And the other two questions I asked?
The example script works, I get correct readings, but, only in version 0.4.3.
Last version don't get connection neither readings.
Obter o BlueMail para Android
Em 9/06/2022, 20:32, em 20:32, niels @.***> escreveu:
Does one of the example scripts work? What output do you get? Have you tried reading any values or are you just getting an unexpected value on
connected()?-- Reply to this email directly or view it on GitHub: https://github.com/nmakel/sdm_modbus/issues/14#issuecomment-1151535689 You are receiving this because you authored the thread.
Message ID: @.***>
Since 0.4.3 many many things have changed. Without more debugging output it will be difficult to narrow down what's wrong.
Can you check the pymodbus version that is installed? Can you try adding an explicit connect() call?
Could you also try running the test suite?
Pymodbus version:
@.***:~ $ pip install pymodbus Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Requirement already satisfied: pymodbus in ./.local/lib/python3.9/site-packages (2.5.3) Requirement already satisfied: pyserial>=3.4 in /usr/lib/python3/dist-packages (from pymodbus) (3.5b0) Requirement already satisfied: six>=1.15.0 in /usr/local/lib/python3.9/dist-packages (from pymodbus) (1.16.0)
No dia 09/06/2022, às 21:14, niels @.***> escreveu:
pymodbus
Before I start, thank you for all the hard work that you have put into this ad keeping it up to date and sorry for the long post :(
I can confirm that when I use sdm_modbus v0.5.2 and pymodbus v2.5.3 and I run the following code :
from gettext import install
import sdm_modbus
device = sdm_modbus.SDM630(device="/dev/ttyUSB0", stopbits=1, parity="N", baud=9600, timeout=1, retries=3, unit=1)
print(device)
if device.connected():
print("Working")
else:
print("NOT Working")
I get the following reply "NOT Working"

But as soon as I downgrade to sdm_modbus v0.4.3 and still use pymodbus v2.5.3 I get a "Working" response.

The main issue that I am currently experiencing on both SDM_Modbus versions is the below error when I add the below variable to example-rtu.py and change line 20 to meter = sdm_modbus.SDM630( instead of meter = sdm_modbus.SDM120( :
device = sdm_modbus.SDM630(device="/dev/ttyUSB0", stopbits=1, parity="N", baud=9600, timeout=1, unit=1)
and receive the response :
usage: test.py [-h] [--stopbits STOPBITS] [--parity {N,E,O}] [--baud BAUD] [--timeout TIMEOUT] [--unit UNIT] [--json] device
test.py: error: the following arguments are required: device

The full code :
#!/usr/bin/env python3
import argparse
import json
import sdm_modbus
device = sdm_modbus.SDM630(device="/dev/ttyUSB0", stopbits=1, parity="N", baud=9600, timeout=1, unit=1)
if __name__ == "__main__":
argparser = argparse.ArgumentParser()
argparser.add_argument('device', type=str, help="Modbus device")
argparser.add_argument("--stopbits", type=int, default=1, help="Stop bits")
argparser.add_argument("--parity", type=str, default="N", choices=["N", "E", "O"], help="Parity")
argparser.add_argument("--baud", type=int, default=9600, help="Baud rate")
argparser.add_argument("--timeout", type=int, default=1, help="Connection timeout")
argparser.add_argument("--unit", type=int, default=1, help="Modbus unit")
argparser.add_argument("--json", action="store_true", default=False, help="Output as JSON")
args = argparser.parse_args()
meter = sdm_modbus.SDM630(
device=args.device,
stopbits=args.stopbits,
parity=args.parity,
baud=args.baud,
timeout=args.timeout,
unit=args.unit
)
if args.json:
print(json.dumps(meter.read_all(scaling=True), indent=4))
else:
print(f"{meter}:")
print("\nInput Registers:")
for k, v in meter.read_all(sdm_modbus.registerType.INPUT).items():
address, length, rtype, dtype, vtype, label, fmt, batch, sf = meter.registers[k]
if type(fmt) is list or type(fmt) is dict:
print(f"\t{label}: {fmt[str(v)]}")
elif vtype is float:
print(f"\t{label}: {v:.2f}{fmt}")
else:
print(f"\t{label}: {v}{fmt}")
print("\nHolding Registers:")
for k, v in meter.read_all(sdm_modbus.registerType.HOLDING).items():
address, length, rtype, dtype, vtype, label, fmt, batch, sf = meter.registers[k]
if type(fmt) is list:
print(f"\t{label}: {fmt[v]}")
elif type(fmt) is dict:
print(f"\t{label}: {fmt[str(v)]}")
elif vtype is float:
print(f"\t{label}: {v:.2f}{fmt}")
else:
print(f"\t{label}: {v}{fmt}")
I am using the Eastrom SDM630 Modbus nd I have confirmed that the configuration on he meter matches that on the script.
Before I start, thank you for all the hard work that you have put into this ad keeping it up to date and sorry for the long post :(
Thanks, no worries, great that you included everything.
usage: test.py [-h] [--stopbits STOPBITS] [--parity {N,E,O}] [--baud BAUD] [--timeout TIMEOUT] [--unit UNIT] [--json] device test.py: error: the following arguments are required: device
This error simply means you haven't provided /dev/ttyUSB0 to the script as a command line argument. I see you've defined device at the beginning of the script, but this will be done later on using the provided arguments. Remove line 7, and then eun the script again with a device path as a positional argument.
As to the reason why the lastest version doesn't work in the example code you used, still no clue. Have you tried doing this on a normal PC?
Thank you @nmakel for the assist.
I can get all readings from my SDM630 now !!!!
My only issue is I am trying to get it to work on an ESP8266 on MicroPython and I am having allot of issues.
Will it work in MicroPython ?
I am using in raspberry pi only.
Obter o BlueMail para Android
Em 17/06/2022, 08:07, em 08:07, coenraadr @.***> escreveu:
Thank you @nmakel for the assist.
I can get all readings from my SDM630 now !!!!
My only issue is I am trying to get it to work on an ESP8266 on MicroPython and I am having allot of issues.
Will it work in MicroPython ?
-- Reply to this email directly or view it on GitHub: https://github.com/nmakel/sdm_modbus/issues/14#issuecomment-1158563806 You are receiving this because you authored the thread.
Message ID: @.***>
Will it work in MicroPython ?
No idea. Not tested. Besides possible performance issues on that SOC, you may have trouble with getting all of the required libraries working. By all means do let me know if you're succesful :+1:
Still not working on raspberry por with last os.
Can you please send me a Python script?
Obter o BlueMail para Android
Em 22/06/2022, 20:04, em 20:04, niels @.***> escreveu:
Will it work in MicroPython ?
No idea. Not tested. Besides possible performance issues on that SOC, you may have trouble with getting all of the required libraries working. By all means do let me know if you're succesful :+1:
-- Reply to this email directly or view it on GitHub: https://github.com/nmakel/sdm_modbus/issues/14#issuecomment-1163499051 You are receiving this because you authored the thread.
Message ID: @.***>
I have run the code on a raspberry.
Regards
Obter o BlueMail para Android
Em 11/06/2022, 19:58, em 19:58, niels @.***> escreveu:
Before I start, thank you for all the hard work that you have put into this ad keeping it up to date and sorry for the long post :(
Thanks, no worries, great that you included everything.
usage: test.py [-h] [--stopbits STOPBITS] [--parity {N,E,O}] [--baudBAUD] [--timeout TIMEOUT] [--unit UNIT] [--json] device
test.py: error: the following arguments are required: device
This error simply means you haven't provided
/dev/ttyUSB0to the script as a command line argument. I see you've defineddeviceat the beginning of the script, but this will be done later on using the provided arguments. Remove line 7, and then eun the script again with a device path as a positional argument.As to the reason why the lastest version doesn't work in the example code you used, still no clue. Have you tried doing this on a normal PC?
-- Reply to this email directly or view it on GitHub: https://github.com/nmakel/sdm_modbus/issues/14#issuecomment-1152981799 You are receiving this because you authored the thread.
Message ID: @.***>
It is well running on my fresh installation on a PI4B with 8GBram and the latest official Raspios 2022-09-22-raspios-bullseye-arm64.img.xz: $ uname -a Linux rpihaus 5.15.76-v8+ #1597 SMP PREEMPT Fri Nov 4 12:16:41 GMT 2022 aarch64 GNU/Linux $ python -V Python 3.9.2 $ pip3 -V pip 20.3.4 from /usr/lib/python3/dist-packages/pip (python 3.9) $ python ertu.py /dev/ttyUSB1 --stopbits 1 --parity N --baud 9600 --unit 1 SDM630(/dev/ttyUSB1, connectionType.RTU: stopbits=1, parity=N, baud=9600, timeout=1, retries=3, unit=0x1):
Input Registers: L1 Voltage: 222.81V L2 Voltage: 226.05V L3 Voltage: 222.93V L1 Current: 4.23A ...and lot more output lines.