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

Mark F
May 5th, 2006, 09: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])
gir.LogMessage (self.Name,'Invalid input selection '..val,1)
return nil,'Invalid input selection '..val
return true

serial.AddDevice (device)

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

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 (342) April 7, 2006

Rob H
May 5th, 2006, 12: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
Or, alternatively you can bind it to a comport dynamically in Lua using

where portNum = 1 means COM1 etc.

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

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

Mark F
May 5th, 2006, 04: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.

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