A .net class library to facilitate HDMI-CEC communications.
This library can be used to create and parse HDMI Version 1.4 compliant CEC-messages for communication with HDMI-CEC devices. It can be used on top of other communication protocols and libraries which support CEC hardware, such as kwikwai HDMI-CEC AV-controllers or Pulse-Eight's USB-CEC adapter.
Install-Package AleRoe.CecSharpCecSharp provides an object model for dealing with HDMI-CEC messages as well as emulating a HDMI-CEC device. The static CecMessageBuilder class can be used to create arbitrary HDMI-CEC frames which can be used to control devices on the HDMI-CEC bus.
The CecDevice class represents a HDMI-CEC enabled device capable of responding to incoming HDMI-CEC messages via the ProcessCecMessage method.
To emulate a HDMI-CEC device, create a new CecDevice instance, specifying the device type, name, vendor, physical- and logical address. Use the ProcessCecMessage() and ToCec()methods to get the appropriate response depending on the device settings. Not all input messages will generate a response (like UserControlPressed, UserControlReleased or StandBy and messages not intended for this device) and instead return CecMessage.None.
// create devicevardevice=newCecDevice(DeviceType.PlaybackDevice,"OsdName",99999,PhysicalAddress.Parse("2.1.0.0"),LogicalAddress.Tuner3);// create a CecMessage from an incoming CEC-frame// i.e. a request to a device to return its physical address. (Directly addressed)varframe="07:83";varmessage=CecMessage.Parse(frame);// process the message to get the appropriate responsevarresponse=device.ProcessCecMessage(message).ToCec();// returns a ReportPhysicalAddress broadcast message which can be sent as a response// response = "7F:84:21:00:04"In order to create arbitrary CEC-frames, use the static CecMessageBuilder class to build CecMessage structs.
publicstaticclassCecMessageBuilder{publicstaticCecMessageGivePhysicalAddress(LogicalAddresssource,LogicalAddressdestination);publicstaticCecMessageReportPhysicalAddress(LogicalAddresssource,DeviceTypedeviceType,PhysicalAddressphysicalAddress);publicstaticCecMessageReportAudioStatus(LogicalAddresssource,LogicalAddressdestination,AudioMuteStatusstatus,intvalue);publicstaticCecMessageSetSystemAudioMode(LogicalAddresssource,LogicalAddressdestination,SystemAudioStatusstatus);publicstaticCecMessageDeviceVendorId(LogicalAddresssource,intvendorId);publicstaticCecMessageSetOsdName(LogicalAddresssource,LogicalAddressdestination,stringosdName);publicstaticCecMessageMenuStatus(LogicalAddresssource,LogicalAddressdestination,MenuStatusstate);publicstaticCecMessageInactiveSource(LogicalAddresssource,PhysicalAddressphysicalAddress);publicstaticCecMessageActiveSource(LogicalAddresssource,PhysicalAddressphysicalAddress);publicstaticCecMessageFeatureAbort(LogicalAddresssource,LogicalAddressdestination,CommandopCode,AbortReasonreason);publicstaticCecMessageCecVersion(LogicalAddresssource,LogicalAddressdestination,CecVersionversion);publicstaticCecMessageReportPowerStatus(LogicalAddresssource,LogicalAddressdestination,PowerStatusstatus);publicstaticCecMessagePolling(LogicalAddresssource);publicstaticCecMessageSetMenuLanguage(LogicalAddresssource,[NotNull]stringlanguage);publicstaticCecMessageGetMenuLanguage(LogicalAddresssource,LogicalAddressdestination);publicstaticCecMessageSetOSDString(LogicalAddresssource,DisplayControldisplayControl,[NotNull]stringosdString);publicstaticCecMessageGiveOsdName(LogicalAddresssource,LogicalAddressdestination);publicstaticCecMessageRequestActiveSource(LogicalAddresssource);publicstaticCecMessageSetStreamPath(PhysicalAddressphysicalAddress);publicstaticCecMessageRoutingChange(LogicalAddresssource,PhysicalAddressoriginalAddress,PhysicalAddressnewAddress);publicstaticCecMessageRoutingInformation(LogicalAddresssource,PhysicalAddressphysicalAddress);publicstaticCecMessageGiveDevicePowerStatus(LogicalAddresssource,LogicalAddressdestination);publicstaticCecMessageGiveDeviceVendorId(LogicalAddresssource,LogicalAddressdestination);publicstaticCecMessageVendorCommand(LogicalAddresssource,LogicalAddressdestination,byte[]data);publicstaticCecMessageVendorCommand(LogicalAddresssource,LogicalAddressdestination,stringdata);publicstaticCecMessageVendorCommandWithId(LogicalAddresssource,LogicalAddressdestination,intvendorId,byte[]data);publicstaticCecMessageVendorCommandWithId(LogicalAddresssource,LogicalAddressdestination,intvendorId,stringdata);publicstaticCecMessageVendorRemoteButtonDown(LogicalAddresssource,LogicalAddressdestination,byte[]data);publicstaticCecMessageVendorRemoteButtonDown(LogicalAddresssource,LogicalAddressdestination,stringdata);publicstaticCecMessageVendorRemoteButtonUp(LogicalAddresssource,LogicalAddressdestination);publicstaticCecMessageStandby(LogicalAddresssource,LogicalAddressdestination);publicstaticCecMessageUserControlPressed(LogicalAddresssource,LogicalAddressdestination,UiCommandcommand);publicstaticCecMessageUserControlReleased(LogicalAddresssource,LogicalAddressdestination);}Use the .ToCec() extension method to get the actual CEC-Message.
usingAleRoe.CecSharp;usingAleRoe.CecSharp.Extensions;varmessage=CecMessageBuilder.ActiveSource(LogicalAddress.Unregistered,PhysicalAddress.Parse("2.0.0.0"));varcec=message.ToCec();// cec = "FF:82:20:00"Library now targets net 8.0 only.
Support for netstandard 2.1 removed. Library now targets net 7.0 only.
CecSharp now fully supports the following HDMI-CEC features and their related commands for both CecMessageBuilder and ProcessCecMessage (where applicable):
- System Information
- OSD Display
- Device OSD Name Transfer
- Device Power Status
- Routing Control
- Vendor Specific Command
- System Standby
- Device Menu Control
- Abort
Please let me know if you are using this library and have any suggestions or questions.