Пример #1
0
        public bool salWater(string strSal, ref string strLeftAmount)
        {
            try
            {
                string strSalAmount = strSal;
                int    dSalAmount   = Convert.ToInt32(strSalAmount);

                strSalAmount = dSalAmount.ToString("x");

                strSalAmount = this.getSalAmount(strSalAmount);

                if (strSalAmount == "")
                {
                    MessageBox.Show("写卡失败!");
                    return(false);
                }

                string strSalWater = this.getCmd("salWater");

                strSalWater = strSalWater.Trim() + " " + strSalAmount.Trim() + " 00";
                ComSoft.setParams.CSetParams csp = new ComSoft.setParams.CSetParams();
                string strSalWaterEx             = "";

                if (csp.sendCmdNoCrc("", strSalWater, ref strSalWaterEx) == false)
                {
                    return(false);
                }

                cSetParam csparam = new cSetParam(this.axMSComm1);
                csparam.setParams(strSalWaterEx);

                System.Threading.Thread.Sleep(400);

                byte[] btRead = (byte[])this.axMSComm1.Input;
                int    iLen   = btRead.Length - 2;

                if (iLen < 1)
                {
                    return(false);
                }

                int[] iRead = new int[iLen];

                for (int i = 0; i < iLen; i++)
                {
                    iRead[i] = Convert.ToInt32(btRead[i]);
                }

                crc16.crc16 crc16Obj = new crc16.crc16();
                crc16Obj.IniCard();
                long lEnd   = crc16Obj.CRC16_check(iRead, iLen);
                int  iEnd   = Convert.ToInt32(lEnd);
                int  iEndEx = btRead[btRead.Length - 2] * 256 + btRead[btRead.Length - 1];

                if (iEnd != iEndEx)
                {
                    return(false);
                }

                string strOrdial = "";
                for (int i = 0; i < iRead.Length; i++)
                {
                    strOrdial = strOrdial + " " + iRead[i].ToString("x");
                }

                if (this.writeCard(strOrdial, ref strLeftAmount) == false)
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)

            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
        }
Пример #2
0
Файл: cIC.cs Проект: hkiaipc/yh
        public bool salWater(string strSal,ref string strLeftAmount)
        {
            try
            {
                string strSalAmount=strSal;
                int dSalAmount=Convert.ToInt32(strSalAmount);

                strSalAmount=dSalAmount.ToString("x");

                strSalAmount=this.getSalAmount(strSalAmount);

                if(strSalAmount=="")
                {
                    MessageBox.Show("д��ʧ�ܣ�");
                    return false;
                }

                string strSalWater=this.getCmd("salWater");

                strSalWater=strSalWater.Trim()+" "+strSalAmount.Trim()+" 00";
                ComSoft.setParams.CSetParams csp=new ComSoft.setParams.CSetParams();
                string strSalWaterEx="";

                if(csp.sendCmdNoCrc("",strSalWater,ref strSalWaterEx)==false)
                {
                    return false;
                }

                cSetParam csparam=new cSetParam(this.axMSComm1);
                csparam.setParams(strSalWaterEx);

                System.Threading.Thread.Sleep(400);

                byte[] btRead=(byte[])this.axMSComm1.Input;
                int iLen=btRead.Length-2;

                if(iLen<1)
                {
                    return false;
                }

                int[] iRead=new int[iLen];

                for(int i=0;i<iLen;i++)
                {
                    iRead[i]=Convert.ToInt32(btRead[i]);
                }

                crc16.crc16 crc16Obj=new crc16.crc16();
                crc16Obj.IniCard();
                long lEnd=crc16Obj.CRC16_check(iRead,iLen);
                int iEnd=Convert.ToInt32(lEnd);
                int iEndEx=btRead[btRead.Length-2]*256+btRead[btRead.Length-1];

                if(iEnd!=iEndEx)
                {
                    return false;
                }

                string strOrdial="";
                for(int i=0;i<iRead.Length;i++)
                {
                    strOrdial=strOrdial+" "+iRead[i].ToString("x");
                }

                if(this.writeCard(strOrdial,ref strLeftAmount)==false)
                {
                    return false;
                }
                return true;

            }
            catch(Exception ex)

            {
                MessageBox.Show(ex.ToString());
                return false;
            }
        }