コード例 #1
0
        public FirmataTestFixture()
        {
            try
            {
                var loggerFactory = LoggerFactory.Create(builder =>
                {
                    builder.AddConsole().AddProvider(new DebuggerOutputLoggerProvider());
                });

                // Statically register our factory. Note that this must be done before instantiation of any class that wants to use logging.
                LogDispatcher.LoggerFactory = loggerFactory;
                _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                _socket.Connect(IPAddress.Loopback, 27016);
                _socket.NoDelay = true;
                _networkStream  = new NetworkStream(_socket, true);
                Board           = new ArduinoBoard(_networkStream);
                if (!(Board.FirmataVersion > new Version(1, 0)))
                {
                    // Actually not expecting to get here (but the above will throw a SocketException if the remote end is not there)
                    throw new NotSupportedException("Very old firmware found");
                }

                return;
            }
            catch (SocketException)
            {
                Console.WriteLine("Unable to connect to simulator, trying hardware...");
            }

            if (!ArduinoBoard.TryFindBoard(SerialPort.GetPortNames(), new List <int>()
            {
                115200
            }, out var board))
            {
                Board = null;
                return;
            }

            Board = board;
        }
コード例 #2
0
        public FirmataTestFixture()
        {
            try
            {
                _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                _socket.Connect(IPAddress.Loopback, 27016);
                _socket.NoDelay = true;
                _networkStream  = new NetworkStream(_socket, true);
                Board           = new ArduinoBoard(_networkStream);
                if (!(Board.FirmataVersion > new Version(1, 0)))
                {
                    // Actually not expecting to get here (but the above will throw a SocketException if the remote end is not there)
                    throw new NotSupportedException("Very old firmware found");
                }

                Board.LogMessages += (x, y) => Console.WriteLine(x);

                return;
            }
            catch (SocketException)
            {
                Console.WriteLine("Unable to connect to simulator, trying hardware...");
            }

            if (!ArduinoBoard.TryFindBoard(SerialPort.GetPortNames(), new List <int>()
            {
                115200
            }, out var board))
            {
                Board = null;
                return;
            }

            Board              = board;
            Board.LogMessages += (x, y) => Console.WriteLine(x);
        }