One USB to RS485 converter connected to my Mac (Amazon.com)
The other USB to RS485 converter connected to a USB port on the Pi
Bridge Modbus/RTU Serial is enabled on OpenEMS Edge
My custom Deye ESS device code is able to read and write to the ModbusServer Pro simulator on my Mac
The ModbusServer Pro simulator is able to send and receive values to and from the OpenEMS Edge on the Pi
In addition, I have a small snippet of Python code running on the Pi that is also able to read and write to the ModbusServer Pro simulator running on my Mac
Bridge Modbus/RTU Serial is enabled on OpenEMS Edge with similar settings as other Pi
Custom Deye ESS code is also enabled on this Pi
An error shows in the logs stating “Modbus Communication failed”
The same Python test snippet is able to communicate with the inverter over the same USB port
We’ve also tried other cables with not success
To recap, two different Pi’s running the same OpenEMS Edge code but only one of them can communicate properly via Modbus RTU.
I have tried using Wireshark but I am having issues getting it to work on Linux for some reason. I would be willing to try other tools to see if I can get more detailed information on the error.
So, my question is, are there other logs, code, tools, or methods I can look at to try and figure out why the second Pi is unsuccessful in communicating over Modbus serial?
import minimalmodbus # Don't forget to import the library!!
import time
mb_address = 1 # Modbus address of device
inverter = minimalmodbus.Instrument('/dev/ttyUSB0',mb_address) # Make an "instrument" object called sensy_boi (port n>
inverter.serial.baudrate = 9600 # BaudRate
inverter.serial.bytesize = 8 # Number of data bits to be requested
inverter.serial.parity = minimalmodbus.serial.PARITY_NONE # Parity Setting here is NONE but can be ODD or EVEN
inverter.serial.stopbits = 1 # Number of stop bits
inverter.serial.timeout = 0.5 # Timeout time in seconds
inverter.mode = minimalmodbus.MODE_RTU # Mode to be used (RTU or ascii mode)
# Good practice to clean up before and after each execution
inverter.clear_buffers_before_each_transaction = True
inverter.close_port_after_each_call = True
print(inverter) # Print out all the properties of the inverter
for i in range(700, 721):
multiData = inverter.read_registers(i, 1, 3)
myHex = hex(multiData[0])
print (f"{i}, '{myHex}', {multiData[0]}")
time.sleep(0.15)
# Piece of mind close out
inverter.serial.close()
The issue was in my code based on my incorrect assumptions from using a Chinese to English translated Modbus table document. Going to continue to test to be 100% sure, especially with writing to the registers. I’ll follow up with the outcome over the next few days.
Reading and writing to the Modbus registers working great now. I will continue with the process of implementing this inverter. Not sure where to allow a user to configure items such as Time of Use Selling settings (could be in the OpenEMS Edge Configuration area or maybe something to do with Apps).
I’m quite late to the show, answering on the initial post
There is a logVerbosity configuration parameter in both Modbus TCP and RTU bridges. This allows for very detailed logging of the read/write requests and actual bytes being sent:
public enum LogVerbosity {
/**
* Show no logs.
*/
NONE,
/**
* Show basic information in Controller.Debug.Log.
*/
DEBUG_LOG,
/**
* Show logs for all read and write requests.
*/
READS_AND_WRITES,
/**
* Show logs for all read and write requests, including actual hex values of
* request and response.
*/
READS_AND_WRITES_VERBOSE,
/**
* Show logs for all read and write requests, including actual duration time per
* request.
*/
READS_AND_WRITES_DURATION,
/**
* Show logs for all read and write requests, including actual duration time per
* request & trace the internal Event-based State-Machine.
*/
READS_AND_WRITES_DURATION_TRACE_EVENTS;
}