I am thinking of how the RFXCOM plugin should be modified to work with either the USB model or the LAN model.
Is this part of code the right code to put in the startup of the plugin to distinguish if serial over USB or IP must be used ?
if( luup.io.is_connected(lul_device)==true) then
-- serial connection already opened
-- nothing to open
else
-- IP connection to be opened
-- continue with existing code to open the connection
end
We’ve all done it a different way, but I think that they are in general equivalent.
My code checks the ip special variable for the pattern nnn.nnn.nnn.nnn:nnnnn, and if found calls luup.io.open(). Failing that, it checks for the IODevice variable that would indicate a serial port has been assigned to it. If present, the connection should be active already. If absent, probably the user hasn’t configured the device at all, and I have the code return false to show a failure message to the user.
If you want specific examples of code you could check the Onkyo or Denon plugins on code.mios.com, and probably quite a few more. Maybe the DSC Security Panel?
Best Home Automation shopping experience. Shop at Ezlo!