HDMI-CEC to USB EG Support for Pulse Eight

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
barnabas1969
Experienced User
Posts: 133
Joined: Sat Feb 04, 2012 1:42 am

Re: HDMI-CEC to USB EG Support for Pulse Eight

Post by barnabas1969 » Sun Aug 18, 2013 3:09 am

All of the functions are referenced in the "tester" application's source. It's actually not a terrible guide... but I would still like to give the original developers a "tongue lashing" for not writing good documentation for their API. It's very nice that they repeatedly say that they would like others to write software to interface with their hardware... but it's meaningless without documentation.

barnabas1969
Experienced User
Posts: 133
Joined: Sat Feb 04, 2012 1:42 am

Re: HDMI-CEC to USB EG Support for Pulse Eight

Post by barnabas1969 » Sun Aug 18, 2013 3:15 am

Walter (or someone who has experience writing plugins for EG), I need some help. I am stuck at the point where I try to load the DLL. I have read everything I can find on python.org and python.net regarding this subject, and nothing seems to help me.

I even went as far as to open the Python shell that is available in the "Help" menu in EventGhost, and tried to type some of the examples I found in the python.org and python.net documentation. In every scenario, the LoadLibrary function fails. Please see the attached file, which contains all the commands I tried typing into the Python shell (and the error messages I received as a result). Any and all help is greatly appreciated. In VB6/VBscript, this is easy to do. I don't understand why I'm having such a difficult time in Python.

Thanks in advance.
EventGhost-20130817-2303.py
(4.73 KiB) Downloaded 346 times

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: HDMI-CEC to USB EG Support for Pulse Eight

Post by krambriw » Sun Aug 18, 2013 3:35 pm

Hi, good you have found the python shell, it is very useful

When I try this simple test in the python shell just loading a standard windows dll it works fine for me, can you try it too?

Code: Select all

import ctypes
dll = ctypes.windll.LoadLibrary('filemgmt.dll')
dll._name
'filemgmt.dll'
Can you zip and post the 32 bit C++ dll here and I will try to load it

barnabas1969
Experienced User
Posts: 133
Joined: Sat Feb 04, 2012 1:42 am

Re: HDMI-CEC to USB EG Support for Pulse Eight

Post by barnabas1969 » Sun Aug 18, 2013 5:31 pm

Last night, I tried loading the C++ library and it worked. Then, after looking at the RCAware plugin, I decided to try using _ctypes in addition to ctypes. I don't understand the difference between the two, but here's what works:

Code: Select all

from ctypes import *
from _ctypes import LoadLibrary, FreeLibrary
dll = LoadLibrary("C:\Program Files (x86)\Pulse-Eight\USB-CEC Adapter\libcec.dll")
cec = CDLL("libcec.dll", RTLD_GLOBAL, handle=dll)
Now, I can call the functions using the cec object. I still haven't figured out how to pass the parameter to the CecInitialise function, which is required before calling the other functions. I can see, in the C++ source, that they are defining a new variable named g_config with a type of libcec_configuration. I assume that the type libcec_configuration comes from the DLL somehow.

If I can figure out (or if someone can help me) to create a variable in Python of type libcec_configuration, then I think I can go from there. In the C++ code, they are doing something like this:

Code: Select all

g_config.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
g_config.iHDMIPort = hdmiport;
And so-on.

The CEC_DEVICE_TYPE_RECORDING_DEVICE is a constant, and those are all defined in the source. It would be pretty easy to just copy/paste them into the Python script so that my constants are named the same as theirs and have the same values. The hdmiport variable was set from user input. There are several sub_values for g_config, and they are all listed in the source.

EDIT: I've attached both the C++ (libcec.dll) and the C# (LibCecSharp.dll) in a zip file.
USB-CEC Adapter.zip
(145.24 KiB) Downloaded 363 times

barnabas1969
Experienced User
Posts: 133
Joined: Sat Feb 04, 2012 1:42 am

Re: HDMI-CEC to USB EG Support for Pulse Eight

Post by barnabas1969 » Sun Aug 18, 2013 7:56 pm

OK, I think I get it now. From what I can tell, I need to define a new class named g_config (or whatever identifier I choose), and then define variables within it of different c-compatible types like this:

Code: Select all

class g_config:
    clientVersion = c_uint32
    bAutodetectAddress = c_uint8
Then, I can set the values like this:

Code: Select all

g_config.bAutodetectAddress = True
Of course, that depends on the data types in the C++ source. I **think** that the ones I've chosen above are correct for those two variables. Here's the struct section from cectypes.h where the libcec_configuration is defined:

Code: Select all

struct libcec_configuration
{
  uint32_t              clientVersion;        /*!< the version of the client that is connecting */
  char                  strDeviceName[13];    /*!< the device name to use on the CEC bus */
  cec_device_type_list  deviceTypes;          /*!< the device type(s) to use on the CEC bus for libCEC */
  uint8_t               bAutodetectAddress;   /*!< (read only) set to 1 by libCEC when the physical address was autodetected */
  uint16_t              iPhysicalAddress;     /*!< the physical address of the CEC adapter */
  cec_logical_address   baseDevice;           /*!< the logical address of the device to which the adapter is connected. only used when iPhysicalAddress = 0 or when the adapter doesn't support autodetection */
  uint8_t               iHDMIPort;            /*!< the HDMI port to which the adapter is connected. only used when iPhysicalAddress = 0 or when the adapter doesn't support autodetection */
  uint64_t              tvVendor;             /*!< override the vendor ID of the TV. leave this untouched to autodetect */
  cec_logical_addresses wakeDevices;          /*!< list of devices to wake when initialising libCEC or when calling PowerOnDevices() without any parameter. */
  cec_logical_addresses powerOffDevices;      /*!< list of devices to power off when calling StandbyDevices() without any parameter. */

  uint32_t              serverVersion;        /*!< the version number of the server. read-only */

  // player specific settings
  uint8_t               bGetSettingsFromROM;  /*!< true to get the settings from the ROM (if set, and a v2 ROM is present), false to use these settings. */
  uint8_t               bUseTVMenuLanguage;   /*!< use the menu language of the TV in the player application */
  uint8_t               bActivateSource;      /*!< make libCEC the active source on the bus when starting the player application */
  uint8_t               bPowerOffScreensaver; /*!< put devices in standby mode when activating the screensaver */
  uint8_t               bPowerOnScreensaver;  /*!< wake devices when deactivating the screensaver */
  uint8_t               bPowerOffOnStandby;   /*!< put this PC in standby mode when the TV is switched off. only used when bShutdownOnStandby = 0  */
  uint8_t               bSendInactiveSource;  /*!< send an 'inactive source' message when stopping the player. added in 1.5.1 */

  void *                callbackParam;        /*!< the object to pass along with a call of the callback methods. NULL to ignore */
  ICECCallbacks *       callbacks;            /*!< the callback methods to use. set this to NULL when not using callbacks */

  cec_logical_addresses logicalAddresses;     /*!< (read-only) the current logical addresses. added in 1.5.3 */
  uint16_t              iFirmwareVersion;     /*!< (read-only) the firmware version of the adapter. added in 1.6.0 */
  uint8_t               bPowerOffDevicesOnStandby; /*!< put devices in standby when the PC/player is put in standby. added in 1.6.0 */
  uint8_t               bShutdownOnStandby;   /*!< shutdown this PC when the TV is switched off. only used when bPowerOffOnStandby = 0. added in 1.6.0 */
  char                  strDeviceLanguage[3]; /*!< the menu language used by the client. 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/ added in 1.6.2 */
  uint32_t              iFirmwareBuildDate;   /*!< (read-only) the build date of the firmware, in seconds since epoch. if not available, this value will be set to 0. added in 1.6.2 */
  uint8_t               bMonitorOnly;         /*!< won't allocate a CCECClient when starting the connection when set (same as monitor mode). added in 1.6.3 */
  cec_version           cecVersion;           /*!< CEC spec version to use by libCEC. defaults to v1.4. added in 1.8.0 */
  cec_adapter_type      adapterType;          /*!< type of the CEC adapter that we're connected to. added in 1.8.2 */
  uint8_t               iDoubleTapTimeoutMs;  /*!< prevent double taps withing this timeout. defaults to 200ms. added in 2.0.0 */
  cec_user_control_code comboKey;             /*!< key code that initiates combo keys. defaults to CEC_USER_CONTROL_CODE_F1_BLUE. CEC_USER_CONTROL_CODE_UNKNOWN to disable. added in 2.0.5 */
  uint32_t              iComboKeyTimeoutMs;   /*!< timeout until the combo key is sent as normal keypress */

   libcec_configuration(void) { Clear(); }

  bool operator==(const libcec_configuration &other) const
  {
    return (     clientVersion             == other.clientVersion &&
        !strncmp(strDeviceName,               other.strDeviceName, 13) &&
                  deviceTypes               == other.deviceTypes &&
                  bAutodetectAddress        == other.bAutodetectAddress &&
                  iPhysicalAddress          == other.iPhysicalAddress &&
                  baseDevice                == other.baseDevice &&
                  iHDMIPort                 == other.iHDMIPort &&
                  tvVendor                  == other.tvVendor &&
                  wakeDevices               == other.wakeDevices &&
                  powerOffDevices           == other.powerOffDevices &&
                  serverVersion             == other.serverVersion &&
                  bGetSettingsFromROM       == other.bGetSettingsFromROM &&
                  bUseTVMenuLanguage        == other.bUseTVMenuLanguage &&
                  bActivateSource           == other.bActivateSource &&
                  bPowerOffScreensaver      == other.bPowerOffScreensaver &&
                  bPowerOffOnStandby        == other.bPowerOffOnStandby &&
                  bSendInactiveSource       == other.bSendInactiveSource &&
                  logicalAddresses          == other.logicalAddresses &&
                  iFirmwareVersion          == other.iFirmwareVersion &&
                  bPowerOffDevicesOnStandby == other.bPowerOffDevicesOnStandby &&
                  bShutdownOnStandby        == other.bShutdownOnStandby &&
        !strncmp(strDeviceLanguage,           other.strDeviceLanguage, 3) &&
                  iFirmwareBuildDate        == other.iFirmwareBuildDate &&
                  bMonitorOnly              == other.bMonitorOnly &&
                  cecVersion                == other.cecVersion &&
                  adapterType               == other.adapterType &&
                  iDoubleTapTimeoutMs       == other.iDoubleTapTimeoutMs &&
                  (other.clientVersion <= CEC_CLIENT_VERSION_2_0_4 || comboKey            == other.comboKey) &&
                  (other.clientVersion <= CEC_CLIENT_VERSION_2_0_4 || iComboKeyTimeoutMs  == other.iComboKeyTimeoutMs) &&
                  (other.clientVersion <  CEC_CLIENT_VERSION_2_1_0 || bPowerOnScreensaver == other.bPowerOnScreensaver));
  }

  bool operator!=(const libcec_configuration &other) const
  {
    return !(*this == other);
  }

barnabas1969
Experienced User
Posts: 133
Joined: Sat Feb 04, 2012 1:42 am

Re: HDMI-CEC to USB EG Support for Pulse Eight

Post by barnabas1969 » Sun Aug 18, 2013 11:34 pm

I'm stuck now. I've attached the __init__.py file below. Here's what the logger shows:

Code: Select all

19:30:55   Initializing P8 HDMI-CEC
19:30:57   Loading Pulse-Eight HDMI-CEC library
19:30:57   Attempting to initialize the device...
19:30:57   Error starting plugin: Pulse-Eight HDMI-CEC
19:30:57   Traceback (most recent call last) (1630):
19:30:57     File "C:\Program Files (x86)\EventGhost\eg\Classes\PluginInstanceInfo.py", line 177, in Start
19:30:57       self.instance.__start__(*self.args)
19:30:57     File "C:\Program Files (x86)\EventGhost\plugins\P8CEC\__init__.py", line 117, in __start__
19:30:57       mytest = self.cec.CECInitialise(g_config)
19:30:57   ArgumentError: argument 1: <type 'exceptions.TypeError'>: Don't know how to convert parameter 1
19:30:57   Plugin: Pulse-Eight HDMI-CEC
19:30:57      Loading Pulse-Eight HDMI-CEC library
19:30:57      Attempting to initialize the device...
19:30:57      Error starting plugin: Pulse-Eight HDMI-CEC
19:30:57      Traceback (most recent call last) (1630):
19:30:57        File "C:\Program Files (x86)\EventGhost\eg\Classes\PluginInstanceInfo.py", line 177, in Start
19:30:57          self.instance.__start__(*self.args)
19:30:57        File "C:\Program Files (x86)\EventGhost\plugins\P8CEC\__init__.py", line 117, in __start__
19:30:57          mytest = self.cec.CECInitialise(g_config)
19:30:57      ArgumentError: argument 1: <type 'exceptions.TypeError'>: Don't know how to convert parameter 1
It works fine until I try to call the CECInitialise function. I must have something wrong with my parameter. Here's the __init__.py file:
__init__.py
(9.55 KiB) Downloaded 344 times

barnabas1969
Experienced User
Posts: 133
Joined: Sat Feb 04, 2012 1:42 am

Re: HDMI-CEC to USB EG Support for Pulse Eight

Post by barnabas1969 » Sun Aug 18, 2013 11:37 pm

It is time for me to relax for the evening before going back to work tomorrow. I'm very disappointed that I didn't manage to get some basic functionality working tonight. I hope Walter or someone can point me in the right direction.

Good night.

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: HDMI-CEC to USB EG Support for Pulse Eight

Post by krambriw » Mon Aug 19, 2013 9:31 am

Hi, as you noticed, there is an argument error. We need to figure out how the argument has to look like (maybe you have an example from the C++ and/or C# code). As it looks like now, you are just passing a kind of declaration, no real data but I have no clue how it should look like.

If you look at the examples in the link below, some useful hints are in there (maybe you have to pass a Structure as argument)

http://eli.thegreenplace.net/2013/03/09 ... -and-cffi/

Also, since you obviously have the plugin for the other device, do they make a similar init there as well?

Best, Walter

barnabas1969
Experienced User
Posts: 133
Joined: Sat Feb 04, 2012 1:42 am

Re: HDMI-CEC to USB EG Support for Pulse Eight

Post by barnabas1969 » Mon Aug 19, 2013 2:17 pm

That's very useful information, Walter. Thanks. I don't know Python nor C++, so I'm really stabbing in the dark here.

The ctypes Structure seems to be exactly what I need, since the original C++ source defined it with a "struct" block.

The RCAware device's initialization is much simpler than the Pulse-Eight device's initialization.

There are default values defined in the C++ code for Pulse-Eight, and there is a function named Clear() that sets the parameters to default values. My next plan of attack was going to be to create a Clear() function in the EG plugin that sets the same values. But now that you've shown me the ctypes structure, I'll try changing my g_config class to use it in a way that is similar to the example you showed me.

I'll let you know how it goes.

Thanks again.

User avatar
Livin
Experienced User
Posts: 792
Joined: Wed Oct 08, 2008 4:56 am

Re: HDMI-CEC to USB EG Support for Pulse Eight

Post by Livin » Thu Sep 19, 2013 12:33 am

did you get a plugin built?
setup... XBMC, W7MC for DVR & Live OTA TV, JRMC for multi-zone audio, EG, MiCasaVerde Vera3, USB-UIRT IR receiver, Harmony remote, 5.2 home theater system

TheMiracle
Posts: 1
Joined: Wed Feb 26, 2014 11:27 am

Re: HDMI-CEC to USB EG Support for Pulse Eight (MEDIA BUTTON

Post by TheMiracle » Wed Feb 26, 2014 11:38 am

Hi Guys!
I bought two of this devices, hoping to get the same control over my pc as I did with my MCE Controller with no luck, Searching on the web, I stumble upon this thread, and now I have to wonder, and maybe there is something already done for what I want from this device, that it seems has lost every bit of support, (if it ever..) so this is just what I want:
I want to Send all the commands as they are, or at least be able to do it, In every Focused window I have.-
With the help of the examples in EG, I wan able to intercept the commands sent by my Remote over CEC Plugin, but I don't know how to send the Global play/Pause, FF, RWD, Etc, and I don't feel like using AutoHotkey to Automate the launch of an exe, to send the global play, so... is there a plugin? , where im able to send this media commands to windows, so I can customize it with the events of the CEC Plugin?

In a nutshell:

"Event: Play on Remote"
"Action: Play on PC"
"Event: FF on Remote"
"Action: FF on PC"
And so on and so forth

And with this, I will be able to pause and navigate in Netflix/Iheart Radio/Plex, Etc!
Thank you very much in advance!
Max.-

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: HDMI-CEC to USB EG Support for Pulse Eight

Post by krambriw » Wed Feb 26, 2014 2:32 pm

PLease check this thread

viewtopic.php?f=9&t=5907#p28785

barnabas1969
Experienced User
Posts: 133
Joined: Sat Feb 04, 2012 1:42 am

Re: HDMI-CEC to USB EG Support for Pulse Eight

Post by barnabas1969 » Wed Feb 26, 2014 3:08 pm

krambriw is correct that you should look at the other thread. Then, once you get that plugin working to get events in EG from the CEC device, then you will need to setup actions to send the commands to your apps.

There are plugins that send commands to various programs. For example, there is one for Windows Media Center (MCE), and one for Media Player Classic. I'm not sure if there's a plugin to send the Windows default play/pause/ffwd/rwd commands, but there may be one. You'll have to search for it. Also, if there are keyboard shortcuts which do the same things as those commands, you could always just send those keyboard keys.

RichardH
Posts: 32
Joined: Tue Dec 16, 2014 12:59 pm

Re: HDMI-CEC to USB EG Support for Pulse Eight

Post by RichardH » Mon Mar 09, 2015 11:16 am

Hi,
This is to announce that I have built a plugin that integrates libcec.dll into EventGhost. That was something that was in demand until a year or so ago, but this thread has gone quiet recently (perhaps since Kasinator's excellent testclient.exe-based plugin appeared). Is there still any interest in libcec.dll integration? (I don't want to just post the plugin to a dead thread!)

The plugin is based on a fairly direct translation of the libcec header file (version 2.2.0) into ctypes. It generates events from the libcec callbacks. The actions in the initial version are based on the testclient.exe interactive commands (same names, same functionality). (This choice of actions was mainly in order to have a more or less well-defined starting point.) There are extensive configuration options.

Anyone interested?

RichardH

User avatar
Livin
Experienced User
Posts: 792
Joined: Wed Oct 08, 2008 4:56 am

Re: HDMI-CEC to USB EG Support for Pulse Eight

Post by Livin » Mon Mar 09, 2015 4:03 pm

Richard... I'd try it out
setup... XBMC, W7MC for DVR & Live OTA TV, JRMC for multi-zone audio, EG, MiCasaVerde Vera3, USB-UIRT IR receiver, Harmony remote, 5.2 home theater system

Post Reply