This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Universal Modbus TCP/RTU Slave
#74
(18.04.2025, 15:16)imprashant Wrote: Hi, I have done the changes in the mbslave (user library script). But still I didn't understand how will I disable one Zone to communicate with the SCADA  over modbus rtu. Do I need to make some changes in resident script as well. Please guide.

Previously the script I was using was working but sometimes I have to send command 2-3 times from Modscan in order to execute command in LM5. The script I was using:

local mb = require('user.mbslave')
local mbrtu = require('luamodbus').rtu()

mbrtu:open('/dev/RS485-1', 9600, 'N', 8, 1, 'H')
mbrtu:connect()
mbrtu:setslave('*') -- Accept multiple RTU slave IDs

mb.setswap('w')
mb.setfloat16precision(2)

local ga1 = '0/0/11' --zone 1 enable/disable
local ga2 = '0/0/12' --zone 2 enable/disable
local current_mapping = nil

-- Predefine mappings for easy reuse
local mapping1 = {
    [1] = {
        coils = {
            [0] = '0/0/1',
        },
        registers = {
            [0] = '0/0/2',
        }
    }
}

local mapping2 = {
    [1] = {
        coils = {
            [1] = '0/0/3',
        },
        registers = {
            [1] = '0/0/4',
        }
    }
}

while true do
    local val1 = grp.getvalue(ga1)
    local val2 = grp.getvalue(ga2)

    if not val1 and current_mapping ~= "mapping1" then
        mb.setmapping(mapping1)
        current_mapping = "mapping1"
        log("Applied Mapping 1")
    elseif not val2 and current_mapping ~= "mapping2" then
        mb.setmapping(mapping2)
        current_mapping = "mapping2"
        log("Applied Mapping 2")
    end

    mb.rtuhandler(mbrtu)
    os.sleep(1) -- small delay to prevent CPU hogging
end
Reply


Messages In This Thread
Universal Modbus TCP/RTU Slave - by Daniel - 07.10.2022, 12:55
RE: Universal Modbus TCP Slave - by palomino - 07.10.2022, 17:30
RE: Universal Modbus TCP Slave - by Daniel - 07.10.2022, 17:53
RE: Universal Modbus TCP Slave - by Daniel - 07.10.2022, 17:55
RE: Universal Modbus TCP Slave - by palomino - 10.10.2022, 13:39
RE: Universal Modbus TCP Slave - by Daniel - 10.10.2022, 13:44
RE: Universal Modbus TCP Slave - by palomino - 11.10.2022, 16:22
RE: Universal Modbus TCP Slave - by palomino - 23.02.2023, 12:44
RE: Universal Modbus TCP Slave - by admin - 23.02.2023, 12:47
RE: Universal Modbus TCP Slave - by palomino - 24.02.2023, 12:41
RE: Universal Modbus TCP Slave - by admin - 24.02.2023, 12:48
RE: Universal Modbus TCP Slave - by palomino - 27.02.2023, 13:02
RE: Universal Modbus TCP Slave - by Daniel - 27.02.2023, 13:10
RE: Universal Modbus TCP Slave - by palomino - 27.02.2023, 14:00
RE: Universal Modbus TCP Slave - by Daniel - 27.02.2023, 14:03
RE: Universal Modbus TCP Slave - by palomino - 28.02.2023, 02:32
RE: Universal Modbus TCP Slave - by admin - 28.02.2023, 07:02
RE: Universal Modbus TCP Slave - by Fahd - 06.03.2023, 14:11
RE: Universal Modbus TCP Slave - by Daniel - 06.03.2023, 14:35
RE: Universal Modbus TCP Slave - by Fahd - 06.03.2023, 14:50
RE: Universal Modbus TCP Slave - by Daniel - 06.03.2023, 14:55
RE: Universal Modbus TCP Slave - by Daniel - 06.03.2023, 15:16
RE: Universal Modbus TCP Slave - by Fahd - 07.03.2023, 07:59
RE: Universal Modbus TCP Slave - by rw_echo - 14.03.2023, 05:22
RE: Universal Modbus TCP Slave - by Daniel - 07.03.2023, 11:55
RE: Universal Modbus TCP Slave - by rw_echo - 07.03.2023, 12:32
RE: Universal Modbus TCP Slave - by Daniel - 07.03.2023, 12:34
RE: Universal Modbus TCP Slave - by rw_echo - 07.03.2023, 12:49
RE: Universal Modbus TCP Slave - by Daniel - 07.03.2023, 12:59
RE: Universal Modbus TCP Slave - by David - 13.03.2023, 15:40
RE: Universal Modbus TCP Slave - by admin - 13.03.2023, 15:42
RE: Universal Modbus TCP Slave - by David - 13.03.2023, 15:58
RE: Universal Modbus TCP Slave - by Daniel - 13.03.2023, 16:00
RE: Universal Modbus TCP Slave - by David - 13.03.2023, 16:07
RE: Universal Modbus TCP Slave - by Daniel - 13.03.2023, 16:15
RE: Universal Modbus TCP Slave - by David - 13.03.2023, 16:32
RE: Universal Modbus TCP Slave - by Daniel - 13.03.2023, 16:41
RE: Universal Modbus TCP Slave - by admin - 13.03.2023, 16:45
RE: Universal Modbus TCP Slave - by David - 13.03.2023, 19:31
RE: Universal Modbus TCP Slave - by admin - 14.03.2023, 06:18
RE: Universal Modbus TCP Slave - by rw_echo - 14.03.2023, 07:39
RE: Universal Modbus TCP Slave - by Fahd - 14.03.2023, 08:27
RE: Universal Modbus TCP Slave - by admin - 14.03.2023, 08:15
RE: Universal Modbus TCP Slave - by rw_echo - 14.03.2023, 08:35
RE: Universal Modbus TCP Slave - by admin - 14.03.2023, 08:35
RE: Universal Modbus TCP/RTU Slave - by admin - 06.06.2023, 15:34
RE: Universal Modbus TCP/RTU Slave - by admin - 12.06.2023, 08:59
RE: Universal Modbus TCP/RTU Slave - by admin - 28.03.2024, 08:26
RE: Universal Modbus TCP/RTU Slave - by admin - 12.06.2024, 05:26
RE: Universal Modbus RTU - by Ranjeet - 14.06.2024, 07:24
RE: Universal Modbus TCP/RTU Slave - by admin - 12.07.2024, 07:14
RE: Universal Modbus TCP/RTU Slave - by admin - 16.04.2025, 07:06
RE: Universal Modbus TCP/RTU Slave - by imprashant - 21.04.2025, 09:54
RE: Universal Modbus TCP/RTU Slave - by admin - 22.04.2025, 05:32
RE: Universal Modbus TCP/RTU Slave - by admin - 22.04.2025, 09:01

Forum Jump: