Example #1
0
        public void SystemTextRoundTripMed()
        {
            var port = new SerialPort("COM12", 9600);

            port.Open();
            var serializer = new CommandJsonSerializer();

            serializer.UseLibrary = JsonLibrary.SystemTextJson;

            var listener = new DesktopSerialListener(port, serializer);

            Task.Run(() => listener.StartListening());

            UplinkFileCommand rxCmd = null;

            listener.CommandReceived += (l, command) =>
            {
                rxCmd = command as UplinkFileCommand;
            };

            var transport = new WorkerSerialTransport(serializer, port);

            transport.ExternalManageSerialPort = true; // prevent the transport from closing the port
            var payload = new StringBuilder();

            for (int i = 0; i < 100; i++)
            {
                payload.Append($"{i}: abcdefghijklmnopqrstuvwxyz\r\n");
            }

            var txCmd = new UplinkFileCommand
            {
                Destination = "arbitrary path",
                FileData    = payload.ToString()
            };

            Thread.Sleep(1000);
            transport.DeliverCommand(txCmd);
            Thread.Sleep(5000);
            Assert.NotNull(rxCmd);
            Assert.Equal(txCmd.Destination, rxCmd.Destination);
            Assert.Equal(txCmd.FileData, rxCmd.FileData);
        }
Example #2
0
        public void SystemTextRoundTripSmall()
        {
            var port = new SerialPort("COM12", 9600);

            port.Open();
            var serializer = new CommandJsonSerializer();

            serializer.UseLibrary = JsonLibrary.SystemTextJson;

            var listener = new DesktopSerialListener(port, serializer);

            Task.Run(() => listener.StartListening());

            UplinkFileCommand rxCmd = null;

            listener.CommandReceived += (l, command) =>
            {
                rxCmd = command as UplinkFileCommand;
            };

            var transport = new WorkerSerialTransport(serializer, port);

            transport.ExternalManageSerialPort = true; // prevent the transport from closing the port
            var txCmd = new UplinkFileCommand
            {
                Destination = "arbitrary path",
                FileData    = "foo-bar-baz"
            };

            Thread.Sleep(1000);
            transport.DeliverCommand(txCmd);
            Thread.Sleep(2000);
            Assert.NotNull(rxCmd);
            Assert.Equal(txCmd.Destination, rxCmd.Destination);
            Assert.Equal(txCmd.FileData, rxCmd.FileData);
        }