Ejemplo n.º 1
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;
            }
        }
        public Card Read()
        {
            Card card = new Card();

            Polling();
            byte[] data = f.ReadWithoutEncryption(0x010b, 0);
            if (data == null)
            {
                throw new Exception("学籍番号が読み取れません");
            }
            for (int i = 3; i < 10; i++)
            {
                card.ID += (char)data[i];
            }
            data = f.ReadWithoutEncryption(0x010b, 1);
            if (data == null)
            {
                throw new Exception("有効期限が読み取れません");
            }
            for (int i = 0; i < 8; i++)
            {
                card.ValidFromRaw += (char)data[i];
            }
            card.ValidFrom = DateTime.ParseExact(card.ValidFromRaw + "000000", "yyyyMMddHHmmss", null);
            for (int i = 8; i < 16; i++)
            {
                card.ValidToRaw += (char)data[i];
            }
            card.ValidTo = DateTime.ParseExact(card.ValidToRaw + "235959", "yyyyMMddHHmmss", null);
            return(card);
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
 public void Felica_ReadWithoutEncryption_Any()
 {
     using (var felica = new Felica(FelicaSystemCode.Any))
     {
         Debug.WriteLine(felica.ReadWithoutEncryption(FelicaServiceCode.EdyBalance, 0).ToHexString());
     }
 }
Ejemplo n.º 6
0
 public void Felica_ReadWithoutEncryption_Suica()
 {
     using (var felica = new Felica(FelicaSystemCode.Suica))
     {
         Debug.WriteLine(felica.ReadWithoutEncryption(FelicaServiceCode.SuicaAttributes, 0).ToHexString());
     }
 }
Ejemplo n.º 7
0
Archivo: Suica.cs Proyecto: FJB2784/NFC
        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();
                }
            }
        }
Ejemplo n.º 8
0
        private static void Read(ref Felica felica)
        {
            string str = "";

            for (int i = 0; i < 0x0e; i++)
            {
                str += ToString(felica.ReadWithoutEncryption(0x0009, i));
            }
            Console.WriteLine(str);
        }
Ejemplo n.º 9
0
        static void ReadEdyBalanceEtc()
        {
            using (var felica = new Felica(FelicaSystemCode.Edy))
            {
                Console.WriteLine(felica.GetIDm().ToHexString());
                Console.WriteLine(felica.GetPMm().ToHexString());

                var data = felica.ReadWithoutEncryption(FelicaServiceCode.EdyBalance, 0);
                Console.WriteLine(new EdyBalanceItem(data).Balance);
            }
        }
Ejemplo n.º 10
0
 private static void Dump(ref Felica felica)
 {
     Console.Write("addr  ");
     for (int i = 0; i < 0x10; i++)
     {
         Console.Write("+{0:X1} ", i);
     }
     Console.WriteLine();
     for (int i = 0; i < 0x0e; i++)
     {
         Console.WriteLine("00{0:X2}  " + BitConverter.ToString(felica.ReadWithoutEncryption(0x0009, i)).Replace('-', ' '), i);
     }
 }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 13
0
 static void Test2()
 {
     using (var felica = new Felica(FelicaSystemCode.Edy))
     {
         for (int i = 0; i < 1000; i++)
         {
             try
             {
                 var data = felica.ReadWithoutEncryption(FelicaServiceCode.EdyBalance, 0);
                 Console.WriteLine(new EdyBalanceItem(data).Balance);
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.Message);
             }
         }
     }
 }
Ejemplo n.º 14
0
        static void Test1()
        {
            for (int i = 0; i < 1000; i++)
            {
                Console.WriteLine("Start");

                using (var felica = new Felica(FelicaSystemCode.Edy))
                {
                    Console.WriteLine("FeliCa ポート: {0}", felica.TryConnectionToPort());
                    Console.WriteLine("IC カード: {0}", felica.TryConnectionToCard());

                    try
                    {
                        Console.WriteLine(felica.GetIDm().ToHexString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        Console.WriteLine(felica.GetPMm().ToHexString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    try
                    {
                        var data = felica.ReadWithoutEncryption(FelicaServiceCode.EdyBalance, 0);
                        Console.WriteLine(new EdyBalanceItem(data).Balance);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
Ejemplo n.º 15
0
        public void ReadWithoutEncryption_ManyTimes1()
        {
            Task.Run(() =>
            {
                using (var felica = new Felica(FelicaSystemCode.Edy))
                {
                    for (int i = 0; i < 100; i++)
                    {
                        try
                        {
                            var data = felica.ReadWithoutEncryption(FelicaServiceCode.EdyBalance, 0);
                            Console.WriteLine(new EdyBalanceItem(data).Balance);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
            });

            Thread.Sleep(10000);
        }
Ejemplo n.º 16
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);
            }
        }