LogicMachine Forum
Read fire panel sensors current state - Printable Version

+- LogicMachine 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: Read fire panel sensors current state (/showthread.php?tid=4526)



Read fire panel sensors current state - Chmo - 23.01.2023

Hi. I have a fire panel and want to read the state of each sensor by RS232. I´m new at LUA but made some things like this:

-- Include library before calling serial functions
if not port then
require('serial')
-- Setting port parameters and open serial port
port = serial.open('/dev/RS232', {
baudrate = 19200,
databits = 8,
stopbits = 1,
parity = 'none',
duplex = 'full'
})
-- Flushes any read/unsent bytes
port:flush()

-- Read data from serial port
if port:read() == 'Powr___1'
-- Send alert when condition matched
then alert('Projector is ON')
end

-- Closing serial port
port:close()
end

¿How do I enter this contact ID event for reading the current state of the sensor in LUA command. Attached is the contact ID events codes.

-- Read data from serial port
port:read() == 'Powr___1' 
end

¿Is there a "Hello world" command to see if the communication is established between LM and Fire panel?


Thanks for your help


RE: Read fire panel sensors current state - admin - 24.01.2023

Do you have documentation for the serial protocol?


RE: Read fire panel sensors current state - Chmo - 24.01.2023

(24.01.2023, 07:12)admin Wrote: Do you have documentation for the serial protocol?

Just this.


RE: Read fire panel sensors current state - admin - 25.01.2023

Try running this script and see if you get anything in the Logs tab. Check that the panel is configured to send events to RS232.
Code:
if not port then   port = require('serial').open('/dev/RS232', {     baudrate = 19200,   })   buf = {}   function logbuf()     local txt = table.concat(buf)     log(txt)     buf = {}   end end char, err = port:read(1, 1) if char then   if char == '\r' or char == '\n' then     if #buf > 0 then       logbuf()     end   else     buf[ #buf + 1 ] = char     if #buf == 100 then       logbuf()     end   end end