Axium Posted September 6, 2022 Posted September 6, 2022 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? Quote
Andrew H Posted September 6, 2022 Posted September 6, 2022 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. Quote
Axium Posted September 6, 2022 Author Posted September 6, 2022 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.