-
大小: 263KB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2021-05-19
- 語(yǔ)言: 其他
- 標(biāo)簽: Serialport??串口通信??text文檔??
資源簡(jiǎn)介
通過(guò)Serialport空間自動(dòng)接收串口通信的數(shù)據(jù),有CRC16位數(shù)據(jù)校驗(yàn),可設(shè)置串口名,波特率等,主要是接收到的數(shù)據(jù)以追加的形式保存到了text文檔中,文檔以當(dāng)天日期命名。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
namespace?CRC校驗(yàn)16位
{
????public?interface?ICRC
????{
????????long?Value
????????{
????????????get;
????????}
????????void?Reset();
????????void?Crc(int?bval);
????????void?Crc(byte[]?buffer);
????????void?Crc(byte[]?buf?int?off?int?len);
????}
????///??
????///?CRC16?的摘要說(shuō)明。?
????///? ?
????public?class?CRC16?:?ICRC
????{
????????#region?CRC?16?位校驗(yàn)表
????????///??
????????///?16?位校驗(yàn)表?Upper?表?
????????///? ?
????????public?ushort[]?uppercrctab?=?new?ushort[]?
????????{?
????????????0x00000x12310x24620x36530x48c40x5af50x6ca60x7e97?
????????????0x91880x83b90xb5ea0xa7db0xd94c0xcb7d0xfd2e0xef1f?
????????};
????????///??
????????///?16?位校驗(yàn)表?Lower?表?
????????///? ?
????????public?ushort[]?lowercrctab?=?new?ushort[]?
????????{?
????????????0x00000x10210x20420x30630x40840x50a50x60c60x70e7?
????????????0x81080x91290xa14a0xb16b0xc18c0xd1ad0xe1ce0xf1ef?
????????};
????????#endregion
????????ushort?crc?=?0;
????????///??
????????///?校驗(yàn)后的結(jié)果?
????????///? ?
????????public?long?Value
????????{
????????????get
????????????{
????????????????return?crc;
????????????}
????????????set
????????????{
????????????????crc?=?(ushort)value;
????????????}
????????}
????????///??
????????///?設(shè)置crc?初始值?
????????///? ?
????????public?void?Reset()
????????{
????????????crc?=?0;
????????}
????????///??
????????///?Crc16?
????????///? ?
????????///??
????????///??
????????public?void?Crc(ushort?ucrc?byte[]?buf)
????????{
????????????crc?=?ucrc;
????????????Crc(buf);
????????}
????????///??
????????///?Crc16?
????????///? ?
????????///??
????????public?void?Crc(int?bval)
????????{
????????????ushort?h?=?(ushort)((crc?>>?12)?&?0x0f);
????????????ushort?l?=?(ushort)((crc?>>?8)?&?0x0f);
????????????ushort?temp?=?crc;
????????????temp?=?(ushort)(((temp?&?0x00ff)?<8)?|?bval);
????????????temp?=?(ushort)(temp?^?(uppercrctab[(h?-?1)?+?1]?^?lowercrctab[(l?-?1)?+?1]));
????????????crc?=?temp;
????????}
????????///??
????????///?Crc16?
????????///? ?
????????///??
????????public?void?Crc(byte[]?buffer)
????????{
????????????Crc(buffer?0?buffer.Length);
????????}
????????///??
????????///?Crc16?
????????///? ?
????????///??
????????///??
????????///??
????????public?void?Crc(byte[]?buf?int?off?int?len)
????????{
????????????if?(buf?==?null)
????????????{
????????????????throw?new?ArgumentNullException(“buf“);
????????????}
????????????if?(off?0?||?len?0?||?off?+?len?>?buf.Length)
???
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????5632??2012-07-13?08:48??串口通訊測(cè)試\CRC校驗(yàn)16位\bin\Debug\app.publish\Application?Files\CRC校驗(yàn)16位_1_0_0_0\CRC校驗(yàn)16位.exe.deploy
?????文件???????7263??2012-07-13?08:48??串口通訊測(cè)試\CRC校驗(yàn)16位\bin\Debug\app.publish\Application?Files\CRC校驗(yàn)16位_1_0_0_0\CRC校驗(yàn)16位.exe.manifest
?????文件???????5367??2012-07-13?08:48??串口通訊測(cè)試\CRC校驗(yàn)16位\bin\Debug\app.publish\CRC校驗(yàn)16位.application
?????文件?????495024??2012-07-13?08:48??串口通訊測(cè)試\CRC校驗(yàn)16位\bin\Debug\app.publish\setup.exe
?????文件???????1649??2012-07-13?08:58??串口通訊測(cè)試\CRC校驗(yàn)16位\bin\Debug\CRC校驗(yàn)16位.application
?????文件???????5632??2012-07-13?08:58??串口通訊測(cè)試\CRC校驗(yàn)16位\bin\Debug\CRC校驗(yàn)16位.exe
?????文件???????3622??2012-07-13?08:58??串口通訊測(cè)試\CRC校驗(yàn)16位\bin\Debug\CRC校驗(yàn)16位.exe.manifest
?????文件??????15872??2012-07-13?08:58??串口通訊測(cè)試\CRC校驗(yàn)16位\bin\Debug\CRC校驗(yàn)16位.pdb
?????文件??????11608??2011-12-27?14:44??串口通訊測(cè)試\CRC校驗(yàn)16位\bin\Debug\CRC校驗(yàn)16位.vshost.exe
?????文件????????490??2010-03-17?22:39??串口通訊測(cè)試\CRC校驗(yàn)16位\bin\Debug\CRC校驗(yàn)16位.vshost.exe.manifest
?????文件???????4390??2012-07-13?08:58??串口通訊測(cè)試\CRC校驗(yàn)16位\CRC校驗(yàn)16位.csproj
?????文件????????451??2012-07-13?08:58??串口通訊測(cè)試\CRC校驗(yàn)16位\CRC校驗(yàn)16位.csproj.user
?????文件???????1668??2012-07-13?08:48??串口通訊測(cè)試\CRC校驗(yàn)16位\CRC校驗(yàn)16位_TemporaryKey.pfx
?????文件???????1649??2012-07-13?08:58??串口通訊測(cè)試\CRC校驗(yàn)16位\obj\x86\Debug\CRC校驗(yàn)16位.application
?????文件???????1618??2012-07-13?08:48??串口通訊測(cè)試\CRC校驗(yàn)16位\obj\x86\Debug\CRC校驗(yàn)16位.csproj.FileListAbsolute.txt
?????文件???????5632??2012-07-13?08:58??串口通訊測(cè)試\CRC校驗(yàn)16位\obj\x86\Debug\CRC校驗(yàn)16位.exe
?????文件???????3622??2012-07-13?08:58??串口通訊測(cè)試\CRC校驗(yàn)16位\obj\x86\Debug\CRC校驗(yàn)16位.exe.manifest
?????文件??????15872??2012-07-13?08:58??串口通訊測(cè)試\CRC校驗(yàn)16位\obj\x86\Debug\CRC校驗(yàn)16位.pdb
?????文件???????6001??2012-08-22?14:21??串口通訊測(cè)試\CRC校驗(yàn)16位\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????3483??2011-12-26?16:33??串口通訊測(cè)試\CRC校驗(yàn)16位\Program.cs
?????文件???????1370??2011-12-26?16:24??串口通訊測(cè)試\CRC校驗(yàn)16位\Properties\AssemblyInfo.cs
?????文件??????18432??2012-08-22?10:32??串口通訊測(cè)試\SerialportSample\bin\Debug\SerialportSample.exe
?????文件??????36352??2012-08-22?10:32??串口通訊測(cè)試\SerialportSample\bin\Debug\SerialportSample.pdb
?????文件??????11600??2012-08-22?14:21??串口通訊測(cè)試\SerialportSample\bin\Debug\SerialportSample.vshost.exe
?????文件????????490??2010-03-17?22:39??串口通訊測(cè)試\SerialportSample\bin\Debug\SerialportSample.vshost.exe.manifest
?????文件??????11702??2011-02-26?04:24??串口通訊測(cè)試\SerialportSample\Form1.cs
?????文件??????18276??2011-02-26?04:24??串口通訊測(cè)試\SerialportSample\Form1.Designer.cs
?????文件???????6011??2011-02-26?04:24??串口通訊測(cè)試\SerialportSample\Form1.resx
?????文件???????4440??2011-12-19?12:36??串口通訊測(cè)試\SerialportSample\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6399??2012-08-22?14:21??串口通訊測(cè)試\SerialportSample\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
............此處省略41個(gè)文件信息
評(píng)論
共有 條評(píng)論