I have a media PC running Lubuntu, where I run Spotify and Plex Home Theater. I have a Pulse-Eight USB CEC adapter, so I can use my AV receiver's remote to control Plex Home Theater.I run the Spotify Linux client in the background. It works very well, because I can connect to it and control it from my phone and laptop. They also provide a DBUS interface, so I can write programs to control it.My goal is to write a small daemon program that monitors Spotify. Whenever the Spotify status changes to playing, I want to send a CEC command over HDMI, so that my AV receiver switches to the correct channel.I can check the Spotify status using this command:dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus'And I can send the active source CEC command to my receiver using this command:echo as | cec-client -sThe only problem is that Plex Home Theater is locking the CEC device:$ echo as | cec-client -sopening a connection to the CEC adapter...DEBUG:   [              69] Broadcast (F): osd name set to 'Broadcast'ERROR:   [            3575] error opening serial port '/dev/ttyACM0': Couldn't lock the serial portERROR:   [            3575] could not open a connection (try 1)ERROR:   [            6410] error opening serial port '/dev/ttyACM0': Couldn't lock the serial portERROR:   [            6410] could not open a connection (try 2)ERROR:   [            8299] error opening serial port '/dev/ttyACM0': Couldn't lock the serial portERROR:   [            8299] could not open a connection (try 3)ERROR:   [            9559] error opening serial port '/dev/ttyACM0': Couldn't lock the serial portERROR:   [            9559] could not open a connection (try 4)NOTICE:  [           10564] connection openedERROR:   [           10565] could not start CEC communicationsunable to open the device on port /dev/ttyACM0(This command works fine when Plex is not running.)I'm wondering if there is any way I could get a temporary lock on the device, send the command, and then give the lock back to Plex?Or is there any way that I could create a multiplex device that can accept commands from multiple programs? In theory, I don't think it would be too hard to create a special device that locks /dev/ttyACM0 and allows connections from multiple programs.Another way would be to just fork the Plex Home Theater code and add an API endpoint, so that I could make Plex send the CEC command. (Maybe this already exists?) I suppose I could even write the whole Spotify daemon as a plugin for Plex Home Theater.The last resort would be just killing the Plex process and restarting it after sending the command, but that would be an ugly hack.
Is it possible to send a CEC command with `cec-client` if another program has already locked the CEC device?
devices;d bus;hdmi