Beispiel #1
0
        public IDevice CreateDevice(CCToolsDeviceType type, string id, int address)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            var     i2CSlaveAddress = new I2CSlaveAddress(address);
            IDevice deviceInstance;

            switch (type)
            {
            case CCToolsDeviceType.HSPE16_InputOnly:
            {
                deviceInstance = new HSPE16InputOnly(id, i2CSlaveAddress, _i2CBusService, _log);
                break;
            }

            case CCToolsDeviceType.HSPE16_OutputOnly:
            {
                deviceInstance = new HSPE16OutputOnly(id, i2CSlaveAddress, _i2CBusService, _log);
                break;
            }

            case CCToolsDeviceType.HSPE8_InputOnly:
            {
                deviceInstance = new HSPE8InputOnly(id, i2CSlaveAddress, _i2CBusService, _log);
                break;
            }

            case CCToolsDeviceType.HSPE8_OutputOnly:
            {
                deviceInstance = new HSPE8OutputOnly(id, i2CSlaveAddress, _i2CBusService, _log);
                break;
            }

            case CCToolsDeviceType.HSRel5:
            {
                deviceInstance = new HSREL5(id, i2CSlaveAddress, _i2CBusService, _log);
                break;
            }

            case CCToolsDeviceType.HSRel8:
            {
                deviceInstance = new HSREL8(id, i2CSlaveAddress, _i2CBusService, _log);
                break;
            }

            case CCToolsDeviceType.HSRT16:
            {
                deviceInstance = new HSRT16(id, i2CSlaveAddress, _i2CBusService, _log);
                break;
            }

            default: throw new NotSupportedException();
            }

            return(deviceInstance);
        }
Beispiel #2
0
        // TODO: Remove after all calls are migration to a config file.
        public IDevice RegisterDevice(CCToolsDeviceType type, string id, int address)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            var device = CreateDevice(type, id, address);

            _deviceRegistryService.RegisterDevice(device);
            return(device);
        }