Added versiport creation to factory; rearrange success/failure cases to be more descriptive and easier to follow in code

This commit is contained in:
Heath Volmer
2018-01-18 15:52:51 -07:00
parent 32b548eba0
commit bc25c31860
5 changed files with 53 additions and 17 deletions

View File

@@ -167,25 +167,61 @@ namespace PepperDash.Essentials.Devices.Common
portDevice = DeviceManager.GetDeviceForKey(props.PortDeviceKey) as IDigitalInputPorts; portDevice = DeviceManager.GetDeviceForKey(props.PortDeviceKey) as IDigitalInputPorts;
if (portDevice == null) if (portDevice == null)
Debug.Console(0, "Unable to add digital input device with key '{0}'. Port Device does not support digital inputs", key); Debug.Console(0, "ERROR: Unable to add digital input device with key '{0}'. Port Device does not support digital inputs", key);
else else
{ {
var cs = (portDevice as CrestronControlSystem); var cs = (portDevice as CrestronControlSystem);
if (cs == null)
if (cs != null)
if (cs.SupportsDigitalInput && props.PortNumber <= cs.NumberOfDigitalInputPorts)
{ {
Debug.Console(0, "ERROR: Port device for [{0}] is not control system", props.PortDeviceKey);
return null;
}
if (cs.SupportsDigitalInput)
{
if (props.PortNumber > cs.NumberOfDigitalInputPorts)
{
Debug.Console(0, "WARNING: Cannot register DIO port {0} on {1}. Out of range",
props.PortNumber, props.PortDeviceKey);
return null;
}
DigitalInput digitalInput = cs.DigitalInputPorts[props.PortNumber]; DigitalInput digitalInput = cs.DigitalInputPorts[props.PortNumber];
if (!digitalInput.Registered) if (!digitalInput.Registered)
{ {
if(digitalInput.Register() == eDeviceRegistrationUnRegistrationResponse.Success) if (digitalInput.Register() == eDeviceRegistrationUnRegistrationResponse.Success)
return new GenericDigitalInputDevice(key, digitalInput); return new GenericDigitalInputDevice(key, digitalInput);
else else
Debug.Console(0, "Attempt to register digital input {0} on device with key '{1}' failed.", props.PortNumber, props.PortDeviceKey); Debug.Console(0, "WARNING: Attempt to register digital input {0} on device with key '{1}' failed.",
props.PortNumber, props.PortDeviceKey);
}
}
else if (cs.SupportsVersiport)
{
if (props.PortNumber > cs.NumberOfVersiPorts)
{
Debug.Console(0, "WARNING: Cannot register Vesiport {0} on {1}. Out of range",
props.PortNumber, props.PortDeviceKey);
return null;
}
Versiport vp = cs.VersiPorts[props.PortNumber];
if (!vp.Registered)
{
if (vp.Register() == eDeviceRegistrationUnRegistrationResponse.Success)
{
return new GenericVersiportInputDevice(key, vp);
}
else
{
Debug.Console(0, "WARNING: Attempt to register versiport {0} on device with key '{1}' failed.",
props.PortNumber, props.PortDeviceKey);
return null;
}
} }
} }
// Future: Check if portDevice is 3-series card or other non control system that supports versiports
} }
} }

View File

@@ -179,7 +179,7 @@ namespace PepperDash.Essentials
if (newDev != null) if (newDev != null)
DeviceManager.AddDevice(newDev); DeviceManager.AddDevice(newDev);
else else
Debug.Console(0, "WARNING: Cannot load unknown device type '{0}', key '{1}'.", devConf.Type, devConf.Key); Debug.Console(0, "ERROR: Cannot load unknown device type '{0}', key '{1}'.", devConf.Type, devConf.Key);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@@ -4,5 +4,5 @@
[assembly: AssemblyCompany("PepperDash Technology Corp")] [assembly: AssemblyCompany("PepperDash Technology Corp")]
[assembly: AssemblyProduct("PepperDashEssentials")] [assembly: AssemblyProduct("PepperDashEssentials")]
[assembly: AssemblyCopyright("Copyright © PepperDash Technology Corp 2017")] [assembly: AssemblyCopyright("Copyright © PepperDash Technology Corp 2017")]
[assembly: AssemblyVersion("1.0.22.*")] [assembly: AssemblyVersion("1.0.23.*")]