Beispiel #1
0
        public void PrintSuicaInfo(SuicaServiceCode code)
        {
            felica.Polling((int)SystemCode.Suica);

            if (code == SuicaServiceCode.History)
            {
                for (int i = 0; ; i++)
                {
                    byte[] data = felica.ReadWithoutEncryption(0x090f, i);
                    if (data == null)
                    {
                        break;
                    }

                    Console.WriteLine("機器種別 : {0}", GetKikiShubetsu(data[0]));
                    Console.WriteLine("利用種別 : {0}", GetRiyouShubetsu(data[1]));
                    Console.WriteLine("支払種別 : {0}", GetShiharaiShubetsu(data[2]));
                    Console.WriteLine("入出場種別 : {0}", GetNyushutsujoShubetsu(data[3]));
                    Console.WriteLine("処理日付 : {0}", BinaryToDate(data[4], data[5]).ToString("yyyy/MM/dd"));
                    Console.WriteLine("詳細情報 : {0:X2}{1:X2}{2:X2}{3:X2}", data[6], data[7], data[8], data[9]);
                    Console.WriteLine("残額 : \\ {0}", BitConverter.ToUInt16(data, 10));
                    Console.WriteLine("不明 : {0:X2}", data[12]);
                    Console.WriteLine("取引通番 : {0}", BitConverter.ToUInt16(new byte[] { data[14], data[13] }, 0));
                    Console.WriteLine("地域(入場) : {0}", GetChiikiCode(data[15], InOut.In));
                    Console.WriteLine("地域(出場) : {0}", GetChiikiCode(data[15], InOut.Out));
                    Console.WriteLine("不明 : {0:X2}", BinaryToInt32(ByteToBinary(data[15]), 7, 4));
                    Console.WriteLine();
                }
            }
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                using (Felica f = new Felica())
                {
                    f.Polling((int)SystemCode.Common);

                    //学籍番号の読み出し
                    byte[] data      = f.ReadWithoutEncryption(0x1A8B, 0);
                    byte[] studentId = new byte[7];
                    Array.Copy(data, 2, studentId, 0, 7);

                    //名前読み出し
                    byte[] name = f.ReadWithoutEncryption(0x1A8B, 1);


                    studentIDLabel.Text = byte2str(studentId);
                    nameLabel.Text      = byte2str(name);
                }
            }
            catch (Exception ex)
            {
                textBox.Text = ex.Message;
            }
        }
        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();
        }
Beispiel #4
0
        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();
        }
        /// <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);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="f"></param>
        private static void ReadNanaco(Felica f)
        {
            f.Polling((int)SystemCode.Common);
            byte[] data = f.ReadWithoutEncryption(0x558b, 0);
            if (data == null)
            {
                throw new Exception("nanaco ID が読み取れません");
            }
            Console.Write("Nanaco ID = ");
            for (int i = 0; i < 8; i++)
            {
                Console.Write(data[i].ToString("X2"));
            }
            Console.Write("\n");

            for (int i = 0; ; i++)
            {
                data = f.ReadWithoutEncryption(0x564f, i);
                if (data == null)
                {
                    break;
                }

                switch (data[0])
                {
                case 0x47:
                default:
                    Console.Write("支払     ");
                    break;

                case 0x6f:
                    Console.Write("チャージ ");
                    break;
                }

                int value = (data[9] << 24) + (data[10] << 16) + (data[11] << 8) + data[12];
                int year  = (value >> 21) + 2000;
                int month = (value >> 17) & 0xf;
                int date  = (value >> 12) & 0x1f;
                int hour  = (value >> 6) & 0x3f;
                int min   = value & 0x3f;

                Console.Write("{0}/{1:D2}/{2:D2} {3:D2}:{4:D2}", year, month, date, hour, min);

                value = (data[1] << 24) + (data[2] << 16) + (data[3] << 8) + data[4];
                Console.Write("  金額 {0,6}円", value);

                value = (data[5] << 24) + (data[6] << 16) + (data[7] << 8) + data[8];
                Console.Write("  残高 {0,6}円", value);

                value = (data[13] << 8) + data[14];
                Console.WriteLine("  連番 {0}", value);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Print Edy No.
        /// </summary>
        /// <param name="f"></param>
        private static void PrintEdyNo(Felica f)
        {
            f.Polling((int)SystemCode.Edy);
            byte[] edyNoByteArray = f.ReadWithoutEncryption(0x110B, 0)
                                    .Skip(2)
                                    .Take(8)
                                    .ToArray();

            Console.Write("Edy No.: ");
            foreach (var b in edyNoByteArray)
            {
                Console.Write(string.Format("{0:X2}", b));
            }
            Console.Write("\r\n");
        }
        private string ReadStudentID(Felica f)
        {
            string studentID = "";

            f.Polling(0x8277);
            byte[] data = f.ReadWithoutEncryption(0x010b, 0);
            if (data == null)
            {
                throw new Exception("学生証が読み取れません");
            }
            for (int i = 3; i < 10; i++)
            {
                studentID += (char)data[i];
            }
            return(studentID);
        }
Beispiel #9
0
        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");
        }
Beispiel #10
0
 /// <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);
 }
Beispiel #11
0
        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);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Suicaの乗降履歴情報をパースする
        /// 参考:https://www.wdic.org/w/RAIL/%E3%82%B5%E3%82%A4%E3%83%90%E3%83%8D%E8%A6%8F%E6%A0%BC%20%28IC%E3%82%AB%E3%83%BC%E3%83%89%29#090Fx20xE4xB9x97xE9x99x8DxE5xB1xA5xE6xADxB4xE6x83x85xE5xA0xB1
        /// </summary>
        /// <param name="f"></param>
        private void ParseSuica(Felica f)
        {
            // システムコード: 0003 (Suicaなどの領域)
            f.Polling((int)SystemCode.Suica);

            for (int i = 0; ; i++)
            {
                ParseData ps;

                // サービスコード 乗降履歴情報(16バイト)
                byte[] data = f.ReadWithoutEncryption(0x090f, i);
                if (data == null)
                {
                    break;
                }

                // 0: 機器種別
                ps.TerminalNum = data[0];

                // 1: 利用種別
                ps.UsageType = data[1];

                // 2: 決済種別
                ps.SettlementType = data[2];

                // 3: 入出場種別
                ps.EntranceType = data[3];

                // 4-5: 年月日[年 / 7ビット、月 / 4ビット、日 / 5ビット]
                ps.Year  = (data[4] >> 1) + 2000;
                ps.Month = ((data[4] & 0x01) << 3) + (data[5] >> 5);
                ps.Day   = data[5] & 0x1F;

                // 6-9: 入出場駅コード(鉄道)、停留所コード(バス)、物販情報(物販)
                ps.InLineCode     = data[6];
                ps.InStationCode  = data[7];
                ps.OutLineCode    = data[8];
                ps.OutStationCode = data[9];

                // コードから駅名を探す
                ps.InLineStr     = "";
                ps.InStationStr  = "";
                ps.OutLineStr    = "";
                ps.OutStationStr = "";
                foreach (var stationCode in stationCodeList)
                {
                    if (stationCode.LineCode == ps.InLineCode && stationCode.StationSeqCode == ps.InStationCode)
                    {
                        ps.InLineStr    = stationCode.Line;
                        ps.InStationStr = stationCode.Station;
                        break;
                    }
                }
                foreach (var stationCode in stationCodeList)
                {
                    if (stationCode.LineCode == ps.OutLineCode && stationCode.StationSeqCode == ps.OutStationCode)
                    {
                        ps.OutLineStr    = stationCode.Line;
                        ps.OutStationStr = stationCode.Station;
                        break;
                    }
                }

                // 10-11: 残額
                ps.Balance = (UInt16)((data[11] << 8) + data[10]);

                // 13-14 履歴連番
                ps.HistoryNum = (UInt16)((data[13] << 8) + data[14]);

                ps.Charge = 0;

                parseData.Add(ps);
            }
        }
 private void Polling()
 {
     f.Polling((int)0x8277);
 }