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
#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


Messages In This Thread
RE: Connector Bridge RS485 Interface - by admin - 05.06.2024, 07:12

Forum Jump: