Page 1 of 1

New Plugin: USB IR Remote Receiver

Posted: Sat May 08, 2010 8:36 am
by Portisch
Hi,

I have created a new universal multiprotocol USB IR receiver:
http://www.mikrocontroller.net/articles ... e_Receiver

The topic is in german but the download includes an english description.

Now I'm trying to write my first EventGhost plugin:

Code: Select all

"""<rst>
EventGhost Plugin for the `USB IR Remote Receiver`__.

__ http://www.mikrocontroller.net/articles/USB_IR_Remote_Receiver
"""
import eg

eg.RegisterPlugin(
    name = "USB IR Remote Receiver",
    author = "Portisch",
    version = "0.0.1",
    kind = "remote",
    description = __doc__
)

import ctypes
import os
from ctypes import *

class USBIRRemoteReceiver(eg.PluginBase):

    def ReceivedIRCode(self, Protocol, Address, Command, Flags):
        #print "Received Protocol: " + Protocol
        #print "Received Address: " + Address
        #print "Received Command: " + Command
        #print "Received Flags: " + Flags
        self.TriggerEvent("Protocol: " + Protocol + ", Address: 0x" + Address + ", Command: 0x" + Command)

    def __init__(self):
        print ("USBIRRemoteReceiver: Plugin gets loaded.")
        print ("USBIRRemoteReceiver: Actual path: " + os.path.dirname(os.path.abspath(__file__)))
        try:
            print ("USBIRRemoteReceiver: Try to load ''USB_IR_Remote_Receiver.dll''")
            self.dll = ctypes.windll.LoadLibrary(os.path.dirname(os.path.abspath(__file__)) + ("\USB_IR_Remote_Receiver.dll"))
            print ("USBIRRemoteReceiver: USB_IR_Remote_Receiver.dll found and loaded!")
            self.dll.PluginName.restype = c_char_p
            print ("USBIRRemoteReceiver: DLL Plugin Name: " + self.dll.PluginName())            
            self.dll.Version.restype = c_char_p
            print ("USBIRRemoteReceiver: DLL Plugin Version: " + self.dll.Version())
            self.dll.Copyright.restype = c_char_p
            print ("USBIRRemoteReceiver: DLL Plugin Copyright: " + self.dll.Copyright())
            self.dll.Initialized = False
        except:
            raise self.Exceptions.FileNotFound            
        print ("USBIRRemoteReceiver: Init of USB IR Remote Receiver finished!")

    def __start__(self, myString):
        #print ("USB IR Remote Receiver is started")
        # funtion prototype
        prototype = WINFUNCTYPE(None, c_char_p, c_char_p, c_char_p, c_char_p)
        # create callback function            
        self.MyIRCallback = prototype(self.ReceivedIRCode)        
        self.dll.InitPAnsiChar(self.MyIRCallback)
        self.dll.Initialized = True
        print ("USBIRRemoteReceiver: DLL got initialized")

    def __stop__(self):
        #print ("USB IR Remote Receiver is stopped.")
        self.dll.InitPAnsiChar(None)

    def __close__(self):
        ctypes.windll.kernel32.CloseHandle(self.dll._handle)
        print ("USBIRRemoteReceiver: USB_IR_Remote_Receiver.DLL is unloaded!")        
        #print ("USB IR Remote Receiver is closed.")

    def Configure(self, myString=""):        
        panel = eg.ConfigPanel()     
        ShowSettingsButton = wx.Button(panel, id=-1, label='Show Settings/Option Dialog\n\n(This Dialog can only be shown if the plugin got initialized!)', pos=(8, 8), size=(175, 28))
        ShowSettingsButton.Bind(wx.EVT_BUTTON, self.ShowSettingsButtonClick)
        if self.dll.Initialized:
            print ("USBIRRemoteReceiver: Trying to show Settings/Options dialog")
            ShowSettingsButton.Enable()
        else:
            print ("USBIRRemoteReceiver: DLL is not initialized, can't show dialog")
            ShowSettingsButton.Disable()
        panel.sizer.Add(ShowSettingsButton, 1, wx.EXPAND)           
        while panel.Affirmed():
            panel.SetResult("")

    def ShowSettingsButtonClick(self,event):
        try:
            self.dll.ShowSettings.restype = None
            self.dll.ShowSettings(eg.app.hwnd)       
        except:
            print ("USBIRRemoteReceiver: Error showing Settings/Options dialog")
Now I have the problem, that I need the Configure function to show the DLL-Settings/Options dialog.
Is there a more simple way to show the dialog without the panel when I click with the right mouse on the Plugin -> Configure?

Also I can't remove the def __start__(self, myString):,
than I will get the error too many arguments.

Please help tp finish my EventGhost plugin.
The EventGhost plugin can be tested without hardware. Just copy the "USB_IR_Remote_Receiver.dll" in the same folder where the script is located.

Thx!

Re: New Plugin: USB IR Remote Receiver

Posted: Sat May 08, 2010 8:44 am
by Bartman
AFAIK the panel always show.

You get the too many arguments error because you set an empty string as the result and this string gets passed to the start method.
look at the timer plugin to circumvent this.

Re: New Plugin: USB IR Remote Receiver

Posted: Sun May 09, 2010 6:16 pm
by Portisch
Thx for your help!

I finished now the plugin:
Image

Project: USB IR Remote Receiver (German, English description is included in the download of the project)

The plugin is attached, I don't know if this would be added to EventGhost!?

Portisch

Re: New Plugin: USB IR Remote Receiver

Posted: Wed Jun 08, 2011 11:14 am
by brand10
Hello Portisch,

I am very interested in your USB IR Receiver project. Is it possible to get a ready built up receiver? I could build it by myself, but i dont have a programmer for the microcontroller :( Im from Germany.

Best Regards