Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        /// <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);
                }
            }
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
0
 public void Felica_GetIDm_Edy()
 {
     using (var felica = new Felica(FelicaSystemCode.Edy))
     {
         Debug.WriteLine(felica.GetIDm().ToHexString());
     }
 }
Exemplo n.º 5
0
 public void Felica_GetPMm_Suica()
 {
     using (var felica = new Felica(FelicaSystemCode.Suica))
     {
         Debug.WriteLine(felica.GetPMm().ToHexString());
     }
 }
Exemplo n.º 6
0
 public void Felica_TryConnectionToCard()
 {
     using (var felica = new Felica(FelicaSystemCode.Any))
     {
         Assert.AreEqual(false, felica.TryConnectionToCard());
     }
 }
Exemplo n.º 7
0
 public void Felica_ReadWithoutEncryption_Any()
 {
     using (var felica = new Felica(FelicaSystemCode.Any))
     {
         Debug.WriteLine(felica.ReadWithoutEncryption(FelicaServiceCode.EdyBalance, 0).ToHexString());
     }
 }
        /// <summary>
        /// 定周期処理
        /// </summary>
        public async Task Start()
        {
            string prevId = "";
            //スケジューラーをキャンセルするToken(?)
            var token = CancellationToken.None;

            using (Felica felica = new Felica()) {
                while (!token.IsCancellationRequested)
                {
                    //引数1 : 遅延処理
                    //引数2 : 非同期したい処理の内容
                    await Task.WhenAll(Task.Delay(50), Task.Run(async() => {
                        string studentId = felica.GetStudentID();
                        if (!prevId.Equals(studentId))
                        {
                            if (studentId == "")
                            {
                                StudentID = "";
                                Time      = "";
                            }
                            else
                            {
                                StudentID         = studentId;
                                DateTime dateTime = DateTime.Now;
                                Time = dateTime.ToString("HH時mm分ss秒");
                                await FirebaseManager.Instance.PushDataBase(studentId, dateTime);
                                Console.WriteLine(StudentID + " : " + dateTime.ToString("yyyy-MM-dd HH:mm:ss"));
                            }
                        }
                        prevId = studentId;
                    }, token));
                }
            }
        }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
0
 public void Felica_ReadWithoutEncryption_Suica()
 {
     using (var felica = new Felica(FelicaSystemCode.Suica))
     {
         Debug.WriteLine(felica.ReadWithoutEncryption(FelicaServiceCode.SuicaAttributes, 0).ToHexString());
     }
 }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
 public void Felica_ReadBlocksWithoutEncryption_Suica()
 {
     using (var felica = new Felica(FelicaSystemCode.Suica))
     {
         foreach (var data in felica.ReadBlocksWithoutEncryption(FelicaServiceCode.SuicaHistory, 0, 20))
         {
             Debug.WriteLine(data.ToHexString());
         }
     }
 }
Exemplo n.º 13
0
 public void Felica_ReadBlocksWithoutEncryption_Edy_OutOfRange()
 {
     using (var felica = new Felica(FelicaSystemCode.Edy))
     {
         foreach (var data in felica.ReadBlocksWithoutEncryption(FelicaServiceCode.EdyHistory, 5, 2))
         {
             Debug.WriteLine(data.ToHexString());
         }
     }
 }
Exemplo n.º 14
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);
            }
        }
Exemplo n.º 15
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);
            }
        }
Exemplo n.º 16
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);
     }
 }
Exemplo n.º 17
0
        public void ReadFelcia(string iCCardType)
        {
            using (Felica felica = new Felica()) {
                switch (iCCardType)
                {
                case "Suica":
                    ReadSuica(felica);
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 18
0
 public Felica Select(ushort sysCode)
 {
     idm = new byte[FelicaNetHelper.IDM_LENGTH];
     if (FelicaNetHelper.Polling(sysCode, idm))
     {
         Felica card = new Felica(lib, idm);
         return(card);
     }
     else
     {
         StopAccess();
         return(null);
     }
 }
Exemplo n.º 19
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");
        }
Exemplo n.º 20
0
 /// <summary>
 /// Entry Point.
 /// </summary>
 /// <param name="args"></param>
 static void Main(string[] args)
 {
     try
     {
         using (Felica f = new Felica())
         {
             PrintIDm(f);
             PrintEdyNo(f);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Exemplo n.º 21
0
 public void Felica_TryConnectionToPort()
 {
     using (var felica = new Felica(FelicaSystemCode.Any))
     {
         Assert.AreEqual(true, felica.TryConnectionToPort());
     }
     using (var felica = new Felica(FelicaSystemCode.Edy))
     {
         Assert.AreEqual(true, felica.TryConnectionToPort());
     }
     using (var felica = new Felica(FelicaSystemCode.Suica))
     {
         Assert.AreEqual(true, felica.TryConnectionToPort());
     }
 }
        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);
        }
 private void OnTimer(object sender, EventArgs e)
 {
     ClockLabel.Content = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
     try
     {
         using (Felica f = new Felica())
         {
             string studentId = ReadStudentID(f);
             StudentIDText.Content = studentId + " さん";
             if (felicaCheckFlag)
             {
                 return;
             }
             //検索処理
             if (accessLogs.Count(al => al.studentId == studentId) == 0)
             {
                 //見つからない場合
                 accessLogs.Add(new AccessLog()
                 {
                     studentId = studentId, inTime = DateTime.Now
                 });
                 OutputLog(accessLogs[accessLogs.Count - 1], InOutKind.入室);
                 StatusText.Content = "入室";
             }
             else
             {
                 //見つかった場合
                 var target   = accessLogs.Find(al => al.studentId == studentId);
                 var passTime = DateTime.Now - target.inTime;
                 if (passTime < new TimeSpan(0, 0, 10))
                 {
                     return;
                 }
                 OutputLog(target, InOutKind.退室);
                 accessLogs.Remove(target);
                 StatusText.Content = "退室";
             }
             felicaCheckFlag = true;
         }
     }
     catch (Exception ex)
     {
         AllViewClear();
         felicaCheckFlag = false;
         Console.WriteLine(ex.Message);
     }
 }
Exemplo n.º 24
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);
             }
         }
     }
 }
Exemplo n.º 25
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");
        }
Exemplo n.º 26
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);
                    }
                }
            }
        }
Exemplo n.º 27
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);
 }
Exemplo n.º 28
0
        private static void Write(ref Felica felica, string text)
        {
            byte[] text_bytes = GetBytes(text);

            for (int i = 0; i < FELICA_LITE_S_DATA_LENGTH / 0x10; i++)
            {
                byte[] data = new byte[0x10];
                for (int j = 0; j < 0x10; j++)
                {
                    if ((i << 4) + j < text_bytes.Length)
                    {
                        data[j] = text_bytes[(i << 4) + j];
                    }
                    else
                    {
                        data[j] = 0x00;
                    }
                }

                felica.WriteWithoutEncryption(0x0009, i, data);
            }
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Suicaの読み取りを開始する
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            textBox.Clear();
            parseData.Clear();
            try
            {
                using (var f = new Felica())
                {
                    ParseSuica(f);
                    // 利用額の計算
                    CalcCharge();
                    playerOK.Play();

                    // 保存
                    WriteCsv();
                }
            }
            catch (Exception ex)
            {
                textBox.Text = ex.Message;
                playerNG.Play();
            }
        }