Logic Machine Forum
Script to control an Epson projector via RS-232 - Printable Version

+- Logic Machine 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: Script to control an Epson projector via RS-232 (/showthread.php?tid=129)



Script to control an Epson projector via RS-232 - managementboy - 08.11.2015

Today I created a small script in a KNX object to turn my Epson projector on off via a serial link. 

Code:
require('serial')
-- device on the LogicMachine connected to the Epson projector
-- ttyUSB0 is typical for a USB RS-232C
-- tested with adapter based on FT232 or CP210x chip.
device = '/dev/ttyUSB0'
-- opens a serial port using the sugested values of Epson manual
-- https://support.math.unipd.it/sites/default/files/epson_emp_835.pdf
port = serial.open(device, { baudrate = 9600, parity = 'none', stopbits = 1  })

-- get value of KNX object
value = event.getvalue()

if (value == true) then
 -- send power on command with returns to make them stick
 char = "PWR ON\r\n"  
 port:write(char)
else
 -- send power off command
 char = "PWR OFF\r\n"  
 port:write(char)
end

-- close port
port:close()