Table of Contents

Class LibCecSharp

Namespace
CecSharp
Assembly
LibCecSharp.dll

Create a LibCecSharp instance and pass the configuration as argument. Then call Open() to open a connection to the adapter. Close() closes the connection.

libCEC can send commands to other devices on the CEC bus via the methods on this class, and all commands that libCEC receives are sent back to the application via the callback methods on CecCallbackMethods.

This is the pure-C# implementation that binds the native C API (include/cecc.h) over P/Invoke, so it runs on every platform the native library loads on. It replaces the Windows-only C++/CLI wrapper.

public class LibCecSharp : IDisposable
Inheritance
LibCecSharp
Implements
Inherited Members

Constructors

LibCecSharp(CecCallbackMethods, LibCECConfiguration)

Create a new LibCecSharp instance.

public LibCecSharp(CecCallbackMethods callbacks, LibCECConfiguration config)

Parameters

callbacks CecCallbackMethods
config LibCECConfiguration

Methods

CanSaveConfiguration()

Check whether the CEC adapter can save a configuration.

public bool CanSaveConfiguration()

Returns

bool

Close()

Close the connection to the CEC adapter.

public void Close()

DisableCallbacks()

public void DisableCallbacks()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

EnableCallbacks()

public void EnableCallbacks()

~LibCecSharp()

protected ~LibCecSharp()

FindAdapters(string)

Try to find all connected CEC adapters.

public CecAdapter[] FindAdapters(string path)

Parameters

path string

Returns

CecAdapter[]

GetActiveDevices()

Get the logical addresses of the devices that are active on the bus.

public CecLogicalAddresses GetActiveDevices()

Returns

CecLogicalAddresses

GetActiveSource()

Get the logical address of the device that is currently the active source.

public CecLogicalAddress GetActiveSource()

Returns

CecLogicalAddress

GetAdapterProductId()

Get the (virtual) USB product id.

public ushort GetAdapterProductId()

Returns

ushort

GetAdapterVendorId()

Get the (virtual) USB vendor id.

public ushort GetAdapterVendorId()

Returns

ushort

GetCurrentConfiguration(LibCECConfiguration)

Get libCEC's current configuration.

public bool GetCurrentConfiguration(LibCECConfiguration configuration)

Parameters

configuration LibCECConfiguration

Returns

bool

GetDeviceCecVersion(CecLogicalAddress)

Get the CEC version of the device with the given logical address.

public CecVersion GetDeviceCecVersion(CecLogicalAddress logicalAddress)

Parameters

logicalAddress CecLogicalAddress

Returns

CecVersion

GetDeviceInformation(string, LibCECConfiguration, uint)

Get information about the given CEC adapter.

public bool GetDeviceInformation(string port, LibCECConfiguration configuration, uint timeoutMs)

Parameters

port string
configuration LibCECConfiguration
timeoutMs uint

Returns

bool

GetDeviceMenuLanguage(CecLogicalAddress)

Get the menu language of the device with the given logical address.

public string GetDeviceMenuLanguage(CecLogicalAddress logicalAddress)

Parameters

logicalAddress CecLogicalAddress

Returns

string

GetDeviceOSDName(CecLogicalAddress)

Get the OSD name of a device on the CEC bus.

public string GetDeviceOSDName(CecLogicalAddress logicalAddress)

Parameters

logicalAddress CecLogicalAddress

Returns

string

GetDevicePhysicalAddress(CecLogicalAddress)

Get the physical address of the device with the given logical address.

public ushort GetDevicePhysicalAddress(CecLogicalAddress address)

Parameters

address CecLogicalAddress

Returns

ushort

GetDevicePowerStatus(CecLogicalAddress)

Get the power status of the device with the given logical address.

public CecPowerStatus GetDevicePowerStatus(CecLogicalAddress logicalAddress)

Parameters

logicalAddress CecLogicalAddress

Returns

CecPowerStatus

GetDeviceVendorId(CecLogicalAddress)

Get the vendor ID of the device with the given logical address.

public CecVendorId GetDeviceVendorId(CecLogicalAddress logicalAddress)

Parameters

logicalAddress CecLogicalAddress

Returns

CecVendorId

GetLibInfo()

Get a string with information about how libCEC was compiled.

public string GetLibInfo()

Returns

string

GetLogicalAddresses()

Get the list of logical addresses that libCEC is controlling.

public CecLogicalAddresses GetLogicalAddresses()

Returns

CecLogicalAddresses

GetStats()

Get statistics about traffic on the CEC line.

public CecAdapterStats GetStats()

Returns

CecAdapterStats

InitVideoStandalone()

Initialise the host on which libCEC is running. On the RPi this calls bcm_host_init(). Should be called directly after construction and before Open().

public void InitVideoStandalone()

IsActiveDevice(CecLogicalAddress)

Check whether a device is active on the bus.

public bool IsActiveDevice(CecLogicalAddress logicalAddress)

Parameters

logicalAddress CecLogicalAddress

Returns

bool

IsActiveDeviceType(CecDeviceType)

Check whether a device of the given type is active on the bus.

public bool IsActiveDeviceType(CecDeviceType type)

Parameters

type CecDeviceType

Returns

bool

IsActiveSource(CecLogicalAddress)

Check whether a device is currently the active source on the CEC bus.

public bool IsActiveSource(CecLogicalAddress logicalAddress)

Parameters

logicalAddress CecLogicalAddress

Returns

bool

IsLibCECActiveSource()

Check whether libCEC is the active source on the bus.

public bool IsLibCECActiveSource()

Returns

bool

MuteAudio()

Send a mute keypress to an audiosystem if it's present.

public byte MuteAudio()

Returns

byte

Open(string, int)

Open a connection to the CEC adapter.

public bool Open(string strPort, int iTimeoutMs)

Parameters

strPort string
iTimeoutMs int

Returns

bool

PhysicalAddressToString(ushort)

public string PhysicalAddressToString(ushort physicalAddress)

Parameters

physicalAddress ushort

Returns

string

PingAdapter()

Send a ping command to the adapter, to check if it's responding.

public bool PingAdapter()

Returns

bool

PollDevice(CecLogicalAddress)

Send a POLL message to a device, to check if it's present and responding.

public bool PollDevice(CecLogicalAddress logicalAddress)

Parameters

logicalAddress CecLogicalAddress

Returns

bool

PowerOnDevices(CecLogicalAddress)

Power on the given CEC capable devices.

public bool PowerOnDevices(CecLogicalAddress logicalAddress)

Parameters

logicalAddress CecLogicalAddress

Returns

bool

RescanActiveDevices()

Tell libCEC to poll for active devices on the bus.

public void RescanActiveDevices()

SendKeyRelease(CecLogicalAddress, bool)

Send a key release to a device on the CEC bus.

public bool SendKeyRelease(CecLogicalAddress destination, bool wait)

Parameters

destination CecLogicalAddress
wait bool

Returns

bool

SendKeypress(CecLogicalAddress, CecUserControlCode, bool)

Send a keypress to a device on the CEC bus.

public bool SendKeypress(CecLogicalAddress destination, CecUserControlCode key, bool wait)

Parameters

destination CecLogicalAddress
key CecUserControlCode
wait bool

Returns

bool

SetActiveSource(CecDeviceType)

Change the active source to a device type handled by libCEC.

public bool SetActiveSource(CecDeviceType type)

Parameters

type CecDeviceType

Returns

bool

SetConfiguration(LibCECConfiguration)

Change libCEC's configuration.

public bool SetConfiguration(LibCECConfiguration configuration)

Parameters

configuration LibCECConfiguration

Returns

bool

SetDeckControlMode(CecDeckControlMode, bool)

Change the deck control mode, if this adapter is a playback or recording device.

public bool SetDeckControlMode(CecDeckControlMode mode, bool sendUpdate)

Parameters

mode CecDeckControlMode
sendUpdate bool

Returns

bool

SetDeckInfo(CecDeckInfo, bool)

Change the deck info, if this adapter is a playback or recording device.

public bool SetDeckInfo(CecDeckInfo info, bool sendUpdate)

Parameters

info CecDeckInfo
sendUpdate bool

Returns

bool

SetHDMIPort(CecLogicalAddress, byte)

Change the active HDMI port.

public bool SetHDMIPort(CecLogicalAddress address, byte port)

Parameters

address CecLogicalAddress
port byte

Returns

bool

SetInactiveView()

Broadcast a message that this device is no longer the active source.

public bool SetInactiveView()

Returns

bool

SetLogicalAddress(CecLogicalAddress)

Change the logical address of the CEC adapter (debugging only).

public bool SetLogicalAddress(CecLogicalAddress logicalAddress)

Parameters

logicalAddress CecLogicalAddress

Returns

bool

SetMenuState(CecMenuState, bool)

Change the menu state.

public bool SetMenuState(CecMenuState state, bool sendUpdate)

Parameters

state CecMenuState
sendUpdate bool

Returns

bool

SetOSDString(CecLogicalAddress, CecDisplayControl, string)

Display a message on the device with the given logical address.

public bool SetOSDString(CecLogicalAddress logicalAddress, CecDisplayControl duration, string message)

Parameters

logicalAddress CecLogicalAddress
duration CecDisplayControl
message string

Returns

bool

SetPhysicalAddress(ushort)

Change the physical address (HDMI port) of the CEC adapter.

public bool SetPhysicalAddress(ushort physicalAddress)

Parameters

physicalAddress ushort

Returns

bool

SetStreamPath(CecLogicalAddress)

Set the stream path to the device on the given logical address.

public bool SetStreamPath(CecLogicalAddress address)

Parameters

address CecLogicalAddress

Returns

bool

SetStreamPath(ushort)

Set the stream path to the device on the given physical address.

public bool SetStreamPath(ushort physicalAddress)

Parameters

physicalAddress ushort

Returns

bool

StandbyDevices(CecLogicalAddress)

Put the given CEC capable devices in standby mode.

public bool StandbyDevices(CecLogicalAddress logicalAddress)

Parameters

logicalAddress CecLogicalAddress

Returns

bool

StartBootloader()

Start the bootloader of the CEC adapter. Closes the connection when successful.

public bool StartBootloader()

Returns

bool

SwitchMonitoring(bool)

Enable or disable monitoring mode, for debugging purposes.

public bool SwitchMonitoring(bool enable)

Parameters

enable bool

Returns

bool

ToString(CecAudioStatus)

public string ToString(CecAudioStatus status)

Parameters

status CecAudioStatus

Returns

string

ToString(CecDeckControlMode)

public string ToString(CecDeckControlMode iMode)

Parameters

iMode CecDeckControlMode

Returns

string

ToString(CecDeckInfo)

public string ToString(CecDeckInfo status)

Parameters

status CecDeckInfo

Returns

string

ToString(CecLogicalAddress)

public string ToString(CecLogicalAddress iAddress)

Parameters

iAddress CecLogicalAddress

Returns

string

ToString(CecMenuState)

public string ToString(CecMenuState iState)

Parameters

iState CecMenuState

Returns

string

ToString(CecOpcode)

public string ToString(CecOpcode opcode)

Parameters

opcode CecOpcode

Returns

string

ToString(CecPowerStatus)

public string ToString(CecPowerStatus iState)

Parameters

iState CecPowerStatus

Returns

string

ToString(CecSystemAudioStatus)

public string ToString(CecSystemAudioStatus mode)

Parameters

mode CecSystemAudioStatus

Returns

string

ToString(CecVendorId)

public string ToString(CecVendorId iVendorId)

Parameters

iVendorId CecVendorId

Returns

string

ToString(CecVersion)

public string ToString(CecVersion iVersion)

Parameters

iVersion CecVersion

Returns

string

Transmit(CecCommand)

Transmit a raw CEC command over the CEC line.

public bool Transmit(CecCommand command)

Parameters

command CecCommand

Returns

bool

VersionToString(uint)

public string VersionToString(uint version)

Parameters

version uint

Returns

string

VolumeDown(bool)

Send a volume down keypress to an audiosystem if it's present.

public byte VolumeDown(bool sendRelease)

Parameters

sendRelease bool

Returns

byte

VolumeUp(bool)

Send a volume up keypress to an audiosystem if it's present.

public byte VolumeUp(bool sendRelease)

Parameters

sendRelease bool

Returns

byte