Logic Machine Forum
Modbus script problem - Timeout - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Modbus script problem - Timeout (/showthread.php?tid=5577)



Modbus script problem - Timeout - fleeceable - 27.08.2024

Hi!

I'm facing some problems with modbus script over some time.
After some time (about week or two) communication goes to timeout (all reading/writing parameters). After I disable modbus script, enabling port on modbus tab, going to scan modbus devices on specific port (and system finds device with address), disable port on modbus tab, enable script again - everything starts to work again via script.

I attach code in here.
What can cause this?

Resident script with 10s sleep
Mitsubishi frequency converter
Code:
require('luamodbus')
vent_command = grp.getvalue('1/3/13')
reset_command = grp.getvalue('34/1/4')


control_motor = true
motor_on = vent_command

speed_value_perc = grp.getvalue('34/1/2')
hz_sp = math.floor(speed_value_perc*50)

mb = luamodbus.rtu()
mb:open('/dev/RS485-2', 19200, 'E', 8, 1)
mb:connect()
mb:setslave(5)


speed_read,err= mb:readregisters(202)
--log('Speed read22',speed_read,err)

read_mode,err= mb:readregisters(8)
--log('Read mode',read_mode,err)

read_speed,err= mb:readregisters(13)
log('Read speed',read_speed,err)



read_inputs,err= mb:readregisters(214)
--log('Read inputs',read_inputs,err)

read_alarm,err= mb:readregisters(500)
--log('Read alarms',read_alarm,err)


if control_motor then
  if motor_on then
    if read_mode ~= 75 then
      res,err = mb:writeregisters(8,2)
      --log('Write_motor_to_on',res,err)
    end

    if read_speed ~=hz_sp then
      res,err =mb:writeregisters(13,hz_sp)
      --log('Write_motor speed',res,err)
    end
  else
    if read_mode ~= 0 then
      res,err = mb:writeregisters(8,0)
      --log('Write motor off',res,err)
    end
  end
end

if reset_command then
  --log('Reseting frequency converter')
  log(mb:writeregisters(1,1))
  grp.checkupdate('34/1/4', 0)
end

mb:close()

if read_mode == 75 or read_mode == 67 then
  grp.update('34/1/3', read_speed/50)
elseif read_mode == 0 then
  grp.update('34/1/3', 0)
end

I have seen this kind of problem with some other devices as well (chiller cooling units and swegon ventilation unit).


RE: Modbus script problem - Timeout - Daniel - 27.08.2024

Try adding mb:flush() after setslave.
Why don't you use profile?


RE: Modbus script problem - Timeout - fleeceable - 29.08.2024

Thanks!
Gonna try that.

One reason is that I like coding and I usually have custom projects where modbus part is custom every time.
To create profile and test it is quite time consuming compared with coding.