-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
help needed on actual modbusRTU implementation #114
Comments
Hi, |
I have controller 3 metres away from the inverter. and 50-70% of transactions do get good response. I thought this means wiring is ok? Or what should I check regarding the wiring?
Can you elaborate this? Should I use Serial (now I have softwareSerial for that)? Any specific settings you would avise to try? Technical document of inverter specifies "Response timeout is 10 seconds.". This sounds to me like an exceptional setting, could that be a source of the problem that inverter may be "slow" in quite some cases and controller just timesout? |
Basing on you initial post I was suspecting some issue with RS485 transceiver. If most of transactions are ok that was wrong idea. void ModbusRTUTemplate::setBaudrate(uint32_t baud) {
_t = 4; // play with the value
} |
RS845 in my case, I have esp8266 with max485. I will try to replace the wire, adn will try to play with setBaudrate |
Dear Alexander, I would very much appreciate your further advice. I tested read and write operations with inverter with my windows10/usbRS485 adapter and qModbusMaster. I do not have with this config much of the access to configuration, but 9800 baud rate / 8N1 / no flow control / 1sec timeout gives me very rare timeouts (like 5%). on esp8266 I tried both Serial and softwareserial ports. #define MODBUSRTU_TIMEOUT 2000 Wiring I believe is not a problem, as other adapter on the same wiring works well. I would very much appreciate your advice how should find out the problem or what settings I should try to test. Thanks a lot. |
I tried with MODBUSrtU_DEBUG option, but not even sure where to start comprehending.
|
Can you provide complete code as it hard to say what is going wrong. As for lost packets. I suspect that you are using RS485 modules with auto RX/TX switching. With such modules a have in my lab I was unable to get baud rate above 9600 form ESP side. From other hand the same module was working at least at 115200. So I suggest to replace RS485 transceiver. |
I use max485 with rx/tx control pin. I tested several IC's, the resuls does not seem to differ. I will post the code. very much appreciate your help |
Dear @emelianov , this is my code:
|
Hello,
void readSlave(int16_t FIRST_REG, int16_t REG_COUNT) {
Serial.print("Read slave, Hreg: 0x");
Serial.println(FIRST_REG, HEX);
if (!mb_device.slave()) { // Check if no transaction in progress
mb_device.pullHreg(SLAVE_ID, FIRST_REG, FIRST_REG, REG_COUNT, cb);
while(mb_device.slave()) { // Check if transaction is active
mb_device.task();
mb.task(); // Should process incoming requests if long time response of timeout on mb_device happens
delay(10);
}
}
}
|
Hi @rzylius Do you have a terminator resistor (typically 120ohm)? Other thing that might be causing this is if there is a delay on the pins that control the direction of the transceiver. If there is to much capacitance on this pin there is the risk that it can be slow enough that when one of the sides starts transmitting it is still in the wrong mode. Again, the best thing to do is to measure the signals to be sure. |
Hi @DOSpt , thanks for the ideas. Indeed, I had max485 module connected directly without any resistors etc. Now I used https://www.anodas.lt/en/max485-ttl-to-rs485-converter-module module, which improved the error rate. I hoped that would kill all the problems you advised on - resistor, capacitance, etc. Still, I get about ~20-25% errors consistently. I will try to do measurements with oscilloscope. (well, and I guess I will come back with my measurements :) |
Prtobably because of SoftwareSerial. Serial data output formed by software is not so stable-in-time as hardware one.
It should not be a problem as according to Modbus specification remode must send responce with delay that long enough to eliminate electrical processes affects. |
Hi @rzylius @emelianov might be right on the software serial causing problems. Even if you are already using serial0 and serial2 there is an extra serial hardware module on the ESP32 that is a bit hidden that can be used (in the default pins it is unusable as by default it shares pins with the SPI Flash on the module). You can still use the serial1 (UART1) module for this. All pins in the ESP32 are remapable so this is not a problem. In order to use it just to the following:
|
@DOSpt , thanks for ideas. I tried to use Arduino MEGA (to have all the hw serials I need), but have no visible influence. I do receive error rate of ~30%. |
@rzylius you'd better use some kind of logical analizer as it'll show dataflow that is easier to analize. |
Dear @emelianov , sorry for the outside question. To prepare myself for recording transactions with logic analyzer, I set up my test case. I wanted to be sure that I can understand what I see (I did not find much of tuitorials on Modbus - logic analysis on youtube) :
Via MEGA serial port I see that mega successfully querries my windows slave device and receives right answers. But here are my screens from logic analyzer: Channel 3 is Modbus A connection, configures as modbus master There are two communication spikes, I gather this is request and response. Channel 3 (A) gives correct interpretation, it is reading holding registers starting with 0x1000. Now what supposed to be response: What is wrong here? As I worte earlier, actually MEGA receives correct response from the slave, so I expected to see slave response all right, so analyzer software is just misinterpreting what it reads? |
I'm not sure that correctly understanding analyser wiring. |
@emelianov , no, sorry I am getting to know what to measure. Will post updated screenshots, which makes more sense :) |
@rzylius Have you been able to read the metrics of the imeon? I own a 9.12 and want to read the modbus registers .... but I've not been able to find any docs about the registers meaning. Do you have? |
Hi, yes I do. It has "restricted distribution" written all over, so I guess I can not place it plainly on the web. IMEON provided it to me on request. By the way, reading is without any security, but if you want to write values, you will need unique key, which you can get only from IMEON. Drop me an email at [email protected] I can send the doc personally. And I we have one more friend with whom we discuss IMEON things, that will make three of us. Might make sense to make some kind of a group. |
Hi @rzylius, |
hi,
you will find modbusRTU and JSON documentation here:
https://github.com/orgs/imeon-community/discussions
alongside, we have here very small community of imeon adopters
https://github.com/orgs/imeon-community
regards,
rimantas
…On Wed, 17 May 2023 at 23:35, matze-sr ***@***.***> wrote:
Hi @rzylius <https://github.com/rzylius>,
I now own the imeon 9.12 as well. Can you provide me the docs too? Did you
opened a case at Imeon to get them? Can you tell me the wiring for the RJ45
modbus jacket on the Imeon? Is it Pin 1 -> A | Pin 2 -> B | Pin 8 -> GND
like it is for the Smartmeter? Thanks in advance!
—
Reply to this email directly, view it on GitHub
<#114 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAGJVV3NHLIFPBBPYRRHNTXGUY7ZANCNFSM4ZWWHXIA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hi, after some time I came back to the modbusRTU implementation. A reminder the HW I want to connect to: The IMEON RS485 port is configured to use the following
I got connected and all works pretty ok out of the box, but I consistently get 20-30% of timeouts. I tried to work with timeouts and as you advised, but no significant improvement. so I settled on the notions, that this is some IMEON fault. But now I built test code with different library, and it works with 1 error out of 9000 requests. As I myself have no deep technical knowledge, maybe this would provide hint into the peculiar problem I encounter: this is a code which works without problems: ` ModbusMaster node; const uint8_t slaveId = 1; // ModbusRTU Slave ID unsigned long lastRequestTime = 0; const unsigned long customTimeout = 2000; // Custom timeout in milliseconds void setup() { // Initialize ModbusRTU communication on Serial2 at 9600 baud, 8N1 Serial.println("[Setup] ModbusRTU Master initialized. Querying slave for registers..."); void loop() {
} |
one more thing, in ModbusMaster.h I changed timeout parameter to 10000 to reflect IMEON timeout of 10sec
|
Looking up d8:b0:4c:d1:86:4a you will find Jinan USR IOT Technology Co., Ltd. It's probably this product inside the Imeon 9.12: https://en.usr.cn/Industrial-Serial-RS485-to-Ethernet-modbus-rtu-Converter.html On the Webpage there is a table with an overview about portspeed etc. (Dunno, if that helps, though) |
Hi, I did some more testing. `#include <ModbusRTU.h> // Instantiate ModbusRTU object // Define Modbus parameters // Buffer to store register values // Timing variables unsigned long maxResponseTime = 0; // Timing for queries // Counters for successful and error reads // Flag to indicate if a query is pending // Callback function when a response is received if (event == Modbus::EX_SUCCESS) {
}
} // Update lastQueryTime and reset queryPending flag return true; void setup() { Serial2.begin(9600, SERIAL_8N1, 16, 17, 18, -1); // Initialize ModbusRTU object as Master // Wait a moment before starting communication void loop() { // Check if it's time to send a new query and no query is pending
} mb.task(); // Optionally, print maximum times and error statistics periodically
} Now success rate of reads is 78%, which is not bad. But what I observe (I use autoflow rs485-ttl module), that when timeout occurs, actually RX led blinks. that is IMEON responds, but module fails to read it? I have in callback a condition for exception - which never works, module just waits for timeout. |
Dear Alexander,
I have a solar inverter with quite a specification:
The IMEON RS485 port is configured to use the following
I got connected and all works pretty ok out of the box. But I quite often I receive error (not consistently)
I tried to play with #define MODBUSIP_TIMEOUT 1000 setting, without apparent improvement. maybe you may advise the logic how I should try to customize settings for it to work reliably?
Very much appreciate your work,
regards, Rimantas
The text was updated successfully, but these errors were encountered: