Jump to content
C4 Forums | Control4

DriverWorks: Device variables and device/proxy IDs


Axium

Recommended Posts

We are writing several drivers that interact and would like to be able to access (read) variables created by other connected devices. However we are running into problems due to the differentiation of device (or "protocol") IDs and proxy IDs.

The connections between devices can be inspected using the C4:GetBoundConsumerDevices and C4:GetBoundProviderDevice functions but these appear to only deal with proxy IDs, i.e. the parameters taken by the functions and the values returned by the functions are all proxy IDs. There does not appear to be any way to convert a returned proxy ID to a device ID, so in other words we cannot get the device ID of any connected device. (It is possible to get the proxy IDs for any particular device using C4:GetProxyDevicesById() but the reverse does not appear to exist.)

Variables are created using the C4:AddVariable function but they appear to be created under the device rather than the proxy, so if another driver wants to access a variable using the C4:GetDeviceVariables function, then its device ID parameter needs to be the device ID rather than the proxy ID. Therefore there does not seem to be any way for one device to be able to inspect a connected device's variables.

Is there a way around this limitation or another function that we're not aware of? Is there a better way to do this?

Link to comment
Share on other sites


There are a couple of ways to do this depending upon what exactly your drivers will be doing.

You could make a custom binding that would appear under the connections tab using a special class type. This would allow you to connect your devices and to treat this connection as a communication bus using SendToProxy.

 

Another way to approach it would be to use GetDevicesByC4iName from one driver to obtain a list of drivers in the project that are the type with which you wish to communicate. You could then use SendToDevice to send a command to a given device by device id.

 

Either way, it won't be as easy as pulling properties from the same driver. You'll have to write functions to pass info between drivers depending on what you want to communicate. 

Link to comment
Share on other sites

Thanks @Andrew H for the tips. I found C4:GetDevices, which returns all devices and proxies, so I wrote a function for creating an array to map proxy IDs to device IDs:

function get_proxy_device_map()
	local map = {}
	local devices = C4:GetDevices()	-- could add filtering options here
	for k,v in pairs(devices) do
		local proxies = v.proxies or {}
		for k2,_ in pairs(proxies) do
			map[k2] = k
		end
	end
	return map
end

By mapping the proxy IDs to the device IDs, we were able to access the variables on connected devices.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.