ich möchte folgende Module via pymodbus (Modbus RTU) ansteuern, d.h. Eingänge abfragen bzw. Ausgänge setzen:
MR-AI8 (https://www.metz-connect.com/de/products/11083213)
MR-AO4 (https://www.metz-connect.com/de/products/1108351302)
Als Server dient so etwas Ähnliches wie ein Raspberry, auf dem ein mit Yocto erstelltes Linux läuft (Python 2.7/3.5).
Vom Modbus (und leider auch von Python) hab ich nicht die große Ahnung und werde daher nicht so richtig schlau aus der Dokumentation über pymodbus. Ich habe von der pymodbus-Lib folgendes Server-Beispiel benutzt:
https://pymodbus.readthedocs.io/en/late ... erver.html
und lediglich die Kommunikationsparameter angepaßt (die ich auch an dem Modulen eingestellt habe):
Code: Alles auswählen
...
# RTU:
StartSerialServer(context,
framer=ModbusRtuFramer, identity=identity,
port='/dev/ttymxc2',
timeout=1,
baudrate=19200,
parity='E',
ignore_missing_slaves = True )
...
Code: Alles auswählen
2020-02-11 18:15:13,015 MainThread DEBUG sync :46 Client Connected [/dev/ttymxc2:/dev/ttymxc2]
2020-02-11 18:15:13,018 MainThread DEBUG sync :580 Started thread to serve client
Habe dann noch das "Callback Server Example" gefunden (https://pymodbus.readthedocs.io/en/late ... erver.html), allerdings fehlt meinem Python für diese Asynchronen Geschichten das "twisted". Beim Versuch der Installation des Twisted kommt folgende Fehlermeldung:
Code: Alles auswählen
...
return cmd.easy_install(req)
File "/usr/lib/python3.5/site-packages/setuptools/command/easy_install.py", line 666, in easy_install
raise DistutilsError(msg)
distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('incremental>=16.10.1')
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /var/volatile/tmp/pip-build-naq7k5t_/twisted/
Kennt sich von Euch jemand die pymodbus-Lib genauer und kann mich in die richtige Richtung schubsen?
Hab auch mal minimalmodbus ausprobiert, aber da kommt auch nichts zurück:
Code: Alles auswählen
import minimalmodbus
# instrument = minimalmodbus.Instrument('/dev/ttymxc2', 2, debug = True) # port name, slave address (in decimal), debug funktioniert wohl nicht
instrument = minimalmodbus.Instrument('/dev/ttymxc2', 2) # port name, slave address (in decimal)
print('war hier')
instrument.serial.port # this is the serial port name
instrument.serial.baudrate = 19200 # Baud
instrument.serial.bytesize = 8
#instrument.serial.parity = serial.PARITY_EVEN
instrument.serial.parity = minimalmodbus.serial.PARITY_EVEN
instrument.serial.stopbits = 1
instrument.serial.timeout = 1.0 # seconds
#instrument.address # this is the slave address number
instrument.mode = minimalmodbus.MODE_RTU # rtu or ascii mode
instrument.clear_buffers_before_each_transaction = True
## Read temperature (PV = ProcessValue) ##
temperature = instrument.read_register(10, 1) # Registernumber, number of decimals
print(temperature)
## Change temperature setpoint (SP) ##
#NEW_TEMPERATURE = 95
#instrument.write_register(24, NEW_TEMPERATURE, 1) # Registernumber, value, number of decimals for storage
Code: Alles auswählen
...
response = self._communicate(request, number_of_bytes_to_read)
File "/usr/lib/python3.5/site-packages/minimalmodbus.py", line 1406, in _communicate
raise NoResponseError("No communication with the instrument (no answer)")
minimalmodbus.NoResponseError: No communication with the instrument (no answer)
dd0815