How can I execute program on Mervis
I want to run my python program and receive results. How can I do this on Mervis?
short answer is you can't.
Slightly longer answer is you can, but I don't recommend it.
The Mervis is sort of world of its own and it's not easy to make it communicate with anything over other than supported protocols. If we need to use external scripts in our projects, we use simple python script which acts as a ModbusTCP slave running inside the PLC on 127.0.0.1:503. You can add this device in the Mervis and communicate with it via registers and coils. It works, but it requires some deal of work.
@martin-kudláček Thank you for the information. It sounds tough to implement. I finally figured out that if I keep running my application on PLC to collect data and passing result into variables that PLC can touch, it will work equivalent to my question above. Can I do this on Mervis ?
then I suggest you to take a look at PyModbus, especially the client example: https://pymodbus.readthedocs.io/en/latest/readme.html#example-code
On the side of the Mervis, you need to create Modbus Server, see: https://kb.unipi.technology/en:sw:01-mervis:setting-modbus-server-hidden
In the Mervis Modbus Server, you will define registers and coils pointing to some Mervis variables. In the Python script, you will write value to these registers/coils.
PyModbus worked great to me and I understand how to map variables on Mervis to be placed as modbus tcp touchable.
I Still have curious question. I configured 503 port as modbus server, because 502 is already used as another modbus. What is this modbus used for ?
tomkling last edited by
The port 502 is used for passing all data from and to the UniPi I/Os to EVOK, for example. The program that runs it is called unipitcp-server or similar and allows connection only from the UniPi itself. As far as I understand what you're using Mervis for, you could have also gotten the values directly from ModbusTCP on port 502 and then processed them in Python. This would have been probably a bit more difficult, because you would need to decode some values from Modbus' encoding and because you would need to know which register to use, but you can get this information from here: https://kb.unipi.technology/files:products:00-start
You need to choose your product line and download "Modbus Register map".
@tomkling Thank you for your information. I also figured out 502 is used on debugging. So it is important.