Beispiel #1
0
            public void Exception_For_NullHooks()
            {
                var settings = new SerialTransportSettings();

                Check.ThatCode(() => Transport.Create(settings, (ITransportHooks)null))
                .Throws <ArgumentNullException>();
            }
Beispiel #2
0
            public void Exception_For_NullLogger()
            {
                var settings = new SerialTransportSettings();
                var hooks    = new Mock <ITransportHooks>();

                Check.ThatCode(() => Transport.Create(settings, null, hooks.Object)).Throws <ArgumentNullException>();
            }
        /// <summary>
        /// Creates a new serial <see cref="ITransport"/> for the given <paramref name="settings"/>.
        /// </summary>
        ///
        /// <param name="settings">
        /// The settings for the serial transport to create.</param>
        ///
        /// <exception cref="ArgumentNullException">
        /// A null reference was passed to a method that did not accept it as a valid argument.</exception>
        public static ITransport Create(SerialTransportSettings settings)
        {
            Verify.NotNull(settings, nameof(settings));

            settings = new SerialTransportSettings(settings);

            return(new DefaultSerialTransport(settings, NullLogger.Instance, null));
        }
        /// <summary>
        /// Creates a new serial <see cref="ITransport"/> for the given <paramref name="settings"/>.
        /// </summary>
        ///
        /// <param name="settings">
        /// The settings for the serial transport to create.</param>
        /// <param name="logger">
        /// The logger that should be used for logging transport operations.</param>
        ///
        /// <exception cref="ArgumentNullException">
        /// A null reference was passed to a method that did not accept it as a valid argument.</exception>
        public static ITransport Create(SerialTransportSettings settings, ILogger logger)
        {
            Verify.NotNull(settings, nameof(settings));
            Verify.NotNull(logger, nameof(logger));

            settings = new SerialTransportSettings(settings);

            return(new DefaultSerialTransport(settings, logger, null));
        }
 public static void LogFailedToOpen(
     this ILogger logger,
     String portName,
     SerialTransportSettings settings,
     Exception exception
     )
 {
     sFailedToOpen(logger, portName, settings, exception);
 }
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        ///
        /// <param name="settings">
        /// The settings to copy from.</param>
        ///
        /// <exception cref="ArgumentNullException">
        /// A null reference was passed to a method that did not accept it as a valid argument.</exception>
        public SerialTransportSettings(SerialTransportSettings settings)
        {
            Verify.NotNull(settings, nameof(settings));

            PortName  = settings.PortName;
            Baud      = settings.Baud;
            DataBits  = settings.DataBits;
            Parity    = settings.Parity;
            StopBits  = settings.StopBits;
            Handshake = settings.Handshake;
        }
Beispiel #7
0
        public void Construction_Default()
        {
            // act
            var settings = new SerialTransportSettings();

            // assert
            Check.That(settings.PortName).IsEqualTo("COM1");
            Check.That(settings.Baud).IsEqualTo(9600);
            Check.That(settings.DataBits).IsEqualTo(8);
            Check.That(settings.Parity).IsEqualTo(Parity.None);
            Check.That(settings.StopBits).IsEqualTo(StopBits.One);
            Check.That(settings.Handshake).IsEqualTo(Handshake.None);

            Check.That(settings.ToString()).IsEqualTo("COM1,9600,8,None,One,None");
        }
Beispiel #8
0
            public void Create()
            {
                // act
                var settings = new SerialTransportSettings();

                using var transport = Transport.Create(settings);

                // assert
                Check.That(transport).IsInstanceOf <DefaultSerialTransport>();

                var transportImpl = (DefaultSerialTransport)transport;

                Check.That(transportImpl.Settings).Not.IsSameReferenceAs(settings);
                Check.That(transportImpl.Logger).IsSameReferenceAs(NullLogger.Instance);
                Check.That(transportImpl.Hooks).IsNull();
            }
Beispiel #9
0
            public void Create_With_Logger()
            {
                // act
                var settings = new SerialTransportSettings();

                var logger = LoggerFactory.Create(builder => builder.AddSimpleConsole()).CreateLogger("Test");

                using var transport = Transport.Create(settings, logger);

                // assert
                Check.That(transport).IsInstanceOf <DefaultSerialTransport>();

                var transportImpl = (DefaultSerialTransport)transport;

                Check.That(transportImpl.Settings).Not.IsSameReferenceAs(settings);
                Check.That(transportImpl.Logger).IsSameReferenceAs(logger);
                Check.That(transportImpl.Hooks).IsNull();
            }
Beispiel #10
0
        public void Construction_Copy()
        {
            // act
            var org = new SerialTransportSettings {
                PortName  = "COM12",
                Baud      = 38400,
                DataBits  = 7,
                Parity    = Parity.Even,
                StopBits  = StopBits.Two,
                Handshake = Handshake.XOnXOff,
            };

            var settings = new SerialTransportSettings(org);

            // assert
            Check.That(settings.PortName).IsEqualTo("COM12");
            Check.That(settings.Baud).IsEqualTo(38400);
            Check.That(settings.DataBits).IsEqualTo(7);
            Check.That(settings.Parity).IsEqualTo(Parity.Even);
            Check.That(settings.StopBits).IsEqualTo(StopBits.Two);
            Check.That(settings.Handshake).IsEqualTo(Handshake.XOnXOff);
        }
 public static void LogOpen(this ILogger logger, String portName, SerialTransportSettings settings)
 {
     sOpen(logger, portName, settings, null);
 }