⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smartcard.cs

📁 Smart Card communication include tx and rx
💻 CS
📖 第 1 页 / 共 3 页
字号:
            else
            {
                Sector = 16;
            }


            if (RdB.Text == "0")
            {
                Block = 0;
            }
            else if (RdB.Text == "1")
            {
                Block = 1;
            }
            else if (RdB.Text == "2")
            {
                Block = 2;
            }
            else if (RdB.Text == "3")
            {
                Block = 3;
            }
            else if (RdB.Text == "4")
            {
                Block = 4;
            }
            else
            {
                Block = 5;
            }

			if (Sector > 15)
			{
				MessageBox.Show("Invalid Sector, not larger than 15!!", "Message");
			}
			else if (Sector == 2)
			{
				MessageBox.Show("Sector2 is blocked","message");
			}
			else if (Block > 3)
			{
				MessageBox.Show("Invalid Block, not larger than 4!!", "Message");
			}
			else if (Block == 0 || Block == 3)
			{
				MessageBox.Show("Invalid Block, not larger than 4!!", "Message");
			}
			else
			{
				Block = Block + Sector * 4;
				RdD.Text = CardReaderWrapper.RdOneBlock((byte)Sector, (byte)Block);
            }
        }

        private void RdD_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

            int Sector = 0;
            int Block = 0;
            int condition;

            if (WrS.Text == "0")
            {
                Sector = 0;
            }
            else if (WrS.Text == "1")
            {
                Sector = 1;
            }
            else if (WrS.Text == "2")
            {
                Sector = 2;
            }
            else if (WrS.Text == "3")
            {
                Sector = 3;
            }
            else if (WrS.Text == "4")
            {
                Sector = 4;
            }
            else if (WrS.Text == "5")
            {
                Sector = 5;
            }
            else if (WrS.Text == "6")
            {
                Sector = 6;
            }
            else if (WrS.Text == "7")
            {
                Sector = 7;
            }
            else if (WrS.Text == "8")
            {
                Sector = 8;
            }
            else if (WrS.Text == "9")
            {
                Sector = 9;
            }
            else if (WrS.Text == "10")
            {
                Sector = 10;
            }
            else if (WrS.Text == "11")
            {
                Sector = 11;
            }
            else if (WrS.Text == "12")
            {
                Sector = 12;
            }
            else if (WrS.Text == "13")
            {
                Sector = 13;
            }
            else if (WrS.Text == "14")
            {
                Sector = 14;
            }
            else if (WrS.Text == "15")
            {
                Sector = 15;
            }
            else
            {
                Sector = 16;
            }


            if (WrB.Text == "0")
            {
                Block = 0;
            }
            else if (WrB.Text == "1")
            {
                Block = 1;
            }
            else if (WrB.Text == "2")
            {
                Block = 2;
            }
            else if (WrB.Text == "3")
            {
                Block = 3;
            }
            else if (WrB.Text == "4")
            {
                Block = 4;
            }
            else
            {
                Block = 5;
            }

            if (Sector > 15)
            {
                MessageBox.Show("Invalid Sector, not larger than 15!!", "Message");
			}
			else if (Sector == 2)
			{
				MessageBox.Show("Sector0/2 is blocked","message");
			}
            else if ( Block > 3)
            {
                MessageBox.Show("Invalid Block, not larger than 4!!", "Message");
			}
			else if (Block == 0 || Block == 3)
			{
				MessageBox.Show("Invalid Block, not larger than 4!!", "Message");
			}
            else
            {				
				Block = Block +Sector * 4;
				if (CardReaderWrapper.CheckCard())
                        {
                            if (/*Sector == 0 ||*/ Block == 0 || Block == 3)
                            {
                                MessageBox.Show("Memory is not valid to write", "Message");
                            }
                            else{
                                condition = CardReaderWrapper.WrOneBlock((byte)Sector, (byte)Block, WrD.Text);
                                if (condition == 1)
                                {
                                    //txtData.Text = "Complete!";
                                    //CardReaderWrapper.Beat();
                                    MessageBox.Show("Write Block Completed", "Message");
                                }
                                else
                                {
									if(condition==-1)
									{
										MessageBox.Show("Data too large!!", "Message");
									}
									else if(condition==-2)
									{
										MessageBox.Show("Request Failed!!", "Message");
									}
									else if(condition==-3)
									{
										MessageBox.Show("Card Collision!!", "Message");
									}
									else if(condition==-4)
									{
										MessageBox.Show("Select Card Fail!!", "Message");
									}
									else if(condition==-5)
									{
										MessageBox.Show("Authorized Fail!!", "Message");
									}
									else if(condition==-6)
									{
										MessageBox.Show("Write Error!!", "Message");
									}
									else
									{
										MessageBox.Show("Operation Error!!", "Message");
									}
                                }
                            }
                        }
            }
        }

        private void RdB_TextChanged(object sender, EventArgs e)
        {

        }

        private void RdS_TextChanged(object sender, EventArgs e)
        {

        }

        private void RBN_TextChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            // string tmp = null;
            string[] name = new string[2];
            string[] authur = new string[2];
            string[] isbn = new string[1];
            string[] title = new string[4];
            string[] publisher = new string[2];
            string[] year = new string[1];

            if (CardReaderWrapper.CheckCard())
            {
                name[0] = CardReaderWrapper.RdOneBlock(0, 1);
                name[1] = CardReaderWrapper.RdOneBlock(0, 2);
                RBN.Text = name[0] + "" + name[1];
                authur[0] = CardReaderWrapper.RdOneBlock(1, 5);
                authur[1] = CardReaderWrapper.RdOneBlock(1, 6);
                RBA.Text = authur[0] + "" + authur[1];
                isbn[0] = CardReaderWrapper.RdOneBlock(3, 13);
                RBI.Text = isbn[0];
                title[0] = CardReaderWrapper.RdOneBlock(3, 14);
                title[1] = CardReaderWrapper.RdOneBlock(4, 17);
                title[2] = CardReaderWrapper.RdOneBlock(4, 18);
                title[3] = CardReaderWrapper.RdOneBlock(5, 21);
                RBT.Text = title[0] + "" + title[1] + "" + title[2] + "" + title[3];
                publisher[0] = CardReaderWrapper.RdOneBlock(5, 22);
                publisher[1] = CardReaderWrapper.RdOneBlock(6, 25);
                RBP.Text = publisher[0] + "" + publisher[1];
                year[0] = CardReaderWrapper.RdOneBlock(6, 26);
                RBY.Text = year[0];
            }
            else{
                MessageBox.Show("Read Card Error!!", "Message");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string tmp = null;
            string[] name = new string[2];
            string[] authur = new string[2];
            string[] isbn = new string[1];
            string[] title = new string[4];
            string[] publisher = new string[2];
            string[] year = new string[1];

            int[] WriteErrorRecord = new int[12];

            if (CardReaderWrapper.CheckCard())
            {
					tmp = WBN.Text;
					if(tmp.Length>30)
					{
						MessageBox.Show("Invalid Name", "Message");
						return;
					}
                    else if (tmp.Length <= 16)
                    {
                        name[0] = tmp.Substring(0, tmp.Length);
                        name[1] = "";
                    }
                    else
                    {
                        name[0] = tmp.Substring(0, 16);
                        name[1] = tmp.Substring(16, tmp.Length - 16);
                    }

                    WriteErrorRecord[0] = CardReaderWrapper.WrOneBlock(0,1,name[0]);
                    WriteErrorRecord[1] = CardReaderWrapper.WrOneBlock(0,2,name[1]);
                    
					tmp = WBA.Text;
					if(tmp.Length>20)
					{
						MessageBox.Show("Invalid Authur", "Message");
						return;
					}
                    else if (tmp.Length <= 16)
                    {
                        authur[0] = tmp.Substring(0, tmp.Length);
                        authur[1] = "";
                    }
                    else
                    {
                        authur[0] = tmp.Substring(0, 16);
                        authur[1] = tmp.Substring(16, tmp.Length - 16);
                    }

                    WriteErrorRecord[2] = CardReaderWrapper.WrOneBlock(1,5,authur[0]);
                    WriteErrorRecord[3] = CardReaderWrapper.WrOneBlock(1,6,authur[1]);
                   
                    tmp = WBI.Text;
					if(tmp.Length>15)
					{
						MessageBox.Show("Invalid ISBN", "Message");
						return;
					}
                    else if (tmp.Length <= 16)
                    {
                        isbn[0] = tmp.Substring(0, tmp.Length);
                    }

                    WriteErrorRecord[4] = CardReaderWrapper.WrOneBlock(3, 13, isbn[0]);

				tmp = WBT.Text;
				if(tmp.Length>50)
				{
					MessageBox.Show("Invalid Title", "Message");
					return;
				}
				else if (tmp.Length <= 16)
                    {
                        title[0] = tmp.Substring(0, tmp.Length);
                        title[1] = "";
                        title[2] = "";
                        title[3] = "";
                    }
                    else if (tmp.Length <= 32)
                    {
                        title[0] = tmp.Substring(0, 16);
                        title[1] = tmp.Substring(16, tmp.Length - 16);
                        title[2] = "";
                        title[3] = "";

                    }
                    else if (tmp.Length <= 48)
                    {
                        title[0] = tmp.Substring(0, 16);
                        title[1] = tmp.Substring(16, 16);
                        title[2] = tmp.Substring(32, tmp.Length - 32);
                        title[3] = "";
                    }
                    else
                    {
                        title[0] = tmp.Substring(0, 16);
                        title[1] = tmp.Substring(16, 16);
                        title[2] = tmp.Substring(32, 16);
                        title[3] = tmp.Substring(48, tmp.Length - 48);
                    }

                    WriteErrorRecord[5] = CardReaderWrapper.WrOneBlock(3,14,title[0]);
                    WriteErrorRecord[6] = CardReaderWrapper.WrOneBlock(4,17,title[1]);
                    WriteErrorRecord[7] = CardReaderWrapper.WrOneBlock(4,18,title[2]);
                    WriteErrorRecord[8] = CardReaderWrapper.WrOneBlock(5,21,title[3]);

				tmp = WBP.Text;
				if(tmp.Length>20)
				{
					MessageBox.Show("Invalid Publisher", "Message");
					return;
				}
				else if (tmp.Length <= 16)
                    {
                        publisher[0] = tmp.Substring(0, tmp.Length);
                        publisher[1] = "";
                    }
                    else
                    {
                        publisher[0] = tmp.Substring(0, 16);
                        publisher[1] = tmp.Substring(16, tmp.Length - 16);
                    }

                    WriteErrorRecord[9] = CardReaderWrapper.WrOneBlock(5, 22, publisher[0]);
                    WriteErrorRecord[10] = CardReaderWrapper.WrOneBlock(6, 25, publisher[1]);

                    tmp = WBY.Text;

				if(tmp.Length>5)
				{
					MessageBox.Show("Invalid Year", "Message");
					return;
				}
				else if (tmp.Length <= 16)
                    {
                        year[0] = tmp.Substring(0, tmp.Length);
                    }

                    WriteErrorRecord[11] = CardReaderWrapper.WrOneBlock(6, 26, year[0]);
                //}
					int	WriteSuccessed = 0;
                    for (int i = 0; i <= 11; i++)
                    {
						if (WriteErrorRecord[i] != 1)
						{
							MessageBox.Show("Write Data Error!!", "Message");
							WriteSuccessed++;
						}
                    }
				if(WriteSuccessed ==0 )
				{
					MessageBox.Show("Write Completed","Message");
				}

            }
        }

        private void WRP_TextChanged(object sender, EventArgs e)
        {

        }

		private void WrB_TextChanged(object sender, System.EventArgs e)
		{
		
		}





	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -