private void ReadSuica(Felica felica) { //読込む前にList初期化 this.ReadHistoryList = new List <ICCard>(); felica.Polling(0xFFFF); byte[] data = felica.IDm(); string idm = ""; for (int i = 0; i < data.Length; i++) { idm += data[i].ToString("X2"); } for (int i = 0; ; i++) { var history = felica.ReadWithoutEncryption(Suica.SERVICE_SUICA_HISTORY, i); if (history == null) { break; } AddHistryList(history, idm, new Suica()); } CalcuValue(); WriteUserHistoryDB(); }
/// <summary> /// カード読み込み処理 /// </summary> private void ReadCard() { using (Felica felica = new Felica()) { // 読み込みループ while (true) { try { felica.Polling((int)SystemCode.Any); string dataStr = string.Empty; byte[] idm = felica.IDm(); for (int i = 0; i < idm.Length; i++) { dataStr += idm[i].ToString("X2"); } if (!lastReadIdm.Equals(dataStr)) { lastReadIdm = dataStr; ReadCompleteNotify(ReadStatus.COMPLETE, dataStr); //Console.WriteLine(MethodBase.GetCurrentMethod().Name + ", IDm(" + idm + ")"); } } catch { //ReadCompleteNotify(ReadStatus.NO_READ, null); } System.Threading.Thread.Sleep(oneSecond); } } }
private static void Main(string[] args) { Felica felica = new Felica(); try { felica.Polling((int)SystemCode.FelicaLiteS); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } Console.WriteLine("IDm : " + BitConverter.ToString(felica.IDm())); Console.WriteLine(); if (args.Length == 1 && args[0].Equals("DUMP", StringComparison.CurrentCultureIgnoreCase)) { Dump(ref felica); } else if (args.Length == 1 && args[0].Equals("READ", StringComparison.CurrentCultureIgnoreCase)) { Read(ref felica); } else if (args.Length == 2 && args[0].Equals("WRITE", StringComparison.CurrentCultureIgnoreCase)) { Write(ref felica, args[1]); } else { PrintHelp(); } felica.Dispose(); }
private static void PrintIDm(Felica f) { // 共通ポーリング実行 f.Polling((int)SystemCode.Common); // IDm を取得する var idm = f.IDm(); // バイト数を念のため確認する Console.WriteLine(string.Format("Bytes: {0}", idm.Length)); // IDm をプリントする Console.Write("IDm: "); foreach (var b in idm) { Console.Write(string.Format("{0:X2}", b)); } Console.Write("\r\n"); }
/// <summary> /// IDm取得メソッド /// </summary> /// <returns></returns> public string getID() { try { using (Felica felica = new Felica()) { felica.Polling(0xFFFF); byte[] data = felica.IDm(); id = ""; for (int i = 0; i < data.Length; i++) { id += data[i].ToString("X2"); } } } catch (Exception) { //MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } return(id); }
static void Main(string[] args) { try { System.Net.HttpListener server = new System.Net.HttpListener(); // Address, Port を指定 server.Prefixes.Add("http://localhost:8000/"); // サーバ起動 server.Start(); while (true) { // 接続待ち System.Net.HttpListenerContext context = server.GetContext(); // 応答作成 System.Net.HttpListenerResponse response = context.Response; // JavaScriptエラー回避 response.Headers.Add("Access-Control-Allow-Origin", "*"); bool readSuccess = false; byte[] idm = null; if (System.Text.RegularExpressions.Regex.IsMatch(context.Request.Url.ToString(), "http://localhost:8000/getIDmDummy\\?seed=.*")) { // 疑似IDm生成 idm = IDmDummy(context.Request.QueryString.Get("seed")); readSuccess = true; Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}]\t疑似IDm生成"); } else { try { // NFC読み込み Felica felica = new Felica(); felica.Polling((int)SystemCode.FelicaLiteS); idm = felica.IDm(); felica.Dispose(); readSuccess = true; Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}]\tカード読み取り成功"); } catch { Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}]\tカード読み取り失敗"); } } if (readSuccess) { // 読み取り成功 string idm_str = BitConverter.ToString(idm).Replace("-", "").ToLower(); idm = Encoding.UTF8.GetBytes(idm_str); response.StatusCode = 200; response.OutputStream.Write(idm, 0, idm.Length); response.Close(); } else { // 読み取り失敗 response.StatusCode = 500; response.Close(); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }