台灣最大程式設計社群網站
線上人數
1091
 
會員總數:246691
討論主題:190104
歡迎您免費加入會員
討論區列表 >> C# >> 用C#建立一介面,經由RFID Reader讀取Mifare ISO14443A 卡片資料
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
用C#建立一介面,經由RFID Reader讀取Mifare ISO14443A 卡片資料
價值 : 150 QP  點閱數:2697 回應數:1
樓主

sfchang0731
門外漢
0 1
26 0
發送站內信

大家好,
現在我要用C#來建立一個介面,透由介面及RFID Reader來讀取Mifare裡的值。
參考Reader Device (RD300-H1-G)的文件及Code Sample,目前可以讀取到Mifare UID (STX, LEN, CMD, Data -> 0x20, 0x0A, 0x11)。

但進一步想要讀出Mifare Data >> 增加輸入值 Key Type(A/B), Load Key(FFFFFFFFFFFF), Sector(0-39), Block(0-3)
卻一直失敗。

輸入介面設計如圖


想請問,
1. 我該如何定義及抓取下拉式清單裡的值放到Writer Buffer裡?
2. 抓取的值都是String,要如何轉成byte型態送出去?
3. 如何針對"Load Key"來限制填入值必須12byte(e.g FFFFFFFFFFFF),不能多或少。只要不符合,"Get Data"按鍵是反白無法使用。

目前程式如下
*btnGetUID_Click 測試是可行的
*btnGetData_Click 是問題點

請各位提供小弟意見,解決目前疑惑點。謝謝大家的協助。

=====================================================================================
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;
using System.Threading;
using System.IO.Ports;
//using System.BitConverter;

namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}


MW_EasyPOD EasyPOD;

UInt32 dwResult, Index;

unsafe public void btnGetUID_Click(object sender, EventArgs e)
{
UInt32 uiLength, uiRead, uiResult ,uiWritten;
byte[] ReadBuffer = new byte[0x40];
byte[] WriteBuffer = new byte[] { 0x02, 0x01, 0x11 }; //Command {STX, LEN, CMD, DATA1, DATA2.....}

byte[] sResponse = null;
sResponse = new byte[21];

EasyPOD.VID = 0xe6a;
EasyPOD.PID = 0x317;
Index = 1;
uiLength = 64;

fixed (MW_EasyPOD* pPOD = &EasyPOD)
{

dwResult = PODfuncs.ConnectPOD(pPOD, Index);

if ((dwResult != 0))
{
MessageBox.Show("Reader Not Connected");
}
else
{
EasyPOD.ReadTimeOut = 200;
EasyPOD.WriteTimeOut = 200;

dwResult = PODfuncs.WriteData(pPOD, WriteBuffer, 4, &uiWritten); //Send a request command to reader
uiResult = PODfuncs.ReadData(pPOD, ReadBuffer, uiLength, &uiRead); //Read the response data from reader

txbGetUIDh.Text = BitConverter.ToString(ReadBuffer, 4, (Int32)uiRead).Replace("-", " "); //HEX
txbGetUIDd.Text = BitConverter.ToInt32(ReadBuffer, 4).ToString(); //DEC
}
dwResult = PODfuncs.ClearPODBuffer(pPOD);
dwResult = PODfuncs.DisconnectPOD(pPOD);
}
}

unsafe private void btnGetData_Click(object sender, EventArgs e)
{
UInt32 daLength, daRead, daResult, daWritten;
//UInt32 daKeyT, daLoadK, daSector, daBlock;
byte[] ReadBuffer = new byte[0x40];
byte[] WriteBuffer = new byte[] { 0x02, 0x04, 0x13, 0x00, 0x00, 0x01 }; //Command {STX, LEN, CMD, DATA1, DATA2.....}

//daKeyT = cmbKeyT.Text;
//daLoadK = txbLoadK.Text;
//daSector = cmbSector.Text;
//daBlock = cmbBlock.Text;

byte[] sResponse = null;
sResponse = new byte[21];
EasyPOD.VID = 0xe6a;
EasyPOD.PID = 0x317;
Index = 1;
daLength = 64;

fixed (MW_EasyPOD* pPOD = &EasyPOD)
{

dwResult = PODfuncs.ConnectPOD(pPOD, Index);

if ((dwResult != 0))
{
MessageBox.Show("Reader Not Connected");
}
else
{
EasyPOD.ReadTimeOut = 200;
EasyPOD.WriteTimeOut = 200;

dwResult = PODfuncs.WriteData(pPOD, WriteBuffer, 4, &daWritten); //Send a request command to reader
daResult = PODfuncs.ReadData(pPOD, ReadBuffer, daLength, &daRead); //Read the response data from reader

txbGetData.Text = BitConverter.ToString(ReadBuffer, 4, (Int32)daRead).Replace("-", " "); //HEX
//txbGetUIDd.Text = BitConverter.ToInt32(ReadBuffer, 4).ToString(); //DEC
}
dwResult = PODfuncs.ClearPODBuffer(pPOD);
dwResult = PODfuncs.DisconnectPOD(pPOD);
}

}

private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
}
}

===============================================================================================

搜尋相關Tags的文章: [ RFID ] ,
本篇文章發表於2017-09-27 15:11
1樓
回應

奶黃包子
檢舉此回應
因為手邊沒裝置測試大概看了一下


byte[] WriteBuffer = new byte[] { 0x02, 0x04, 0x13, 0x00, 0x00, 0x01 }; //Command {STX, LEN, CMD, DATA1, DATA2.....}
上面你要寫入6 byte的資料

dwResult = PODfuncs.WriteData(pPOD, WriteBuffer, 4, &daWritten); //Send a request command to reader
看一下.WriteData的定義
unsafe public static extern uint WriteData(MW_EasyPOD* pEasyPOD, byte[] lpBuffer, uint nNumberOfBytesToWrite, uint* lpNumberOfBytesWritten);
你定義了NumberOfBytesToWrite=4

資料長度目測不符,要不要試試看修改成6試看看
本篇文章回覆於2017-09-28 10:55
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.