File tree Expand file tree Collapse file tree 4 files changed +28
-6
lines changed
Tests/UnitTestsSerialPort Expand file tree Collapse file tree 4 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -93,12 +93,12 @@ You can as well write and read strings:
9393``` csharp
9494string toSend = " I ❤ nanoFramework" ;
9595port .WriteLine (toSend );
96- // this will send the string encoded finishing by a new line, by default \r\n
97- // You can change the new line by anything:
96+ // this will send the string encoded finishing by a new line, by default `\n`
97+ // You can change the new line to be anything:
9898port .NewLine = " ❤❤" ;
99- // Now it will send the 2 hearts as the end of line while operating a ReadLine or WriteLine
100- // You can ad anytime change it back:
101- port .NewLine = SerialPort .DefaultNewLine ; // default is "\r\ n"
99+ // Now it will send 2 hearts as the line ending `WriteLine` and will use 2 hearts as the terminator for `ReadLine`.
100+ // You can change it back to the `\n` default at anytime :
101+ port .NewLine = SerialPort .DefaultNewLine ; // default is "\n"
102102// This will read the existing buffer:
103103string existingString = port .ReadExisting ();
104104// Note that if it can't properly convert the bytes to a string, you'll get an exception
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ public sealed class SerialPort : IDisposable
1515 {
1616 // default new line
1717 [ System . Diagnostics . DebuggerBrowsable ( Diagnostics . DebuggerBrowsableState . Never ) ]
18- private const string _defaultNewLine = "\r " ;
18+ private const string _defaultNewLine = "\n " ;
1919
2020 [ System . Diagnostics . DebuggerBrowsable ( Diagnostics . DebuggerBrowsableState . Never ) ]
2121 private static readonly SerialDeviceEventListener s_eventListener = new ( ) ;
Original file line number Diff line number Diff line change 1+ # SerialPort Unit Tests
2+ Note:
3+ The current unit tests only run on real hardware, and are currently setup for ESP32 devices with ` COM2 ` and ` COM3 ` available and interconnected.
4+ Other devices can be added easily by changing the ` SetupComPorts ` in [ SerialTests.cs] ( SerialTests.cs ) .
5+
Original file line number Diff line number Diff line change @@ -93,6 +93,23 @@ public void BasicReadWriteTests()
9393 }
9494 }
9595
96+ [ TestMethod ]
97+ public void VerifyDefaultReadLineCharacter ( )
98+ {
99+ // Arrange
100+ EnsurePortsOpen ( ) ;
101+ _serOne . WriteTimeout = 1000 ;
102+ _serOne . ReadTimeout = 1000 ;
103+ _serTwo . WriteTimeout = 1000 ;
104+ _serTwo . ReadTimeout = 1000 ;
105+ string toSend = "This is a simple test for verifying the default readline character \r \n \\ r" ;
106+ // Act
107+ _serOne . Write ( toSend ) ;
108+ string toReceive = _serTwo . ReadLine ( ) ;
109+ // Assert
110+ Assert . Equal ( toSend , toReceive + "\\ r" + _serOne . NewLine ) ;
111+ }
112+
96113 [ TestMethod ]
97114 public void WriteAndReadStringTests ( )
98115 {
You can’t perform that action at this time.
0 commit comments