示例#1
0
 /// <summary>
 /// 生成
 /// </summary>
 /// <param name="error">FelicaErrorType or FalpErrorType</param>
 public FelicaException(Object error)
     : base(FelicaHelper.GetErrorDescription(error))
 {
     if (error is FelicaErrorType)
     {
         FelicaError = (FelicaErrorType)error;
     }
     else if (error is FalpErrorType)
     {
         FalpError = (FalpErrorType)error;
     }
 }
示例#2
0
 /// <summary>
 /// FelicaExceptionをthrowする
 /// </summary>
 /// <param name="type">FelicaErorrTyper</param>
 private static void RaiseException(Type type)
 {
     if (type == typeof(FelicaErrorType))
     {
         FelicaErrorType error = FelicaErrorType.FELICA_UNKNOWN_ERROR;
         felica_dll.GetLastErrorType(out error);
         throw new FelicaException(error);
     }
     else if (type == typeof(FalpErrorType))
     {
         FalpErrorType error = FalpErrorType.FALP_UNKNOWN_ERROR;
         felica_dll.FalpGetLastErrorType(out error);
         throw new FelicaException(error);
     }
 }
示例#3
0
        public static bool FalpGetLastErrorType(out FalpErrorType type)
        {
            uint errorType = 0;
            byte res       = falp_get_last_error_type(ref errorType);

            if (res == TRUE)
            {
                type = (FalpErrorType)errorType;
                return(true);
            }
            else
            {
                type = 0;
                return(false);
            }
        }
示例#4
0
        /// <summary>
        /// FALPでのデータ送信
        /// </summary>
        /// <param name="buffer">データ</param>
        /// <param name="offset">位置</param>
        /// <param name="length">長さ</param>
        /// <returns>T:OK,F:NG</returns>
        public static bool SendFalp(byte[] buffer, int offset, int length)
        {
            bool   finish    = false;
            uint   sendCount = 0;
            Thread th        = new Thread(
                new ThreadStart(delegate(){
                while (true)
                {
                    if (sendCount >= length)
                    {
                        finish = true;
                        break;
                    }

                    byte[] buf = new byte[length - sendCount];
                    Array.Copy(buffer, offset + sendCount, buf, 0, buf.Length);

                    //送信
                    uint buffered = (uint)buf.Length;
                    if (!felica_dll.FalpSend(buf, ref buffered))
                    {
                        FalpErrorType error = FalpErrorType.FALP_UNKNOWN_ERROR;
                        felica_dll.FalpGetLastErrorType(out error);
                        Debug.WriteLine("FALP Error:" + GetErrorDescription(error));
                        break;
                    }
                    Debug.WriteLine("FALP Send Prepare:" + sendCount + "," + buffered);
                    sendCount += buffered;

                    //待つ
                    FalpEvent detected;
                    if (!felica_dll.FalpWaitEvent(1000, out detected
                                                  , FalpEvent.SEND_READY | FalpEvent.SEND_EMPTY))
                    {
                        break;
                    }
                }
                return;
            }));

            th.Start();
            th.Join();
            return(finish);
        }