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 whether you accept or reject these cookies being set.

Sauna RS485 connection with LM
#1
Hi,
I want to send command for sauna control over RS485
   

Comand list



   




How need to look my command in LM?
Code:
require('serial')
port = serial.open('/dev/RS485-1', { baudrate = 57600, parity = 'none', duplex = 'half', databits = 8, stopbits = 1 })
port:flush()

log = port:write (info)
port:close()
Reply
#2
Code:
port:write('set sauna on\r')
port:write('set sauna val 70\r')
Reply
#3
This is correct that I done in resident  for reading:
Code:
require('serial')
port = serial.open('/dev/RS485-1', { baudrate = 57600, parity = 'none', duplex = 'half', databits = 8, stopbits = 1 })
port:flush()

grp.write('32/2/2', port:write(('get sauna val\r'), 'uint16'))

port:close()

   
Reply
#4
If you want to query status periodically then things get more complicated. You need to have a single resident script which will handle both reading and writing because you cannot have multiple scripts accessing serial port at the same time.

You also need to parse the response because the reply will contain some additional characters.
This should log raw response of temperature value.
Code:
function readack()
  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

port:write('get sauna val\r')
res, err = readack()
log(res, err)
Reply
#5
Ok connection is working maybe you know why I get not correct value?
   
Reply
#6
Evrithing is good its working code:

Code:
require('serial')
port = serial.open('/dev/RS485-1', { baudrate = 57600, parity = 'none', duplex = 'half', databits = 8, stopbits = 1 })
port:flush()


function readack()
 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

port:write('get sauna\r')
res, err = readack()
log(res, err)

port:close()
Reply


Forum Jump: