Example #1
0
        private void write()
        {
            try
            {
                string ptrStr = edtTxtAddress_W.Text.Trim();
                if (ptrStr == string.Empty)
                {
                    Toast.MakeText(mContext, "Please input the address!", ToastLength.Short).Show();
                    return;
                }
                else if (!Comm.IsNumber(ptrStr))
                {
                    Toast.MakeText(mContext, "Address must be a decimal data!", ToastLength.Short).Show();
                    return;
                }

                string cntStr = edtTxtLeng_W.Text.Trim();
                if (cntStr == string.Empty)
                {
                    Toast.MakeText(mContext, "Length cannot be empty", ToastLength.Short).Show();
                    return;
                }
                else if (!Comm.IsNumber(cntStr))
                {
                    Toast.MakeText(mContext, "Length must be a decimal data!", ToastLength.Short).Show();
                    return;
                }

                string pwdStr = edtTxtPassword_W.Text.Trim();
                if (pwdStr != string.Empty)
                {
                    if (pwdStr.Length != 8)
                    {
                        Toast.MakeText(mContext, "The length of the access password must be 8!", ToastLength.Short).Show();
                        return;
                    }
                    else if (!Comm.isHex(pwdStr))
                    {
                        Toast.MakeText(mContext, "Please enter the hexadecimal number content!", ToastLength.Short).Show();
                        return;
                    }
                }
                else
                {
                    pwdStr = "00000000";
                }


                string strData = edtTxtData_W.Text.Trim();         // 要写入的内容

                if (strData == string.Empty)
                {
                    Toast.MakeText(mContext, "Write data can not be empty!", ToastLength.Short).Show();
                    return;
                }
                else if (!Comm.isHex(strData))
                {
                    Toast.MakeText(mContext, "Please enter the hexadecimal number content!", ToastLength.Short).Show();
                    return;
                }
                else if ((strData.Length) % 4 != 0)
                {
                    Toast.MakeText(mContext, "Write data of the length of the string must be in multiples of four!", ToastLength.Short).Show();
                    return;
                }

                Com.Rscja.Deviceapi.RFIDWithUHF.BankEnum bank = Com.Rscja.Deviceapi.RFIDWithUHF.BankEnum.ValueOf(spnBank_W.SelectedItem.ToString());

                string strReUII = mContext.uhfAPI.WriteData(pwdStr, bank, int.Parse(ptrStr), int.Parse(cntStr), strData);         // 返回的UII
                if (strReUII != string.Empty)
                {
                    Toast.MakeText(mContext, "Write data successfully!" + "\nUII: "
                                   + strReUII, ToastLength.Short).Show();
                    Sound();
                }
                else
                {
                    Toast.MakeText(mContext, "Write data failure!", ToastLength.Short).Show();
                }
            }catch {
            }
        }