Page 1 of 10 123 ... LastLast
Results 1 to 10 of 99

Thread: Anybody using Phidgets under Girder 4?

  1. #1
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,477

    Default Anybody using Phidgets under Girder 4?

    I have ordered a 0/16/16 board that will probably arrive Friday to control basically all of my HT and a few more things. Has anybody got working code to control Phidgets? The only mention I have seen in this forum was from May, so I don't know if that's relevant now.
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

  2. #2
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,551

    Default

    I have a grand total of one phidet and it works :-) Just remember the rules for comobjects.
    Ron
    No support through PM

  3. #3
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,477

    Default

    Ha-ha! Very funny! :evil: I haven't even got one line of code, I don't even know what to do beyond installing the library! ops: Of course with one example for inputs and one for outputs, I would be on my way... :wink:
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

  4. #4
    Join Date
    Aug 2002
    Location
    New York, NY
    Posts
    253

    Default

    I use the 0/0/4 phidgets relay with G4. Works perfectly. I had a long therad about it with mike early in the summer. I'll try and post my code when I get home.

  5. #5
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,477

    Default

    Thanks! I think it was your question I saw this May. I'm really looking forward to seeing what you have!
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

  6. #6
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,477

    Default

    You guys want me on my begging knees? OK, I am! Please, please, please! I'm getting my Phidget 0/16/16 in a few hours, and I would very much like an example of using input and output ports, so I have something to start with! Pleeeeeaaaasssseeeee.... :cry: (Pathetic enough for ya? :wink: )
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

  7. #7
    Join Date
    Dec 2001
    Posts
    11,560

    Default

    ok, this is some old g3.3 code but should work

    Code:
    
    function PhidgetManagerInitialize ()
      PM = luacom.CreateObject ("PHIDGET.PhidgetManager")
    
      if not PM then
        return nil, "Failed to open manager"
      end
    
    
      if not luacom.Connect (PM,PMEvents) then
        return nil, "Failed to connect event handler"
      end
    
      PDL = {} -- list of attached phidgets
    
      return 1
    end
    
    function PhidgetsManagerClose ()
      local x,y
      for x,y in PDL do
        PDL [x].device = nil
      end
      PM = nil
      collectgarbage ()
    end
    
    PMEvents = {}  -- list of manager events
    
    function PMEvents:OnAttach(Phidget)
      gir.TriggerEvent ("OSD", 18,"Attach",Phidget.DeviceType, Phidget.SerialNumber, Phidget.IsAttached)
      PhidgetAddDevice (Phidget.DeviceType, Phidget.SerialNumber)
    end
    
    function PMEvents:OnDetach(Phidget)
      gir.TriggerEvent ("OSD", 18,"Detach",Phidget.DeviceType, Phidget.SerialNumber, Phidget.IsAttached)
      PhidgetRemoveDevice (Phidget.DeviceType, Phidget.SerialNumber)
    end
    
    function PMEvents:OnError(Phidget, Description, SCODE)
      gir.TriggerEvent ("OSD", 18,"ERROR",Phidget.DeviceType, Phidget.SerialNumber, Description..SCODE)
    end
    
    
    function PhidgetAddDevice (Type,SerialNumber)
      PDL [SerialNumber] = {} -- new device, index table by sn
      PDL [SerialNumber].eh = {} -- eventhandler
      
      if Type == "PhidgetEncoder" then
        PDL [SerialNumber].device = luacom.CreateObject ("PHIDGET.PhidgetEncoder")
        if not PDL [SerialNumber].device then
          return nil, "Error adding device"
        end
        PDL [SerialNumber].device:Open (0)
        PDL [SerialNumber].eh.OnPositionChange = function (self,Index, Time , EncoderDisplacement) PEOnPositionChange (self.SerialNumber,Index, Time , EncoderDisplacement) end --
        PDL [SerialNumber].eh.OnInputChange = function (self,Index,NewState) PEOnInputChange (self.SerialNumber,Index,NewState) end
        PDL [SerialNumber].eh.SerialNumber = SerialNumber
    
        if not luacom.Connect( PDL [SerialNumber].device, PDL [SerialNumber].eh) then --link event handler
          return nil, "Error connecting event handler"
        end
        return SerialNumber
      end
    
      if Type == "PhidgetInterfaceKit" then
        PDL [SerialNumber].device = luacom.CreateObject ("PHIDGET.PhidgetInterfaceKit")
        if not PDL [SerialNumber].device then
          return nil, "Error adding device"
        end
        PDL [SerialNumber].device:Open (0)
        PDL [SerialNumber].eh.OnInputChange = function (self,Index,NewState) PIOnInputChange (self.SerialNumber,Index,NewState) end
        PDL [SerialNumber].eh.OnOutputChange = function (self,Index,NewState) PIOnOutputChange (self.SerialNumber,Index,NewState) end
        PDL [SerialNumber].eh.OnSensorChange = function (self,Index,SensorValue) PIOnSensorChange (self.SerialNumber,Index,SensorValue) end
        PDL [SerialNumber].eh.SerialNumber = SerialNumber
        if not luacom.Connect( PDL [SerialNumber].device, PDL [SerialNumber].eh) then --link event handler
          return nil, "Error connecting event handler"
        end
        return SerialNumber
      end
    
      return nil,"Unknown device: "..Type
    end
    
    function PhidgetRemoveDevice (Type,SerialNumber)
      PDL [SerialNumber].device = nil
      PDL [SerialNumber].eh = nil
      collectgarbage ()
    end
    
    
    
    --[[
    
    Encoder Events
    
    --]]
    
    
    function  PEOnPositionChange (SerialNumber,Index, Time , EncoderDisplacement)
     gir.TriggerEvent ("OSD", 18, "Encoder " .. Index.." Serial ".. SerialNumber,"Time "..Time,"Disp "..EncoderDisplacement,"Position "..PDL [SerialNumber].device:EncoderPosition (Index))
    end
    
    function PEOnInputChange(SerialNumber,Index, NewState)
      gir.TriggerEvent ("OSD", 18, "Encoder " .. Index.." Serial ".. SerialNumber, "State "..NewState)
    end
    
    --[[
    
    InterfaceKit Events
    
    --]]
    
    
    function PIOnInputChange(SerialNumber, NewState)
      gir.TriggerEvent ("OSD", 18, "Interface " .. Index, "State "..NewState)
    end
    
    function PIOnOutputChange(SerialNumber,Index, NewState)
      gir.TriggerEvent ("OSD", 18, "Interface " .. Index, "State "..NewState)
    end
    
    function PIOnSensorChange(SerialNumber,Index, SensorValue)
      gir.TriggerEvent ("OSD", 18, "Sensor " .. Index, "Value "..SensorValue)
    end
    
    function PrintDeviceList ()
      for x = 1, PM.Count do
        print (PM:Item (x).DeviceType)
      end
    end
    
    if PhidgetManagerInitialize() then
      print ("Phidget Manager Initialized")
     else
       print ("Error initializing Phidget Manager")
    end

  8. #8
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,477

    Default

    Thanks! Wow! Talk about a handfull! :roll: So this is the function part. Remember me and those spoons you sometimes will feed me with? You have one now? Is this the code to open port 0 on the interface kit?

    Code:
    PDL [SerialNumber].device:Open (0)
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

  9. #9
    Join Date
    Dec 2001
    Posts
    11,560

    Default

    you know what....

    this is much simpler....

    Code:
    PI = luacom.CreateObject ("PHIDGET.PhidgetInterfaceKit")
    PI:Open(0)
    
    print ("Phidget Interface ".. tostring (PI.IsAttached))
    print ("Serial ".. PI.SerialNumber)
    print ("Version ".. PI.DeviceVersion)
    print ("Inputs "..PI.NumInputs)
    print ("Outputs "..PI.NumOutputs)
    print ("Sensors "..PI.NumSensors)
    
    PIEvents = {}
    
    function PIEvents:OnDetach()
      TriggerEvent ("OSD", 18, "Detached")
    end
    
    function PIEvents:OnError(Description, SCODE)
      TriggerEvent ("OSD", 18, "Error",Description,SCODE)
    end
    
    function PIEvents:OnInputChange(Index, NewState)
      TriggerEvent ("OSD", 18, "Interface " .. Index, "State "..NewState)
    end
    
    function PIEvents:OnOutputChange(Index, NewState)
      TriggerEvent ("OSD", 18, "Interface " .. Index, "State "..NewState)
    end
    
    function PIEvents:OnSensorChange(Index, SensorValue)
      TriggerEvent ("OSD", 18, "Sensor " .. Index, "Value "..SensorValue)
    end
    
    luacom.Connect (PI,PIEvents)

  10. #10
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,477

    Default

    Thanks again! But simpler and simpler... At least it's a lot shorter! I assume that the inputs are easy, since I will probably see changes in them in the logger window. Or won't I? But the outputs, would control be like what I wrote above?
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

Page 1 of 10 123 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •