資源簡介
基于C#語言的上位機串口通信助手的源代碼,非常適合初學者,功能齊全,可以自動識別有效的COM端口,也支持手動輸入端口號,設置波特率、數據位、停止位、校驗位,可以選擇接受的數據格式(16進制和字符串格式),可實現定時向串口發送數據,代碼簡單容易理解,支持二次開發編程。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
namespace?_01_SerialPort
{
????public?enum?InitialCrcValue?{?Zeros?NonZero1?=?0xffff?NonZero2?=?0x1D0F?}
????public?class?Crc16Ccitt
????{
????????const?ushort?poly?=?0x1021;
????????ushort[]?table?=?new?ushort[256];
????????ushort?initialValue?=?0;
????????public?ushort?ComputeChecksum(byte[]?bytes)
????????{
????????????ushort?crc?=?this.initialValue;
????????????for?(int?i?=?0;?i?????????????{
????????????????crc?=?(ushort)((crc?<8)?^?table[((crc?>>?8)?^?(0xff?&?bytes[i]))]);
????????????}
????????????return?crc;
????????}
????????public?byte[]?ComputeChecksumBytes(byte[]?bytes)
????????{
????????????ushort?crc?=?ComputeChecksum(bytes);
????????????return?new?byte[]?{?(byte)(crc?>>?8)?(byte)(crc?&?0x00ff)?};
????????}
????????public?Crc16Ccitt(InitialCrcValue?initialValue)
????????{
????????????this.initialValue?=?(ushort)initialValue;
????????????ushort?temp?a;
????????????for?(int?i?=?0;?i?????????????{
????????????????temp?=?0;
????????????????a?=?(ushort)(i?<8);
????????????????for?(int?j?=?0;?j?8;?j++)
????????????????{
????????????????????if?(((temp?^?a)?&?0x8000)?!=?0)
????????????????????{
????????????????????????temp?=?(ushort)((temp?<1)?^?poly);
????????????????????}
????????????????????else
????????????????????{
????????????????????????temp?<<=?1;
????????????????????}
????????????????????a?<<=?1;
????????????????}
????????????????table[i]?=?temp;
????????????}
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????..A..H.?????62976??2018-06-21?21:48??串口\.vs\01_SerialPort\v14\.suo
????..A..H.?????45056??2017-10-26?09:39??串口\.vs\01_SerialPort\v15\.suo
?????文件??????????0??2017-10-26?09:39??串口\.vs\01_SerialPort\v15\Server\sqlite3\db.lock
?????文件?????512000??2017-10-26?09:39??串口\.vs\01_SerialPort\v15\Server\sqlite3\storage.ide
?????文件???????3968??2018-06-04?16:55??串口\01_SerialPort\01_SerialPort.csproj
?????文件??????25600??2018-06-21?21:26??串口\01_SerialPort\bin\Debug\01_SerialPort.exe
?????文件??????42496??2018-06-21?21:26??串口\01_SerialPort\bin\Debug\01_SerialPort.pdb
?????文件??????21680??2018-06-21?21:26??串口\01_SerialPort\bin\Debug\01_SerialPort.vshost.exe
?????文件????????490??2016-07-16?19:44??串口\01_SerialPort\bin\Debug\01_SerialPort.vshost.exe.manifest
?????文件???????1609??2018-06-04?16:55??串口\01_SerialPort\Crc16Ccitt.cs
?????文件??????29444??2018-06-21?21:26??串口\01_SerialPort\Form1.cs
?????文件??????25687??2018-06-21?21:09??串口\01_SerialPort\Form1.Designer.cs
?????文件???????5814??2018-06-21?21:09??串口\01_SerialPort\Form1.resx
?????文件?????????42??2017-10-26?09:39??串口\01_SerialPort\obj\Debug\01_SerialPort.csproj.CoreCompileInputs.cache
?????文件???????7430??2018-06-21?21:26??串口\01_SerialPort\obj\Debug\01_SerialPort.csproj.FileListAbsolute.txt
?????文件????????905??2018-06-21?21:09??串口\01_SerialPort\obj\Debug\01_SerialPort.csproj.GenerateResource.Cache
?????文件???????1758??2018-06-14?21:37??串口\01_SerialPort\obj\Debug\01_SerialPort.csprojResolveAssemblyReference.cache
?????文件??????25600??2018-06-21?21:26??串口\01_SerialPort\obj\Debug\01_SerialPort.exe
?????文件??????42496??2018-06-21?21:26??串口\01_SerialPort\obj\Debug\01_SerialPort.pdb
?????文件???????1230??2018-06-20?14:17??串口\01_SerialPort\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6888??2018-06-14?21:34??串口\01_SerialPort\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????4608??2015-04-14?11:51??串口\01_SerialPort\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll
?????文件????????180??2018-06-21?21:09??串口\01_SerialPort\obj\Debug\_01_SerialPort.Form1.resources
?????文件????????180??2018-06-04?16:55??串口\01_SerialPort\obj\Debug\_01_SerialPort.Properties.Resources.resources
?????文件????????495??2015-03-18?08:57??串口\01_SerialPort\Program.cs
?????文件???????1358??2015-03-18?08:57??串口\01_SerialPort\Properties\AssemblyInfo.cs
?????文件???????2868??2015-03-18?08:57??串口\01_SerialPort\Properties\Resources.Designer.cs
?????文件???????5612??2015-03-18?08:57??串口\01_SerialPort\Properties\Resources.resx
?????文件???????1114??2015-03-18?08:57??串口\01_SerialPort\Properties\Settings.Designer.cs
?????文件????????249??2015-03-18?08:57??串口\01_SerialPort\Properties\Settings.settings
............此處省略151個文件信息
評論
共有 條評論