public Scheduler.Classes.DeviceClass getHSRootDevice() { // Don't cache hsDevice directly - but we cache HS refId. // We can invalidate root dev by setting hsRootDevRefId to 0 if (hsRootDevRefId == 0) { var hsDev = getHSDevice(EnOceanDeviceType.Controller, this.getPortName()); if (hsDev != null) { hsRootDevRefId = hsDev.get_Ref(null); return(hsDev); } Console.WriteLine(" No EnOcean controller HS device - creating."); var newDev = createHSDevice("EnOcean controller: " + getPortName(), EnOceanDeviceType.Controller, getPortName()); newDev.set_Device_Type_String(HS, "EnOcean Controller"); // newDev.MISC_Set(HS, Enums.dvMISC.NO_LOG); newDev.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES); HS.SaveEventsDevices(); return(newDev); } Scheduler.Classes.DeviceClass rootDev = (Scheduler.Classes.DeviceClass)HS.GetDeviceByRef(hsRootDevRefId); return(rootDev); }