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
#61
(26.02.2024, 09:08)Daniel Wrote: This is how it meant to work. You need to convert it back to float on master device.
mb.setfloat16precision(2) sets how float16 is converted to integer. By default it's 2 decimals (0.01 precision). Change 2 to 0 to convert to integer without any decimals.

Hi! Yes, it works. Not a big problem to convert back to float on master device, but just to clarify. Is it possible to make pure float register (either it can be little or big endian)?
Reply
#62
float32 data type is handled as is without any conversion. The script can be modified to convert float16 to float32 instead of int16.

Edit: script has been updated with optional conversion of float16 to float32: https://kb.logicmachine.net/integration/...tcp-slave/
Reply
#63
How do i set up the script to use slave id 1 on the first RS-485 port and slave id 2 on the second RS-485 port on an LM5 Lite?
Reply
#64
Create two separate scripts, one for each port.
Reply
#65
I am Using Daikin Ac and Ac Guy Given me address and holding register ID. So query is that when I'm triggering from Logic Machine not getting response from AC. even i used json file.

Attached Files Thumbnail(s)
   
Reply
#66
This thread is for modbus slave and you are using master so if you have issues create dedicated topic for your case please.
------------------------------
Ctrl+F5
Reply
#67
Hi Sir,
When I am doing read test in Modbus in Logic Machine then it is showing me this number, what does it mean?
I have Attached Sceenshot

Attached Files Thumbnail(s)
       
Reply
#68
It is what the text says, result of the read request.
------------------------------
Ctrl+F5
Reply
#69
Thanks For Reply
sir I want to Know that how to understand this result and What it means
Reply
#70
Check the register description in the device documentation.
Reply
#71
We have 5 Zones in our project and each zone has an Automation DB having KNX Actuators and a KNX keypad.
So now we have to implement Auto/Manual logic in that way that if we press the button on KNX keypad the DB will go on the manual mode, it means now we are only able to control the DB devices (KNX Actuators) with keypad only and no command can be executed from the SCADA system until we remove the Manual mode by pressing the Auto mode key on the KNX keypad.
This Auto/Manual logic is to be implemented for all the 5 Zones.
Is it possible to make different resident script for different zone in MODBUS RTU so that we can disable the communication of particular zone by just disabling the resident script of that particular zone. We are using one LM5 as MODBUS RTU Slave for all 5 Zones.
Reply
#72
Multiple resident scripts can't share the same RS-485 port. It should be enough just to block writing as needed.

Replace the whole handlers.writeregister function with this, modify writeallowed logic as needed.
Code:
local function writeallowed(slaveid)
  if slaveid == 1 then
    return grp.getvalue('1/1/1')
  elseif slaveid == 2 then
    return grp.getvalue('1/1/2')
  end
end

handlers.writeregister = function(slaveid, fncode, data)
  if #data ~= 4 then
    return
  end

  local addr = touint16(data, 1)
  local map = getmapping(slaveid, fncode)

  if not map or not map[ addr ] then
    return excodes.illegaldataaddress
  end

  local mapobj = map[ addr ]

  if mapobj.len ~= 1 then
    return excodes.illegaldataaddress
  end

  if writeallowed(slaveid) then
    writevalue(mapobj, data, 3)
  end

  return data
end

Replace the whole handlers.writeregisters function with this.
Code:
handlers.writeregisters = function(slaveid, fncode, data)
  if #data < 5 then
    return
  end

  local addr = touint16(data, 1)
  local count = touint16(data, 3)
  local bytes = touint8(data, 5)

  if #data ~= (bytes + 5) then
    return
  end

  if count == 0 or count > limits.writeregisters or bytes ~= count * 2 then
    return excodes.illegaldataaddress
  end

  local map = getmapping(slaveid, fncode)

  if not map then
    return excodes.illegaldataaddress
  end

  if writeallowed(slaveid) then
    for i = 0, (count - 1) do
      local mapobj = map[ addr + i ]

      if mapobj and not mapobj.readonly then
        local offset = 6 + i * 2
        writevalue(mapobj, data, offset)
      end
    end
  end

  return data:sub(1, 4)
end
Reply
#73
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.
Reply


Forum Jump: