让知识更加联贯
让技术走进生活
我的博客
我的程序
我的网络
------
郑紫至
E-mail:zhengzizhi@yahoo.com.cn
智能通道系统
本系统全面地展示了
Socket
与多线程,数据库,工业上采用的
CRC
查表校验信息码
等综合技术的完整代码,从代码的角度展示了工控通讯的完整过程,本系统可以改装成
地铁、火车站、海关、商场、旅游景点,智能小区、大型集团公司,大型停车场,
等等需要刷卡通行智能验证平台,本系统使用了软终端从理论的角度模拟出单片机终
端设备的通讯过程。
开发工具
:Visual Studio 2008.NET(C#) + Microsoft SQL Server 2005
智能通道系统之
(2)
CRC16(0xA001)
1
.设计模式下的界面截图
2. MainForm.cs
:
//******************************************************************************************
//
作者 :郑紫至
//
创建日期:2008-03-14
//
邮件地址:zhengzizhi@mail.china.com
//
博客地址:http://hi.csdn.net/zhengzizhi
//
备注说明:欢迎大家转载我的博客内容,代码版权归本人所有,请保留此信息。
//******************************************************************************************
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
namespace
CRC16_0xA001_
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void btnOK_Click(object sender, EventArgs e)
{
const ushort polynomial = 0xA001;
ushort value;ushort temp;
for (ushort i = 0; i <= 0xFF; i++)
{
value = 0; temp = i;
for (byte j = 0; j < 8; j++)
{
if (((value ^ temp) & 0x0001) != 0)
{
value = (ushort)((value >> 1) ^ polynomial);
}
else
{
value >>= 1;
}
temp >>= 1;
}
if (i == 0xFF)
{
this.txtHigh8Bit.Text += "0x" + value.ToString("x4").Substring(0, 2).ToUpper() + " ";
this.txtLow8Bit.Text += "0x" + value.ToString("x4").Substring(2, 2).ToUpper() + " ";
}
else
{
this.txtHigh8Bit.Text += "0x" + value.ToString("x4").Substring(0, 2).ToUpper() + ",";
this.txtLow8Bit.Text += "0x" + value.ToString("x4").Substring(2, 2).ToUpper() + ",";
}
}
}
}
}
2. MainForm.Designer.cs:
namespace
CRC16_0xA001_
{
partial class MainForm
{
///<summary>
/// Required designer variable.
///</summary>
private System.ComponentModel.IContainer components = null;
///<summary>
/// Clean up any resources being used.
///</summary>
///<param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
Windows Form Designer generated code
///<summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///</summary>
private void InitializeComponent()
{
this.txtHigh8Bit = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.txtLow8Bit = new System.Windows.Forms.TextBox();
this.btnOK = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// txtHigh8Bit
//
this.txtHigh8Bit.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtHigh8Bit.Location = new System.Drawing.Point(3, 17);
this.txtHigh8Bit.Multiline = true;
this.txtHigh8Bit.Name = "txtHigh8Bit";
this.txtHigh8Bit.Size = new System.Drawing.Size(250, 403);
this.txtHigh8Bit.TabIndex = 0;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.txtHigh8Bit);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(256, 423);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Polynomial = 0xA001
高8位表"
;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.txtLow8Bit);
this.groupBox2.Location = new System.Drawing.Point(269, 12);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(256, 423);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Polynomial = 0xA001
低8位表"
;
//
// txtLow8Bit
//
this.txtLow8Bit.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtLow8Bit.Location = new System.Drawing.Point(3, 17);
this.txtLow8Bit.Multiline = true;
this.txtLow8Bit.Name = "txtLow8Bit";
this.txtLow8Bit.Size = new System.Drawing.Size(250, 403);
this.txtLow8Bit.TabIndex = 0;
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(231, 442);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(75, 23);
this.btnOK.TabIndex = 3;
this.btnOK.Text = "
生成(&P)"
;
this.btnOK.UseVisualStyleBackColor = true;
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// MainForm
//
this.AcceptButton = this.btnOK;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(540, 469);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "MainForm";
this.Text = "
生成CRC16的校验码表(Polynomial = 0xA001)"
;
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TextBox txtHigh8Bit;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.TextBox txtLow8Bit;
private System.Windows.Forms.Button btnOK;
}
}
CRC16(0xA001)
项目所有代码全部发布完毕(包括自动生成的代码)