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.

Connector Bridge RS485 Interface
#1
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

Attached Files
.pdf   Connector_Bridge_RS485_Interface.pdf (Size: 288.66 KB / Downloads: 17)
Reply
#2
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)
Reply


Forum Jump: