godsharp - GodSharp.SerialPort 1.2.0.6
An easy-to-use .NET SerialPort Library.
PM> Install-Package GodSharp.SerialPort -Version 1.2.0.6 -Source https://www.myget.org/F/godsharp/api/v3/index.json
> nuget.exe install GodSharp.SerialPort -Version 1.2.0.6 -Source https://www.myget.org/F/godsharp/api/v3/index.json
> dotnet add package GodSharp.SerialPort --version 1.2.0.6 --source https://www.myget.org/F/godsharp/api/v3/index.json
source https://www.myget.org/F/godsharp/api/v3/index.json
nuget GodSharp.SerialPort ~> 1.2.0.6
Copy to clipboard
> choco install GodSharp.SerialPort --version 1.2.0.6 --source https://www.myget.org/F/godsharp/api/v2
Import-Module PowerShellGet
Register-PSRepository -Name "godsharp" -SourceLocation "https://www.myget.org/F/godsharp/api/v2"
Install-Module -Name "GodSharp.SerialPort" -RequiredVersion "1.2.0.6" -Repository "godsharp"
Copy to clipboard
GodSharp.SerialPort
An easy-to-use .NET SerialPort class.
Requirement
.NET Framework >= 3.5
Getting Started
- New instance GodSerialPort.
GodSerialPort serial = new GodSerialPort("COM1", 9600,0);
- Use
DataReceived
event with received data action:Action<byte[]>
.
Notice:This is not need when you read data by read method.
serial.UseDataReceived(true,(sp,bytes)=>{});
- Open SerialPort object.
serial.Open();
- Write/Send data.
byte[] bytes = new byte[]{31,32,33,34};
serial.Write(bytes);
serial.Write(bytes,offset:1,count:2);
serial.WriteHexString("7E 48 53 44");
serial.WriteAsciiString("ascii string");
- Read data.
byte[] bytes = serial.Read();
string stringAsciiOrHex = serial.ReadString();
Sample
class Program
{
static void Main(string[] args)
{
Console.Write("input serialport number(only 0-9):");
string read = Console.ReadLine();
bool flag = uint.TryParse(read, out uint num);
if (!flag)
{
Exit();
}
GodSerialPort gsp = new GodSerialPort("COM"+num, 9600,0);
gsp.UseDataReceived(true,(sp,bytes) => {
string buffer = string.Join(" ", bytes);
Console.WriteLine("receive data:" + buffer);
});
flag = gsp.Open();
if (!flag)
{
Exit();
}
Console.WriteLine("serialport opend");
Console.WriteLine("press any thing as data to send,press key 'q' to quit.");
string data = null;
while (data == null || data.ToLower()!="q")
{
if (!string.IsNullOrEmpty(data))
{
Console.WriteLine("send data:"+data);
gsp.WriteAsciiString(data);
}
data = Console.ReadLine();
}
}
static void Exit()
{
Console.WriteLine("press any key to quit.");
Console.ReadKey();
Environment.Exit(0);
}
}
Notes
1.2.0
- 1.support .NET Core 2.0.
1.1.2
- 1.Add GodSerialPort to event action as signature param for initial a list.
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.
1.0.1
- 1.Fix ctor and comments.
1.0.0
- 1.The first version release.
-
.NETFramework 3.5
-
.NETFramework 4.0
-
.NETFramework 4.5
-
.NETFramework 4.6
-
.NETFramework 4.7
-
.NETStandard 2.0
- System.IO.Ports (>= 4.5.0)
- .NETFramework 3.5: 3.5.0.0
- .NETFramework 4.0: 4.0.0.0
- .NETFramework 4.5: 4.5.0.0
- .NETFramework 4.6: 4.6.0.0
- .NETFramework 4.7: 4.7.0.0
- .NETStandard 2.0: 2.0.0.0
OwnersSeay |
Authorsseayxu |
Project URLhttps://github.com/godsharp/GodSharp.SerialPort |
LicenseMIT |
TagsGodSharp,GodSharp.SerialPort,SerialPort |
Info0 total downloads |
0 downloads for version 1.2.0.6 |
Download (50.98 KB) |
Found on the current feed only |
Package history
Version | Size | Last updated | Downloads | Mirrored? | |||
---|---|---|---|---|---|---|---|
1.2.0.6 | 50.98 KB | Tue, 07 May 2019 10:05:43 GMT | 0 | ||||
1.2.0.5 | 50.98 KB | Sun, 25 Nov 2018 10:00:42 GMT | 0 | ||||
1.2.0.5-preview1 | 51.15 KB | Sun, 25 Nov 2018 09:32:13 GMT | 0 | ||||
1.2.0.5-preview2 | 51.18 KB | Sun, 25 Nov 2018 09:47:38 GMT | 0 | ||||
1.2.0 | 50.91 KB | Tue, 13 Nov 2018 13:39:53 GMT | 0 | ||||
1.1.2 | 12.35 KB | Mon, 28 Aug 2017 12:08:10 GMT | 0 | ||||
1.1.1 | 12.54 KB | Tue, 18 Apr 2017 08:01:27 GMT | 0 |