Example #1
0
File: cIC.cs Project: wwkkww1983/yh
        public bool readCard(ref string strCardNo, ref string strSal)
        {
            try
            {
                string    strCmd = this.getCmd("readCard");
                cSetParam csp    = new cSetParam(this.axMSComm1);
                csp.setParams(strCmd);
                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.readCard(strOrdial, ref strCardNo, ref strSal) == false)
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
        }
Example #2
0
File: cIC.cs Project: hkiaipc/yh
        public bool iniCard(ref string strCardNo)
        {
            try
            {
                string strCmd=this.getCmd("iniCard");
                cSetParam csp=new cSetParam(this.axMSComm1);
                csp.setParams(strCmd);
                System.Threading.Thread.Sleep(1000);
                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.iniCard(strOrdial,ref strCardNo)==false)
                {
                    return false;
                }
                return true;
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return false;
            }
        }
Example #3
0
File: cIC.cs Project: wwkkww1983/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);
            }
        }
Example #4
0
File: cIC.cs Project: 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;
            }
        }