Skip to content

Commit d960761

Browse files
committed
Add constructor and change the constructor signature.
1 parent 61d671c commit d960761

File tree

10 files changed

+571
-255
lines changed

10 files changed

+571
-255
lines changed

README.md

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,6 @@ An easy-to-use .NET SerialPort class.
1515
GodSerialPort serial = new GodSerialPort("COM1", 9600);
1616
```
1717

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
34-
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-
4218
2. Use `DataReceived` event with received data action: `Action<byte[]>`.
4319

4420
**Notice**:*This is not need when you read data by read method.*
@@ -122,13 +98,17 @@ class Program
12298

12399
# Notes
124100

125-
## 1.0.0
126-
- The first version release.
127-
128-
## 1.0.1
129-
- Fix ctor and comments.
130-
101+
## 1.1.1
102+
- 1.Add constructor and change the constructor signature.
103+
- 2.Add `PortUtil` class.
104+
131105
## 1.1.0
132106
- 1.Add UseDataReceived method use to trigger DataReceived event.
133107
- 2.The read metnod can be used to end character.
134-
- 3.Add sleep time when try read data.
108+
- 3.Add sleep time when try read data.
109+
110+
## 1.0.1
111+
- 1.Fix ctor and comments.
112+
113+
## 1.0.0
114+
- 1.The first version release.

src/GodSharp.SerialPort/GodSharp.SerialPort.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,24 @@
4444
<Reference Include="System.Core" />
4545
</ItemGroup>
4646
<ItemGroup>
47+
<Compile Include="..\GodSharp.Shared\Extension\ByteExtension.cs">
48+
<Link>Extension\ByteExtension.cs</Link>
49+
</Compile>
50+
<Compile Include="..\GodSharp.Shared\Extension\StringExtension.cs">
51+
<Link>Extension\StringExtension.cs</Link>
52+
</Compile>
4753
<Compile Include="..\GodSharp.Shared\SerialPort\DataFormat.cs">
4854
<Link>DataFormat.cs</Link>
4955
</Compile>
5056
<Compile Include="..\GodSharp.Shared\SerialPort\GodSerialPort.cs">
5157
<Link>GodSerialPort.cs</Link>
5258
</Compile>
59+
<Compile Include="..\GodSharp.Shared\Util\PortUtil.cs">
60+
<Link>Util\PortUtil.cs</Link>
61+
</Compile>
5362
<Compile Include="Properties\AssemblyInfo.cs" />
5463
</ItemGroup>
64+
<ItemGroup />
5565
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5666
<PropertyGroup>
5767
<PostBuildEvent>

src/GodSharp.SerialPort/GodSharp.SerialPort.nuspec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>GodSharp.SerialPort</id>
5-
<version>1.1.0</version>
5+
<version>1.1.1</version>
66
<title>GodSharp.SerialPort</title>
77
<authors>seayxu</authors>
88
<owners>seayxu</owners>
@@ -14,6 +14,10 @@
1414
<releaseNotes>
1515
An easy-to-use .NET SerialPort class.(.NET Framework >= 3.5)
1616

17+
1.1.1
18+
- 1.Add constructor and change the constructor signature.
19+
- 2.Add PortUtil class.
20+
1721
1.1.0
1822
- 1.Add UseDataReceived method use to trigger DataReceived event.
1923
- 2.The read metnod can be used to end character.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
3+
namespace GodSharp.Extension
4+
{
5+
/// <summary>
6+
/// Byte extension methods class.
7+
/// </summary>
8+
public static class ByteExtension
9+
{
10+
/// <summary>
11+
/// Bytes to hexadecimal.
12+
/// </summary>
13+
/// <param name="bytes">The byte array.</param>
14+
/// <param name="separator">The separator,default is space</param>
15+
/// <returns>String of hex.</returns>
16+
public static string ToHexString(this byte[] bytes,string separator=" ")
17+
{
18+
if (bytes==null||bytes.Length<1)
19+
{
20+
return null;
21+
}
22+
23+
List<string> list = new List<string>();
24+
foreach (byte b in bytes)
25+
{
26+
list.Add(b.ToString("X2"));
27+
}
28+
29+
return string.Join(separator, list.ToArray());
30+
}
31+
}
32+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
3+
namespace GodSharp.Extension
4+
{
5+
/// <summary>
6+
/// String extension methods class.
7+
/// </summary>
8+
public static class StringExtension
9+
{
10+
/// <summary>
11+
/// Hexadecimal string to an byte array.
12+
/// </summary>
13+
/// <param name="hex">The hex string.</param>
14+
/// <returns>An byte array.</returns>
15+
public static byte[] HexToByte(this string hex)
16+
{
17+
// remove space
18+
hex = hex.Replace(" ", "");
19+
20+
byte[] bytes = new byte[hex.Length / 2];
21+
for (int i = 0; i < hex.Length; i += 2)
22+
{
23+
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
24+
}
25+
return bytes;
26+
}
27+
}
28+
}

src/GodSharp.Shared/GodSharp.Shared.projitems

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
<Import_RootNamespace>GodSharp</Import_RootNamespace>
1010
</PropertyGroup>
1111
<ItemGroup>
12+
<Compile Include="$(MSBuildThisFileDirectory)Extension\ByteExtension.cs" />
13+
<Compile Include="$(MSBuildThisFileDirectory)Extension\StringExtension.cs" />
1214
<Compile Include="$(MSBuildThisFileDirectory)SerialPort\DataFormat.cs" />
1315
<Compile Include="$(MSBuildThisFileDirectory)SerialPort\GodSerialPort.cs" />
16+
<Compile Include="$(MSBuildThisFileDirectory)Util\PortUtil.cs" />
1417
</ItemGroup>
1518
</Project>

0 commit comments

Comments
 (0)