Diagnosis of gateway issues is complex. There are three sides to it, TCP, serial, and internal. From openHAB, you can only see TCP “not working” and cannot even tell which area to look more closely at.
You have a transient recoverable error, which is good news, but also means you won’t find a solid cause. You’l almost certainly have to resort to try-it-and-see.
Okay, that’s the general stuff. What’s most likely to go wrong?
The gateway has limited processing power divided amongst several tasks, and Modbus binding default settings can hammer it.
It is possible the gateway is just too busy to talk once in a while.
If you haven’t already applied it here, I would recommend reviewing the performance guide
paying attention to the TCP section - reduce your connect/disconnect overheads by settings in the Modbus binding.
It is however more likely to be serial side problems. If a serial transaction messes up, this gateway cannot tell you about it, and just fails the TCP transaction.
It would be nice to inspect the gateways serial error log … but I don’t think it keeps one.
Your settings for RS485 look reasonable, and I assume match the real slave device.
So, to the physical serial bus…
RS485 wiring bus should in theory be terminated with a 120R resistor at both ends.
In reality, you can “usually get away with” one for short wiring runs, or even none for very short. “Short” for RS485 is relative - a few metres is short, but I would do it properly once we get into tens of metres or more than two devices on bus.
This USR box includes a terminator resistor, I think it can be selected by internal link on the PCB , but is enabled from the factory. If in doubt, check with a meter between A and B (gateway powered off, disconnected from bus)
Likewise, a slave device may or may not have an onboard resistor, but these are generally disabled from factory. Again you can check with a meter.
RS485 lines need bias resistors as well - weak resistors that apply a voltage to the line representing a clean “idle” state. Almost all devices include these, certainly the USR box, and you shouldn’t need to worry about these unless something really weird goes on.
Much more worthy of attention is the wiring itself. You MUST use twisted pair cable. It’s not so critical what cable exactly at reasonable lengths, but cat5 is ideal.
Where the cable runs is important - while some proximity to power cables is unavoidable, long runs of RS485 cable parallel to mains power cables will almost certainly introduce noise and glitches.
If this is inescapable, you may need to use shielded (screened) twisted pair, although that is not often needed outside an industrial environment. The shielding should be connected to earth at only one end.
Earth loops can arise on RS485 buses. Grown up RS485 devices (the expensive industrial stuff) has isolated interfaces, but the kind of cheap stuff we use at home does not. This can cause a problem if this box’s “zero volts” is different to that box’s. This is unlikely to be your problem though - on the assumption that your gateway is powered from a wall-wart mini SMPSU or similar that should provide a “floating earth” for your gateway.