How to get the status of an audio capture source in Lua

whbcstreaming

New Member
Greetings everyone. I'm trying to write a short Lua script to interrogate our X32 mixer USB connection to make
sure it is on and connected to OBS. The code snippet (posted below) works sometimes. If the X32 is powered on
and the PC connects to it, then everything works. Also, if the X32-USB gets changed to "default" then it also
works. There is one use-case though where it doesn't work, and that is the case where the device_id shows
X32-USB but the status is "disconnected" (as per the attached screen shot). So, to get the script to be 100%
accurate I need to get the status value of the device_id, but can't find in the API docs how to do that.

Anybody know the steps to get the actual status of a device?

Thanks as always,

Pat

local x32connect = 0
local source = obs.obs_get_source_by_name("X32-USB")
if (source) then
local settings = obs.obs_source_get_settings(source)
if (settings) then
obs.obs_source_release(source)
local device = obs.obs_data_get_string(settings,"device_id")
obs.obs_data_release(settings)
if (device == "{0.0.1.00000000}.{f6cad7ef-c5d5-4a5d-aa59-bffdd2d2ad89}") then
x32connect = 1
end
end
else
print ("Source returned null")
end
if (x32connect == 1) then
return
else
print ("\n\n **** X32 is not connected to OBS. \n")
print (" Check the troubleshooting guide to repair\n")
print ("<<< Ignore the next message >>>")
-- The next line is just to make the Script log window appear to show the error
-- ignore function doesn't exist
ignore()
end

Screen Shot 2023-02-23 at 4.44.10 PM.png
 
Top