I’m writing a plugin for my Epson home cinema 1080UB projector. It is a serial communication device with a fairly simple command set. It works via a simple : returned from the projector stating that it’s ready for input. Commands are cr/lf terminated. The replies however seem to be only : terminated (from my hyperterm connection in to test). No matter what I try I never see any return commands from mi casa. I’ve tried the protocol as CR, CR/LF, and RAW.
Most recently I’ve tried with a RAW protocol, and tried on my startup to send the command to check the power status (“PWR?”, as part of the genericPoll function) and then do a read, however that does not appear to work (I get Luup error “Lua Engine Failed to Load”). If I use the incomming block, I get nothing ever returned.
Any ideas?
Here’s my implementation file.
[code]<?xml version="1.0"?>
raw
<functions>
local buffer = ""
local socket = require("socket")
local THISDEVICE
local mappingTable = {
["InputSelection1"] = {
["COMPONENT"] = "SOURCE 10",
["VGA"] = "SOURCE 20",
["HDMI1"] = "SOURCE 30",
["HDMI2"] = "SOURCE A0",
["VIDEO"] = "SOURCE 40",
},
["InputSelection2"] = {
["SOURCE=10"] = "COMPONENT",
["SOURCE=20"] = "VGA",
["SOURCE=30"] = "HDMI1",
["SOURCE=A0"] = "HDMI2",
["SOURCE=40"] = "VIDEO",
},
}
-- -------------------------------------------------------------------------
-- Perform the startup for the receiver (i.e. open the telnet port)
function doStartup(lul_device)
luup.log("Starting Epson Projector",1)
if( luup.io.is_connected(lul_device)==false ) then
luup.log('No port for ProjectorScreen',1)
luup.task('Choose the Serial Port for the Projector',2,'ProjectorScreen Interface',-1)
return false
end
genericPoll(lul_device, null)
end
function sendCode(code)
local cmd = code
luup.log("Epson Projector: " .. cmd .. string.char(13) .. string.char(10), 1)
if (luup.io.write(cmd .. string.char(13) .. string.char(10)) == false) then
luup.log("Cannot send command " .. code .. " communications error", 1)
luup.set_failure(true)
return false
end
return true
end
-- -------------------------------------------------------------------------
-- Perform the appropriate action based on the mapping table for this action
function doAction(deviceType, actionName)
local code = mappingTable[deviceType][actionName];
luup.log("Epson Projector action: " .. deviceType .. "-" .. actionName, 1)
-- Do we have a code?
if( code ~= "") then
sendCode(code)
else
luup.log("Unimplemented action: " .. deviceType .. "-" .. actionName, 1)
luup.set_failure(true)
return false
end
return true
end
function EpsonIncoming(data)
luup.log("Epson Projector data: " .. data, 1)
end
function toggleSwitch(lul_device, lul_settings)
luup.log("Epson Projector Power: " .. lul_settings.newTargetValue, 1)
if (lul_settings.newTargetValue=="1") then
sendCode("PWR ON")
else
sendCode("PWR OFF")
end
end
function doInputChange(lul_device, lul_settings)
doAction("InputSelection1",lul_settings.InputTarget)
end
function genericPoll(lul_device, lul_settings)
--sendCode("LAMP?")
--sendCode("SOURCE?")
luup.io.intercept
luup.io.write("PWR?" .. string.char(13) .. string.char(10))
luup.log("Epson Projector Raw Write: " .. "PWR?", 1)
luup.log("Epson Projector Recieving Data on : " .. lul_device, 1)
reply = luup.io.read(3, lul_device)
luup.log("Epson Projector data waiting", 1)
luup.log("Epson Projector data: " .. reply, 1)
end
</functions>
-- -------------------------------------------------------------------------
<incoming>
<lua>
EpsonIncoming(lul_data)
</lua>
</incoming>
<startup>doStartup</startup>
<actionList>
<action>
<serviceId>urn:micasaverde-com:serviceId:InputSelection1</serviceId>
<name>ToggleInput</name>
<run>
doInputChange(lul_device, lul_settings)
</run>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:SwitchPower1</serviceId>
<name>SetTarget</name>
<run>
toggleSwitch(lul_device, lul_settings)
</run>
</action>
<action>
<serviceId>urn:micasaverde-com:serviceId:HaDevice1</serviceId>
<name>Poll</name>
<run>
genericPoll(lul_device, lul_settings)
</run>
</action>
</actionList>
[/code]