Logic Machine Forum
Connector Bridge RS485 Interface - 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: Connector Bridge RS485 Interface (/showthread.php?tid=5450)



Connector Bridge RS485 Interface - TomasIha - 04.06.2024

Hello, I have a Connector Bridge RS485 Interface device. Can you send the script how to send such commands through modbus.

I am trying the common function:

function blind(command)
require('serial')
port = serial.open('/dev/RS485-1', { baudrate = 9600, parity = 'none', databits = 8, stopbits = 1 })
port:flush()
port:write(command)
port:close()
end


Example event script:
]
blind('!000V?;')


I am attaching the command of the device

Thank you


RE: Connector Bridge RS485 Interface - admin - 05.06.2024

Use this script to send a command and receive a reply from the bridge. Make sure that only a single script instance is running at any time. Serial port cannot be shared between multiple concurrent scripts.

Code:
require('serial')

port = serial.open('/dev/RS485-1', { baudrate = 9600 })

function readreply()
  local line = {}

  while true do
    local char, err = port:read(1, 5)

    if char == nil then
      return nil, err
    elseif char == ';' then
      break
    else
      line[ #line + 1 ] = char
    end
  end

  return table.concat(line)
end

command = '!000V?;'
port:write(command)

res, err = readreply()
log(res, err)