基于RFID的防伪系统设计
基于RFID的防偽系統(tǒng)設(shè)計(jì)
近幾年來(lái),由于茶葉質(zhì)量安全危機(jī)頻繁發(fā)生,引起了廣大消費(fèi)者的關(guān)注,如何對(duì)茶葉質(zhì)量安全進(jìn)行有效追蹤與追溯,已成為一個(gè)急需解決的課題。利用RFID技術(shù)建立一個(gè)茶葉質(zhì)量安全追蹤與追溯體系,一旦發(fā)現(xiàn)茶葉存在質(zhì)量安全的問(wèn)題,通過(guò)RFID讀寫器讀寫貼合在茶葉產(chǎn)品上帶有唯一標(biāo)識(shí)的RFID標(biāo)簽,結(jié)合茶葉產(chǎn)品數(shù)據(jù)庫(kù)就可以對(duì)茶葉質(zhì)量進(jìn)行跟蹤與追溯,查清哪個(gè)環(huán)節(jié)出了問(wèn)題。本文主要針對(duì)茶葉質(zhì)量安全進(jìn)行追蹤與追溯研究。
關(guān)鍵詞: RFID,防偽系統(tǒng),茶葉溯源,數(shù)據(jù)庫(kù)
Fragile RFID-based security systems tea
IN recent years, due to the frequent occurrence of tea quality and safety crisis, causing the concerns of consumers, how to tea quality and safety for effective tracking and tracing, has become an urgent problem to be solved. The use of RFID technology to establish a tea quality and safety tracking and tracing system, once found in tea quality and safety issues, through the RFID reader to read and write RFID tags with lamination uniquely identified on tea products, tea products combine the database can tea quality tracking and tracing, to identify which aspects of a problem. Tracking and tracing paper mainly research on tea quality and safety.
Key Words: RFID,Security systems,Origin of tea,database
論文+代碼下載地址:下載地址
目錄:
第1章 緒論 1
1.1 研究背景 1
1.2 研究意義 1
1.3 研究?jī)?nèi)容 2
第2章 茶葉物流追溯系統(tǒng)支撐技術(shù) 3
2.1 RFID技術(shù) 3
2.1.1 RFID系統(tǒng)工作原理 3
2.1.2 RFID標(biāo)簽 3
2.1.3 讀寫器 4
2.1.4 RFID技術(shù)特點(diǎn)與優(yōu)勢(shì) 5
2.2 Visual Studio技術(shù) 5
2.3 My Sql 5
2.4 c#語(yǔ)言 6
第3章 茶葉防偽的數(shù)據(jù)庫(kù)的設(shè)計(jì) 7
3.1 數(shù)據(jù)庫(kù) 7
第4章 基于茶葉防偽的系統(tǒng)設(shè)計(jì) 9
4.1 功能設(shè)計(jì) 9
4.2 概要設(shè)計(jì) 9
4.3 詳細(xì)設(shè)計(jì) 10
4.3.1 茶葉種植 10
4.3.2 茶葉采摘 10
4.3.3 茶葉加工 11
4.3.4 茶葉銷售 11
4.4 用戶界面邏輯設(shè)計(jì) 12
4.4.1 茶葉采摘錄入界面 12
4.4.2 用戶查詢防偽界面 13
第5章 系統(tǒng)測(cè)試 14
5.1 完成采摘環(huán)節(jié) 14
5.2 完成所有環(huán)節(jié) 15
5.3 假冒偽劣產(chǎn)品 16
結(jié)論 17
參考文獻(xiàn) 18
致謝 19
附錄1 部分關(guān)鍵源碼及解釋 20
附錄2 翻譯 31
RFID技術(shù)
什么是RFID,RFID就是一種利用空間耦合來(lái)自動(dòng)實(shí)現(xiàn)捕獲目標(biāo)對(duì)象并且獲得相關(guān)數(shù)據(jù)的技術(shù),如果你的標(biāo)簽發(fā)出的頻率在讀卡器的接收頻率范圍內(nèi),就能成功讀取信息。比如我們?nèi)粘3鋈氲男^(qū)大門中就有使用到。RFID與讀卡器的結(jié)合不需要硬件上的連接,也就是說(shuō)不需要焊在一起等,也不需要像二維碼,需要攝像頭掃描清楚二維碼的圖像才能成功掃描,RFID發(fā)出的無(wú)線電就像無(wú)孔不入的信息流,只要有配對(duì)的讀卡器,像淘寶上買的手持式讀卡器,讀寫距離可以延伸到幾百米,實(shí)用性很強(qiáng)操作方便。
2.1.1 RFID系統(tǒng)工作原理
RFID系統(tǒng)主要是由電子標(biāo)簽、讀寫器還有PC終端三大部分組成。工作原理就是我們物理中學(xué)習(xí)到的:rfid標(biāo)簽與讀卡器主要通過(guò)磁場(chǎng)來(lái)互相傳遞能量和相關(guān)信息,當(dāng)RFID標(biāo)簽進(jìn)入磁場(chǎng),讀寫器發(fā)出的操作需求,RFID可以自行接收,此時(shí)感應(yīng)線圈將被激活,同時(shí)RFID將信息傳到讀卡器再通過(guò)讀卡器翻譯后發(fā)到電腦端,便于操作人員使用
2.1.2 RFID標(biāo)簽
RFID標(biāo)簽就是向讀卡器發(fā)射信號(hào)的,電子標(biāo)簽由天線、線圈、存儲(chǔ)器和集成電路組成,電子標(biāo)簽最大的特點(diǎn)莫過(guò)于他的唯一性,這也是他能夠成功防偽的特點(diǎn)之一。下面我們將從三個(gè)部分來(lái)說(shuō)說(shuō)這個(gè)RFID標(biāo)簽
(1)主動(dòng)式標(biāo)簽。何為主動(dòng)式標(biāo)簽,就是自己能提供能量發(fā)送信號(hào)。并且由于這個(gè)特點(diǎn),他的讀寫距離遠(yuǎn),但是呢,沒(méi)有十全十美的東西,這種標(biāo)簽也是如此,因?yàn)楸旧韼в须娫?#xff0c;一旦電源耗盡電量,他的所有優(yōu)點(diǎn)就會(huì)變成缺點(diǎn),這樣一來(lái),隨著使用次數(shù)越來(lái)越多,傳輸距離也有可能從幾百米縮短到幾米甚至幾厘米。這樣就太不穩(wěn)定了。
(2)被動(dòng)式標(biāo)簽。被動(dòng)式標(biāo)簽相對(duì)于上面那種最大的區(qū)別就是沒(méi)有電源,所以在使用的時(shí)候,就需要外界給予刺激,讀卡器就承擔(dān)了這份工作。被動(dòng)式標(biāo)簽的最大特點(diǎn)就是耐用,可以說(shuō)這是一個(gè)永久牌的標(biāo)簽,只要沒(méi)有特殊原因?qū)е聵?biāo)簽損壞,他就還能用。人無(wú)完人,他也是有缺點(diǎn)的,相較于前者,他并沒(méi)有那么長(zhǎng)的讀寫距離。信號(hào)強(qiáng)點(diǎn),可以讀的遠(yuǎn)一點(diǎn),信號(hào)弱的話,距離就會(huì)更近。
(3)半主動(dòng)式標(biāo)簽。第三種標(biāo)簽叫做半主動(dòng)式標(biāo)簽,他是比較中肯的一款產(chǎn)品,集聚了上面兩款的優(yōu)點(diǎn),既有電源,使得讀寫距離比被動(dòng)式遠(yuǎn),又耐用,這樣比較中肯的產(chǎn)品也深受企業(yè)家的喜愛(ài),像我們圖書館,宿舍門禁實(shí)用的門禁卡,多數(shù)使用的就是這一種標(biāo)簽。
2.1.3 讀寫器
讀寫器就是與標(biāo)簽配套使用的讀取標(biāo)簽信息的工具。讀取到信息后,再將翻譯后的信息發(fā)送到電腦端,讀寫器既能讀,也可以寫。讀寫器一般是由天線、射頻模塊和讀寫模塊組成。除此之外,讀寫器還分為固定式讀寫器和手持式讀寫器兩種,一般來(lái)說(shuō),手持式使用更加方便,但是制作成本更大,也是的價(jià)格略高,在某寶上,固定式讀寫器只需一兩百,而手持式至少上千。本文所使用的是固定式讀寫器ER302NFC讀寫器。ER302和電腦是通過(guò)USB數(shù)據(jù)線連接的。也就是說(shuō),電腦端發(fā)送指令給讀卡器,讀卡器再發(fā)送指令給RFID標(biāo)簽,最后再返回結(jié)果給電腦端。如果電腦端沒(méi)有給讀卡器發(fā)送指令。讀卡器便不會(huì)工作,比如讀卡,寫卡等等。
2.1.4 RFID技術(shù)特點(diǎn)與優(yōu)勢(shì)
RFID技術(shù)是近幾年比較盛行的,用讀卡器讀取標(biāo)簽很方便,三歲兒童也可以完成,只要與讀卡器在一定的距離范圍內(nèi)即可識(shí)別,不需要像條形碼或者二維碼一樣對(duì)準(zhǔn)取景入框。并且,相比較條形碼來(lái)說(shuō),標(biāo)簽不僅是可以讀取信息還可以寫。對(duì)比之前的那些防偽方法,有點(diǎn)真是有過(guò)之而無(wú)不及。下面我們將從四個(gè)方面來(lái)分析RFID技術(shù)到底有哪些優(yōu)點(diǎn),也對(duì)我們?yōu)槭裁匆x取它來(lái)進(jìn)行防偽來(lái)進(jìn)行解釋。
(1)易讀:RFID標(biāo)簽不需要與讀卡器進(jìn)行實(shí)物上的連接,只需在讀卡范圍內(nèi),或者這樣說(shuō),讀卡器在讀取信息的時(shí)候,也可以將標(biāo)簽遮蓋,這樣也能有效讀取。以上我們討論的三種標(biāo)簽的第一種,他自己具有電源,所以距離遠(yuǎn)。即使是后面兩種標(biāo)簽也比條形碼和二維碼來(lái)得遠(yuǎn)。在茶葉加工后入庫(kù)時(shí),操作員工也可以一次性讀取比較多的標(biāo)簽,這樣既能縮短時(shí)間,提高效率,還能便于管理。
(2)唯一性:我們通常買東西后會(huì)刷刷二維碼,接著打開(kāi)一個(gè)網(wǎng)頁(yè)或者一行字,其實(shí)二維碼很容易復(fù)制,如果黑心商家將假冒的產(chǎn)品每個(gè)都貼上相同的二維碼,在制作一個(gè)網(wǎng)頁(yè)。消費(fèi)者在掃瞄二維碼后成功打開(kāi)網(wǎng)頁(yè),網(wǎng)頁(yè)上文字顯示下產(chǎn)品的真實(shí)性,就很容易欺騙到消費(fèi)者。而RFID標(biāo)簽,在設(shè)計(jì)的時(shí)候就已保證他自身的唯一性,且具有唯一的卡號(hào)。正品商家在自家網(wǎng)站上建立好完整的產(chǎn)品信息庫(kù),消費(fèi)者購(gòu)買后通過(guò)掃描標(biāo)簽,即可知道產(chǎn)品的真?zhèn)尾⒌玫较胍男畔ⅰ?br /> (3)范圍廣:買過(guò)有二維碼標(biāo)簽的人都知道,一旦不小心將物品弄臟,再要掃描二維碼就不容易了,而RFID標(biāo)簽。及時(shí)在有水,煙的情況下,仍舊能有效讀取。這就決定了RFID標(biāo)簽的使用防偽更加廣。不僅是安靜潔凈的房間里,在臟兮兮的地方也能使用,真是能屈能伸啊。
(4)實(shí)時(shí):操作人員在錄入信息的時(shí)候可以實(shí)時(shí)動(dòng)態(tài)讀取和錄入。操作效率高,節(jié)約時(shí)間和人力。
本系統(tǒng)是基于RFID的茶葉防偽的從茶園到茶杯的一系列溯源追蹤。主要調(diào)查內(nèi)容包括茶葉種植、采摘、加工、包裝、物流運(yùn)輸、經(jīng)銷商、零售價(jià)等。通過(guò)不同階段掃描標(biāo)簽,不同種類的數(shù)據(jù)都被整合到后臺(tái)數(shù)據(jù)庫(kù),通過(guò)用戶界面呈現(xiàn)出來(lái)。管理員可以根據(jù)現(xiàn)實(shí)情況對(duì)茶葉制作等相關(guān)數(shù)據(jù)的修改和更新。用戶在pc端可通過(guò)讀卡器讀取rfid標(biāo)簽讀取每個(gè)階段的信息。
系統(tǒng)展示
部分代碼
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;using System.Runtime.InteropServices;
using MySql.Data.MySqlClient;namespace Mifare1K
{public partial class Mifare_1K : Form{[DllImport("kernel32.dll")]static extern void Sleep(int dwMilliseconds);[DllImport("MasterRD.dll")]static extern int lib_ver(ref uint pVer);[DllImport("MasterRD.dll")]static extern int rf_init_com(int port, int baud);[DllImport("MasterRD.dll")]static extern int rf_ClosePort();[DllImport("MasterRD.dll")]static extern int rf_antenna_sta(short icdev, byte mode);[DllImport("MasterRD.dll")]static extern int rf_init_type(short icdev, byte type);[DllImport("MasterRD.dll")]static extern int rf_request(short icdev, byte mode, ref ushort pTagType);[DllImport("MasterRD.dll")]static extern int rf_anticoll(short icdev, byte bcnt, IntPtr pSnr, ref byte pRLength);[DllImport("MasterRD.dll")]static extern int rf_select(short icdev, IntPtr pSnr, byte srcLen, ref sbyte Size);[DllImport("MasterRD.dll")]static extern int rf_halt(short icdev);[DllImport("MasterRD.dll")]static extern int rf_M1_authentication2(short icdev, byte mode, byte secnr, IntPtr key);[DllImport("MasterRD.dll")]static extern int rf_M1_initval(short icdev, byte adr, Int32 value);[DllImport("MasterRD.dll")]static extern int rf_M1_increment(short icdev, byte adr, Int32 value);[DllImport("MasterRD.dll")]static extern int rf_M1_decrement(short icdev, byte adr, Int32 value);[DllImport("MasterRD.dll")]static extern int rf_M1_readval(short icdev, byte adr, ref Int32 pValue);[DllImport("MasterRD.dll")]static extern int rf_M1_read(short icdev, byte adr, IntPtr pData, ref byte pLen);[DllImport("MasterRD.dll")]static extern int rf_M1_write(short icdev, byte adr, IntPtr pData);[DllImport("MasterRD.dll")]static extern int rf_ul_select(short icdev, IntPtr pSnr, ref byte pRLength);[DllImport("MasterRD.dll")]static extern int rf_ul_write(short icdev, byte page, IntPtr pData);[DllImport("MasterRD.dll")]static extern int rf_beep(short icdev, char msec);//bool bConnectedDevice;/*是否連接上設(shè)備*/static char[] hexDigits = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};public static byte GetHexBitsValue(byte ch){byte sz = 0;if (ch <= '9' && ch >= '0')sz = (byte)(ch - 0x30);if (ch <= 'F' && ch >= 'A')sz = (byte)(ch - 0x37);if (ch <= 'f' && ch >= 'a')sz = (byte)(ch - 0x57);return sz;}//#region byteHEX/// <summary>/// 單個(gè)字節(jié)轉(zhuǎn)字字符./// </summary>/// <param name="ib">字節(jié).</param>/// <returns>轉(zhuǎn)換好的字符.</returns>public static String byteHEX(Byte ib){String _str = String.Empty;try{char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A','B', 'C', 'D', 'E', 'F' };char[] ob = new char[2];ob[0] = Digit[(ib >> 4) & 0X0F];ob[1] = Digit[ib & 0X0F];_str = new String(ob);}catch (Exception){new Exception("對(duì)不起有錯(cuò)。");}return _str;}#endregionpublic static string ToHexString(byte[] bytes){String hexString = String.Empty;for (int i = 0; i < bytes.Length; i++)hexString += byteHEX(bytes[i]);return hexString;}public static byte[] ToDigitsBytes(string theHex){byte[] bytes = new byte[theHex.Length / 2 + (((theHex.Length % 2) > 0) ? 1 : 0)];for (int i = 0; i < bytes.Length; i++){char lowbits = theHex[i * 2];char highbits;if ((i * 2 + 1) < theHex.Length)highbits = theHex[i * 2 + 1];elsehighbits = '0';int a = (int)GetHexBitsValue((byte)lowbits);int b = (int)GetHexBitsValue((byte)highbits);bytes[i] = (byte)((a << 4) + b);}return bytes;}/**/public Mifare_1K(){InitializeComponent();}private void Mifare_1K_Load(object sender, EventArgs e){bConnectedDevice = false;tscbxPort.SelectedIndex = 2; // default port 3tscbxBaud.SelectedIndex = 6; // default 115200}private void tsbtnConnect_Click(object sender, EventArgs e){/*toolbar button[connect] clicked*/if (!bConnectedDevice){int port = 0;int baud = 0;int status;port = Convert.ToInt32(tscbxPort.Text);baud = Convert.ToInt32(tscbxBaud.Text);status = rf_init_com(port, baud);if (0 == status){tsbtnConnect.Text = "Disconnect";bConnectedDevice = true;MessageBox.Show("Connect device success!");}else{string strError;strError = "Connect device failed";bConnectedDevice = false;MessageBox.Show(strError, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);}}else {rf_ClosePort();bConnectedDevice = false;tsbtnConnect.Text = "Connect";}}//查找并讀取標(biāo)簽的7個(gè)字節(jié)UID號(hào)// This command include 2 commands: request and UL_Select,finally get the 7 bytes UID of Ultralight tag.private void btnUID7_Click(object sender, EventArgs e){short icdev = 0x0000;int status;// byte type = (byte)'A';//mifare one type is A 卡詢卡方式為Abyte mode = 0x26; // Request the card which is not halted.ushort TagType = 0;// byte bcnt = 0x04;//mifare 卡都用4, hold on 4IntPtr pSnr;byte len = 255;// sbyte size = 0;if (!bConnectedDevice){MessageBox.Show("Not connect to device!!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);return;}txtUID7.Text = "";pSnr = Marshal.AllocHGlobal(1024);for (int i = 0; i < 2; i++){// Sleep(50); // After open the antenna, it needs about 50ms delay before request.status = rf_request(icdev, mode, ref TagType);//搜尋沒(méi)有休眠的卡,request card if (status != 0)continue;status = rf_ul_select(icdev, pSnr, ref len);//防沖突得到返回卡的序列號(hào),--get the card UID if (status != 0)continue;byte[] szBytes = new byte[len];for (int j = 0; j < len; j++){szBytes[j] = Marshal.ReadByte(pSnr, j);}String m_cardNo = "";for (int q = 0; q < len; q++){m_cardNo += byteHEX(szBytes[q]);}txtUID7.Text = m_cardNo;//連接數(shù)據(jù)庫(kù)信息string constr = "server=localhost;User Id=root;password=root;Database=tea_info";using (MySqlConnection mycon = new MySqlConnection(constr)){mycon.Open();MySqlCommand mycmd = new MySqlCommand("select* from tea_table where UID = '" + txtUID7.Text + "'", mycon);using (MySqlDataReader reader = mycmd.ExecuteReader()){if (reader.Read()){/*從數(shù)據(jù)庫(kù)里查詢出和用戶相對(duì)應(yīng)的teaName的值 *reader.GetOrdinal("teaName")的作用是得到teaName的為這行數(shù)據(jù)中的第幾列,返回回值是int *reader.GetString()的作用是得到第幾列的值,返回類型為String. */string teaName = reader.GetString(reader.GetOrdinal("teaName"));string teaGrade = reader.GetString(reader.GetOrdinal("teaGrade"));string plantLoc = reader.GetString(reader.GetOrdinal("plantLoc"));string locWorker = reader.GetString(reader.GetOrdinal("locWorker"));string pickTime = reader.GetString(reader.GetOrdinal("pickTime"));string pickWorker = reader.GetString(reader.GetOrdinal("pickWorker"));string processNum = reader.GetString(reader.GetOrdinal("processNum"));string wdWorker = reader.GetString(reader.GetOrdinal("wdWorker"));string zqWorker = reader.GetString(reader.GetOrdinal("zqWorker"));string sqWorker = reader.GetString(reader.GetOrdinal("sqWorker"));string rhWorker = reader.GetString(reader.GetOrdinal("rhWorker"));string rkWorker = reader.GetString(reader.GetOrdinal("rkWorker"));string wareTime = reader.GetString(reader.GetOrdinal("wareTime"));string sellers = reader.GetString(reader.GetOrdinal("sellers"));string price = reader.GetString(reader.GetOrdinal("price"));String str = "該" + teaName + "是真貨\r\n\r\n";textBox1.AppendText(str);str = "茶葉等級(jí):" + teaGrade + "\r\n\r\n";textBox1.AppendText(str);str = "種植地:" + plantLoc + "\t種植員工:" + locWorker + "\r\n\r\n";textBox1.AppendText(str);str = "采摘時(shí)間:" + pickTime + "\t采摘員工:" + pickWorker + "\r\n\r\n";textBox1.AppendText(str);str = "加工批號(hào):" + processNum + "\r\n\r\n";textBox1.AppendText(str);str = "加工工序:\r\n\r\n";textBox1.AppendText(str);str = "\t萎凋\t負(fù)責(zé)員工:" + wdWorker + "\r\n\r\n";textBox1.AppendText(str);str = "\t做青\t負(fù)責(zé)員工:" + zqWorker + "\r\n\r\n";textBox1.AppendText(str);str = "\t殺青\t負(fù)責(zé)員工:" + sqWorker + "\r\n\r\n";textBox1.AppendText(str);str = "\t揉捻\t負(fù)責(zé)員工:" + rhWorker + "\r\n\r\n";textBox1.AppendText(str);str = "入庫(kù)時(shí)間:" + wareTime + "\t負(fù)責(zé)員工:" + rkWorker + "\r\n\r\n";textBox1.AppendText(str);str = "銷售商:" + sellers + "\r\n\r\n";textBox1.AppendText(str);str = "全國(guó)統(tǒng)一售價(jià):" + price;textBox1.AppendText(str);}else{ char msec = (char)80;//蜂鳴器響的時(shí)間,1個(gè)單位10msrf_beep(icdev, msec);textBox1.Text = "該產(chǎn)品是假貨";}}}break;}Marshal.FreeHGlobal(pSnr);}}
}
**參考文獻(xiàn):**```bash
[1] C程序設(shè)計(jì) 譚浩強(qiáng) 清華大學(xué)出版社
[2] C++程序設(shè)計(jì) 譚浩強(qiáng) 清華大學(xué)出版社
[3] ARM體系結(jié)構(gòu)與編程 杜春雷 清華大學(xué)出版社
[4] Windows程序設(shè)計(jì) 王艷平 人民郵電出版社
[5] 射頻識(shí)別系統(tǒng)設(shè)計(jì)、仿真與應(yīng)用 周曉光 人民郵電出版社
[6] 智能卡技術(shù)-----ic卡、rfid標(biāo)簽與物聯(lián)網(wǎng) 王愛(ài)英 清華大學(xué)出版社
[7] 超高頻識(shí)別技術(shù)與應(yīng)用 Dominique paret|安建平譯 電子工業(yè)出版社
總結(jié)
以上是生活随笔為你收集整理的基于RFID的防伪系统设计的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 英美大学放榜日期汇总!哪些国际学校是英美
- 下一篇: 温控自动烘焙系统的研究与实现