11# GodSharp.SerialPort
2- Easy to use SerialPort class.
2+ An easy-to- use .NET SerialPort class.
33
44[ ![ AppVeyor build status] ( https://img.shields.io/appveyor/ci/seayxu/godsharp-serialport.svg?label=appveyor&style=flat-square )] ( https://ci.appveyor.com/project/seayxu/godsharp-serialport/ ) [ ![ NuGet] ( https://img.shields.io/nuget/v/GodSharp.SerialPort.svg?label=nuget&style=flat-square )] ( https://www.nuget.org/packages/GodSharp.SerialPort/ ) [ ![ MyGet] ( https://img.shields.io/myget/seay/v/GodSharp.SerialPort.svg?label=myget&style=flat-square )] ( https://www.myget.org/Package/Details/seay?packageType=nuget&packageId=GodSharp.SerialPort )
55
6+
7+ # Requirement
8+ .NET Framework >= 3.5
9+
610# Getting Started
711
8121 . New instance GodSerialPort.
@@ -11,10 +15,35 @@ Easy to use SerialPort class.
1115GodSerialPort serial = new GodSerialPort("COM1", 9600);
1216```
1317
14- 2 . Initialize the GodSerialPort instance with received data action: ` Action<byte[]> ` .
18+ About params:
19+
20+ - Parity value.
21+
22+ - Parity.Space:0|s|space
23+ - Parity.Mark:1|m|mark
24+ - Parity.Even:2|e|even
25+ - Parity.Odd:3|o|odd
26+ - Parity.None:4|n|none
27+
28+ - StopBits value.
29+
30+ - StopBits.None:0|n|none
31+ - StopBits.One:1|o|one
32+ - StopBits.OnePointFive:3|opf|of|f
33+ - StopBits.Two:2|t|two
1534
35+ - Handshake value.
36+
37+ - Handshake.None:0|n|none
38+ - Handshake.RequestToSend:1|r|rst
39+ - Handshake.RequestToSendXOnXOff:2|rtsxx|rsxx|rtsx|rsx|rx
40+ - Handshake.XOnXOff:3|x|xx
41+
42+ 2 . Use ` DataReceived ` event with received data action: ` Action<byte[]> ` .
43+
44+ ** Notice** :* This is not need when you read data by read method.*
1645```
17- serial.Init ((bytes)=>{});
46+ serial.UseDataReceived ((bytes)=>{});
1847```
1948
20493 . Open SerialPort object.
@@ -28,31 +57,16 @@ serial.Open();
2857```
2958byte[] bytes = new byte[]{31,32,33,34};
3059serial.Write(bytes);
31- serial.WriteAsciiString("ascii string" );
60+ serial.Write(bytes,offset:1,count:2 );
3261serial.WriteHexString("7E 48 53 44");
62+ serial.WriteAsciiString("ascii string");
3363```
3464
35- 5 . Parity value.
36-
37- - Parity.Space:0|s|space
38- - Parity.Mark:1|m|mark
39- - Parity.Even:2|e|even
40- - Parity.Odd:3|o|odd
41- - Parity.None:4|n|none
42-
43- 6 . StopBits value.
44-
45- - StopBits.None:0|n|none
46- - StopBits.One:1|o|one
47- - StopBits.OnePointFive:3|opf|of|f
48- - StopBits.Two:2|t|two
49-
50- 7 . Handshake value.
51-
52- - Handshake.None:0|n|none
53- - Handshake.RequestToSend:1|r|rst
54- - Handshake.RequestToSendXOnXOff:2|rtsxx|rsxx|rtsx|rsx|rx
55- - Handshake.XOnXOff:3|x|xx
65+ 5 . Read data.
66+ ```
67+ byte[] bytes = serial.Read();
68+ string stringAsciiOrHex = serial.ReadString();
69+ ```
5670
5771# Sample
5872
@@ -70,7 +84,7 @@ class Program
7084 }
7185
7286 GodSerialPort gsp = new GodSerialPort("COM"+num, 9600);
73- gsp.Init ((bytes) => {
87+ gsp.UseDataReceived ((bytes) => {
7488 string buffer = string.Join(" ", bytes);
7589 Console.WriteLine("receive data:" + buffer);
7690 });
@@ -105,3 +119,16 @@ class Program
105119 }
106120}
107121```
122+
123+ # Notes
124+
125+ ## 1.0.0
126+ - The first version release.
127+
128+ ## 1.0.1
129+ - Fix ctor and comments.
130+
131+ ## 1.1.0
132+ - 1.Add UseDataReceived method use to trigger DataReceived event.
133+ - 2.The read metnod can be used to end character.
134+ - 3.Add sleep time when try read data.
0 commit comments