PDA

View Full Version : How To: Access serial device once it is defined?



Mark F
May 5th, 2006, 10:33 AM
I'm back. ;) I have been looking through the serial support for G4 and cannot find an answer to a question.

I have a HDMI switcher I am trying to control and the simple device code looks like this:


local device = serial.Classes.Simple:New({

Name = "GefenSwitch",
Description = "Gefen 4x2 HDMI Switcher",
GlobalName = "GefenSwitch",

BaudRate = 19200,
Parity = 0,
StopBits = 0,
DataBits = 8,
FlowControl = 'N',

OutputValues = { serial.hextobyte( "31" ), serial.hextobyte( "32" ), serial.hextobyte( "33" ), serial.hextobyte( "34" ) },

SelectInput = function (self, val)
if ((val > 0) and (val < 5)) then
gir.LogMessage (self.Name,'Input selection '..val,1)
self:Write (self.OutputValues [val])
else
gir.LogMessage (self.Name,'Invalid input selection '..val,1)
return nil,'Invalid input selection '..val
end
return true
end,
}
)

serial.AddDevice (device)


If I access this via the gloabl variable GefenSwitch I can get to the SelectInput method using this statement:
GefenSwitch:SelectInput(1)

If I remove the line:
GlobalName = "GefenSwitch",
the GefenSwitch global variable is no longer created (as expected) but the serial.devices.GefenSwitch variable doesn't have the SelectInput method defined.

My question (finally) is: What is the form of the LUA statement to call the SelectInput method on this device when it is NOT a global variable?

EDIT: I'm using G 4.0.4.2 (342) April 7, 2006

Rob H
May 5th, 2006, 01:50 PM
The devices field is the prototype for a serial device.

You can access the real device (assuming it has been bound to a comport) by using
serial.comports[portNum].device
Or, alternatively you can bind it to a comport dynamically in Lua using


serial.devices[deviceName].New(portNum)
where portNum = 1 means COM1 etc.

Mark F
May 5th, 2006, 02:13 PM
OK, thanks for the response. :)

Promixis
May 5th, 2006, 05:19 PM
Mark, great to see you back!

Mark F
May 5th, 2006, 05:55 PM
Maybe "back" is too strong of a term. I don't know how much I'll be hanging out here. :(

I am FINALLY automating my theater as I change the room color/furniture and needed an automation controller. I purchased a new silent PC (car-puter, actually) and am using it for theater automation, MP3 serving (SlimDevices Sqeezebox 3), MP3 playing (Softsqueeze) and anything else I may think up (pre-show trailers and trivia?). I know Girder is perfect for this even though I will have a bit of a learning curve going from G3 to G4. :D

The RS-232 devices are:
Gefen 4x2 HDMI switcher
Faroudja DVP-1080 HD Video Processor
Lexicon MC-8b Pre/Pro
Sim2 C3X 3-chip DLP projector

I also have a laser disc player, room lighting, HD cable box and Sony multi-disc DVD changer to automate via IR. Yuck!

I have the first two RS-232 devices written but need to debug them once I'm done re-painting the room. As I get devices sorted out, I'll upload the results for all to share.

Ron
May 5th, 2006, 07:15 PM
Hey Mark sounds like you have a fun project going on!