Skip to content

Commit

Permalink
Add constructor and change the constructor signature.
Browse files Browse the repository at this point in the history
  • Loading branch information
seayxu committed Apr 18, 2017
1 parent 61d671c commit d960761
Show file tree
Hide file tree
Showing 10 changed files with 571 additions and 255 deletions.
42 changes: 11 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,6 @@ An easy-to-use .NET SerialPort class.
GodSerialPort serial = new GodSerialPort("COM1", 9600);
```

About params:

- Parity value.

- Parity.Space:0|s|space
- Parity.Mark:1|m|mark
- Parity.Even:2|e|even
- Parity.Odd:3|o|odd
- Parity.None:4|n|none

- StopBits value.

- StopBits.None:0|n|none
- StopBits.One:1|o|one
- StopBits.OnePointFive:3|opf|of|f
- StopBits.Two:2|t|two

- Handshake value.

- Handshake.None:0|n|none
- Handshake.RequestToSend:1|r|rst
- Handshake.RequestToSendXOnXOff:2|rtsxx|rsxx|rtsx|rsx|rx
- Handshake.XOnXOff:3|x|xx

2. Use `DataReceived` event with received data action: `Action<byte[]>`.

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

# Notes

## 1.0.0
- The first version release.

## 1.0.1
- Fix ctor and comments.

## 1.1.1
- 1.Add constructor and change the constructor signature.
- 2.Add `PortUtil` class.

## 1.1.0
- 1.Add UseDataReceived method use to trigger DataReceived event.
- 2.The read metnod can be used to end character.
- 3.Add sleep time when try read data.
- 3.Add sleep time when try read data.

## 1.0.1
- 1.Fix ctor and comments.

## 1.0.0
- 1.The first version release.
10 changes: 10 additions & 0 deletions src/GodSharp.SerialPort/GodSharp.SerialPort.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,24 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\GodSharp.Shared\Extension\ByteExtension.cs">
<Link>Extension\ByteExtension.cs</Link>
</Compile>
<Compile Include="..\GodSharp.Shared\Extension\StringExtension.cs">
<Link>Extension\StringExtension.cs</Link>
</Compile>
<Compile Include="..\GodSharp.Shared\SerialPort\DataFormat.cs">
<Link>DataFormat.cs</Link>
</Compile>
<Compile Include="..\GodSharp.Shared\SerialPort\GodSerialPort.cs">
<Link>GodSerialPort.cs</Link>
</Compile>
<Compile Include="..\GodSharp.Shared\Util\PortUtil.cs">
<Link>Util\PortUtil.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
Expand Down
6 changes: 5 additions & 1 deletion src/GodSharp.SerialPort/GodSharp.SerialPort.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>GodSharp.SerialPort</id>
<version>1.1.0</version>
<version>1.1.1</version>
<title>GodSharp.SerialPort</title>
<authors>seayxu</authors>
<owners>seayxu</owners>
Expand All @@ -14,6 +14,10 @@
<releaseNotes>
An easy-to-use .NET SerialPort class.(.NET Framework >= 3.5)

1.1.1
- 1.Add constructor and change the constructor signature.
- 2.Add PortUtil class.

1.1.0
- 1.Add UseDataReceived method use to trigger DataReceived event.
- 2.The read metnod can be used to end character.
Expand Down
32 changes: 32 additions & 0 deletions src/GodSharp.Shared/Extension/ByteExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections.Generic;

namespace GodSharp.Extension
{
/// <summary>
/// Byte extension methods class.
/// </summary>
public static class ByteExtension
{
/// <summary>
/// Bytes to hexadecimal.
/// </summary>
/// <param name="bytes">The byte array.</param>
/// <param name="separator">The separator,default is space</param>
/// <returns>String of hex.</returns>
public static string ToHexString(this byte[] bytes,string separator=" ")
{
if (bytes==null||bytes.Length<1)
{
return null;
}

List<string> list = new List<string>();
foreach (byte b in bytes)
{
list.Add(b.ToString("X2"));
}

return string.Join(separator, list.ToArray());
}
}
}
28 changes: 28 additions & 0 deletions src/GodSharp.Shared/Extension/StringExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;

namespace GodSharp.Extension
{
/// <summary>
/// String extension methods class.
/// </summary>
public static class StringExtension
{
/// <summary>
/// Hexadecimal string to an byte array.
/// </summary>
/// <param name="hex">The hex string.</param>
/// <returns>An byte array.</returns>
public static byte[] HexToByte(this string hex)
{
// remove space
hex = hex.Replace(" ", "");

byte[] bytes = new byte[hex.Length / 2];
for (int i = 0; i < hex.Length; i += 2)
{
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
}
return bytes;
}
}
}
3 changes: 3 additions & 0 deletions src/GodSharp.Shared/GodSharp.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
<Import_RootNamespace>GodSharp</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Extension\ByteExtension.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extension\StringExtension.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SerialPort\DataFormat.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SerialPort\GodSerialPort.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Util\PortUtil.cs" />
</ItemGroup>
</Project>
Loading

0 comments on commit d960761

Please sign in to comment.