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.

Tulikivi sauna heater relay board
#2
Try this:
Code:
require('serial')
port, err = serial.open('/dev/RS485', {
  baudrate = 9600,
  databits = 8,
  stopbits = 1,
  parity = 'none',
  duplex = 'half'
})

function send(cmd, data)
  local msg, res, err, b1, b2

  data = data or 0

  msg = string.char(
    bit.band(cmd, 0xFF),
    bit.band(bit.rshift(data, 8), 0xFF),
    bit.band(data, 0xFF)
  )

  port:flush()
  port:write(msg)

  res, err = port:read(2, 3)
  if type(res) == 'string' then
    if #res == 2 then
      b1, b2 = res:byte(1, 2)
      return bit.bor(bit.lshift(b1, 8), b2)
    else
      return nil, 'invalid reply'
    end
  else
    return nil, err
  end
end

-- turn on
res, err = send(1, 1)
log(res, err)

-- turn off
res, err = send(1, 0)
log(res, err)

-- read current temperature
res, err = send(15)
log(res, err)
Reply


Messages In This Thread
RE: Tulikivi sauna heater relay board - by admin - 11.06.2021, 07:16

Forum Jump: