I've created some custom Lua scripts on TRB140 which read measurements from different devices via Modbus and do some special processing before the data is sent to cloud. I'm using the custom register block as described here:
My custom regfile is located at /tmp/modbus/regfile
When the device is restarted, the regfile is removed (as expected). The problem is that if I create the regfile in my Lua script or shell script after restart, it does not work: The Modbus request test tool just throws the "Unexpected response length" error regardless of contents of the file. However, if I go to Modbus slave settings and change something (like register count) and save, the regfile is created by the system and it works again.
I've also tried different methods for creating the file, like taking a backup of a working regfile and copying to the desired location on device startup, but it still keeps throwing the same error. I've also set identical file permissions so it's not about them either. The only way to create a functioning regfile is by changing the settings and saving. I also tried to inspect how the file is actually created when saving the settings, but I haven't found anything so far.
The device is using firmware version TRB1_R_00.07.01