Beispiel #1
0
 private bool WasSetupCorrectly(ICommunicationDeviceSettings settings)
 {
     if (_port is null || settings is null || !(settings is SerialPortSettingsModel))
     {
         return(false);
     }
     return(PortNumberExists(((SerialPortSettingsModel)settings).PortNumber));
 }
Beispiel #2
0
        /// <summary>
        /// Sets up all of the necessary parameters for this instance of the device
        /// </summary>
        /// <param name="settings">Configuration from AppSettings for this type of device</param>
        /// <returns>True if successful</returns>
        private void Setup(ICommunicationDeviceSettings settings)
        {
            if (!(settings is SerialPortSettings set))
            {
                throw new ArgumentNullException(nameof(settings));
            }

            SetUpDeviceOptions(set);
        }
Beispiel #3
0
        public void Add(ICommunicationDeviceSettings settings)
        {
            _ = settings ?? throw new System.ArgumentNullException(nameof(settings));

            if (_adapters.Any(s => s.Name == settings.Name))
            {
                throw new System.Exception($@"Device ""{settings.Name}"" already exists in this container");
            }
            _adapters.Add(settings);
        }
Beispiel #4
0
        public bool Setup(ICommunicationDeviceSettings settings)
        {
            IMoqPortSettingsModel internalSettings = (IMoqPortSettingsModel)settings;

            _portName           = internalSettings.PortNumber.ToString();
            CompletitionTimeout = internalSettings.CompletitionTimeout;
            ConfirmationTimeout = internalSettings.ConfirmationTimeout;
            Name = internalSettings.Name;

            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Sets up all of the necessary parameters for this instance of the device
        /// </summary>
        /// <param name="settings">Configuration from AppSettings for this type of device</param>
        /// <returns>True if successful</returns>
        public bool Setup(ICommunicationDeviceSettings settings)
        {
            if (settings is null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (!WasSetupCorrectly(settings))
            {
                return(_wasSetupCorrectly = false);
            }

            SetUpDeviceOptions((SerialPortSettingsModel)settings);
            return(_wasSetupCorrectly = true);
        }
        public ICommunicationDevice CreateDevice(ICommunicationDeviceSettings settings)
        {
            ICommunicationDevice device;

            switch (settings)
            {
            case var _ when settings is SerialPortSettingsModel:
                device = _deviceFactory[DeviceType.Serial];
                break;

            case var _ when settings is IMoqPortSettingsModel:
                device = _deviceFactory[DeviceType.Moq];
                break;

            default:
                device = null;
                break;
            }
            device?.Setup(settings);
            return(device);
        }
Beispiel #7
0
 public SerialPortAdapter(ICommunicationDeviceSettings settings)
 {
     Setup(settings);
     SetupPhysicalConnectionMonitoring();
 }
Beispiel #8
0
 public SerialPortAdapter(ICommunicationDeviceSettings settings) : this() => Setup(settings);