Exemple #1
0
        public static int crc16(int[] ints, int iLen)
        {
            crc16.crc16 crc16Obj = new crc16.crc16();
            crc16Obj.IniCard();
            long lCrc16 = crc16Obj.CRC16_check(ints, iLen);
            int  iCrc16 = Convert.ToInt32(lCrc16);

            return(iCrc16);
        }
Exemple #2
0
        private void farSetCmd(string strCmd, string strVal)
        {
            string[] strCmds = strCmd.Split(' ');

            byte[] btsCmd = new byte[strCmds.Length + 4];

            for (int i = 0; i < strCmds.Length; i++)
            {
                btsCmd[i] = Convert.ToByte(strCmds[i], 16);
            }

            int    iAllAmount   = int.Parse(strVal);
            string strAllAmount = "";

            if (this.getRealData(iAllAmount, ref strAllAmount) == false)
            {
                //this.stopCmd();
                return;
            }

            btsCmd[strCmds.Length]     = Convert.ToByte(strAllAmount.Substring(2, 2), 16);
            btsCmd[strCmds.Length + 1] = Convert.ToByte(strAllAmount.Substring(0, 2), 16);

            int[] intsCmd = new int[btsCmd.Length];

            for (int i = 0; i < (btsCmd.Length - 2); i++)
            {
                intsCmd[i] = Convert.ToInt32(btsCmd[i]);
            }

            crc16.crc16 crcObj = new crc16.crc16();
            crcObj.IniCard();

            long lData = crcObj.CRC16_check(intsCmd, intsCmd.Length - 2);

            int iHigh = (int)lData / 256;
            int iLow  = (int)lData & 255;

            intsCmd[intsCmd.Length - 2] = iHigh;
            intsCmd[intsCmd.Length - 1] = iLow;

            for (int i = 0; i < btsCmd.Length; i++)
            {
                btsCmd[i] = Convert.ToByte(intsCmd[i]);
            }

            strCmd = "";

            for (int i = 0; i < btsCmd.Length; i++)
            {
                strCmd = strCmd.Trim() + " " + btsCmd[i].ToString("x").Trim();
            }

            this.m_frmCom.farCmd(strCmd);
        }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
        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;
            }
        }
Exemple #5
0
        public static string addCrc(string strSource)
        {
            try
            {
                strSource = strSource.Replace("  ", " ");
                strSource = strSource.Replace("   ", " ");
                strSource = strSource.Trim();
                string[] strsSource = strSource.Split(' ');
                if (strsSource.Length == 0)
                {
                    return("");
                }

                int[] intsSource = new int[strsSource.Length + 2];
                for (int i = 0; i < strsSource.Length; i++)
                {
                    intsSource[i] = Convert.ToInt32(strsSource[i], 16);
                }
                crc16.crc16 crc = new crc16.crc16();
                crc.IniCard();
                long lCrc = crc.CRC16_check(intsSource, strsSource.Length);
                if (lCrc == -1)
                {
                    MessageBox.Show(strSource + "  " + "交验错误");
                    return("");
                }
                int iCrc = (int)lCrc;
                intsSource[strsSource.Length]     = iCrc / 256;
                intsSource[strsSource.Length + 1] = iCrc & 255;

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

                return(strRet);
            }
            catch (Exception ex)
            {
                MessageBox.Show(strSource + "  " + ex.ToString());
                return("");
            }
        }
Exemple #6
0
        public static string addCrc(string strSource)
        {
            try
            {
                strSource=strSource.Replace("  "," ");
                strSource=strSource.Replace("   "," ");
                strSource=strSource.Trim();
                string[] strsSource=strSource.Split(' ');
                if(strsSource.Length==0)
                {
                    return "";
                }

                int[] intsSource=new int[strsSource.Length+2];
                for(int i=0;i<strsSource.Length;i++)
                {
                    intsSource[i]=Convert.ToInt32(strsSource[i],16);
                }
                crc16.crc16 crc=new crc16.crc16();
                crc.IniCard();
                long lCrc=	crc.CRC16_check(intsSource,strsSource.Length);
                if(lCrc==-1)
                {
                    MessageBox.Show(strSource+"  "+"�������");
                    return "";
                }
                int iCrc=(int)lCrc;
                intsSource[strsSource.Length]=iCrc/256;
                intsSource[strsSource.Length+1]=iCrc&255;

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

                return strRet;
            }
            catch(Exception ex)
            {
                MessageBox.Show(strSource+"  "+ex.ToString());
                return "";
            }
        }
Exemple #7
0
        public static bool checkCrc(int[] ints, int iLen)
        {
            if (ints.Length < 3)
            {
                return(false);
            }

            crc16.crc16 crc16Obj = new crc16.crc16();
            crc16Obj.IniCard();
            long lCrc16 = crc16Obj.CRC16_check(ints, iLen - 2);
            int  iCrc16 = Convert.ToInt32(lCrc16);

            int i1 = iCrc16 / 256;
            int i2 = iCrc16 & 255;

            if (ints[iLen - 2] == i1)
            {
                if (ints[iLen - 1] == i2)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #8
0
        private void farSetCmd(string strCmd,string strVal)
        {
            string[] strCmds=strCmd.Split(' ');

            byte[] btsCmd=new byte[strCmds.Length+4];

            for(int i=0;i<strCmds.Length;i++)
            {
                btsCmd[i]=Convert.ToByte(strCmds[i],16);
            }

            int iAllAmount=int.Parse(strVal);
            string strAllAmount="";

            if(this.getRealData(iAllAmount,ref strAllAmount)==false)
            {
                //this.stopCmd();
                return ;
            }

            btsCmd[strCmds.Length]=Convert.ToByte(strAllAmount.Substring(2,2),16);
            btsCmd[strCmds.Length+1]=Convert.ToByte(strAllAmount.Substring(0,2),16);

            int[] intsCmd= new int[btsCmd.Length];

            for(int i=0;i<(btsCmd.Length-2);i++)
            {
                intsCmd[i]=Convert.ToInt32(btsCmd[i]);
            }

            crc16.crc16 crcObj=new crc16.crc16();
            crcObj.IniCard();

            long lData=crcObj.CRC16_check(intsCmd,intsCmd.Length-2);

            int iHigh=(int)lData/256;
            int iLow=(int)lData&255;

            intsCmd[intsCmd.Length-2]=iHigh;
            intsCmd[intsCmd.Length-1]=iLow;

            for(int i=0;i<btsCmd.Length;i++)
            {
                btsCmd[i]=Convert.ToByte(intsCmd[i]);
            }

            strCmd="";

            for(int i=0;i<btsCmd.Length;i++)
            {
                strCmd=strCmd.Trim()+" "+btsCmd[i].ToString("x").Trim();
            }

            this.m_frmCom.farCmd(strCmd);
        }
Exemple #9
0
        private void clearAmount(string adr)
        {
            XmlDocument xDoc=new XmlDocument();
            xDoc.Load("farCmd.xml");
            XmlNode xNode=xDoc.DocumentElement.SelectSingleNode("./farCmd/setAmount[@des='����']");

            this.m_arrBackInfo.Clear();

            for(int i=0;i<xNode.ChildNodes.Count;i++)
            {
                string strCmd=xNode.ChildNodes[i].Attributes.GetNamedItem("val").Value.Trim();
                strCmd=strCmd.Replace("xx",int.Parse(adr).ToString("x"));
                string strSleep=xNode.ChildNodes[i].Attributes.GetNamedItem("sleep").Value.Trim();

                //PengW
                string[] strCmds=strCmd.Split(' ');

                byte[] btsCmd=new byte[strCmds.Length+2];

                for(int j=0;j<strCmds.Length;j++)
                {
                    btsCmd[j]=Convert.ToByte(strCmds[j],16);
                }

                int[] intsCmd= new int[btsCmd.Length];

                for(int j=0;j<(btsCmd.Length-2);j++)
                {
                    intsCmd[j]=Convert.ToInt32(btsCmd[j]);
                }

                crc16.crc16 crcObj=new crc16.crc16();
                crcObj.IniCard();

                long lData=crcObj.CRC16_check(intsCmd,intsCmd.Length-2);

                int iHigh=(int)lData/256;
                int iLow=(int)lData&255;

                intsCmd[intsCmd.Length-2]=iHigh;
                intsCmd[intsCmd.Length-1]=iLow;

                for(int j=0;j<btsCmd.Length;j++)
                {
                    btsCmd[j]=Convert.ToByte(intsCmd[j]);
                }

                strCmd="";

                for(int j=0;j<btsCmd.Length;j++)
                {
                    strCmd=strCmd.Trim()+" "+btsCmd[j].ToString("x").Trim();
                }

                //
                this.m_frmCom.farCmd(strCmd);
                this.sleep(int.Parse(strSleep));
            }

            if(this.m_arrBackInfo.Count==1)
            {
                if((this.m_arrBackInfo[0].ToString().IndexOf("�ɹ�")>=0)&&(this.m_arrBackInfo[0].ToString().IndexOf("�ɹ�")>=0))
                {
                    MessageBox.Show("����ɹ�!");
                    return ;
                }
            }

            MessageBox.Show("�ȴ���ʱ!");
        }
Exemple #10
0
        private void clearAmount(string adr)
        {
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load("farCmd.xml");
            XmlNode xNode = xDoc.DocumentElement.SelectSingleNode("./farCmd/setAmount[@des='清零']");

            this.m_arrBackInfo.Clear();

            for (int i = 0; i < xNode.ChildNodes.Count; i++)
            {
                string strCmd = xNode.ChildNodes[i].Attributes.GetNamedItem("val").Value.Trim();
                strCmd = strCmd.Replace("xx", int.Parse(adr).ToString("x"));
                string strSleep = xNode.ChildNodes[i].Attributes.GetNamedItem("sleep").Value.Trim();

                //PengW
                string[] strCmds = strCmd.Split(' ');

                byte[] btsCmd = new byte[strCmds.Length + 2];

                for (int j = 0; j < strCmds.Length; j++)
                {
                    btsCmd[j] = Convert.ToByte(strCmds[j], 16);
                }


                int[] intsCmd = new int[btsCmd.Length];

                for (int j = 0; j < (btsCmd.Length - 2); j++)
                {
                    intsCmd[j] = Convert.ToInt32(btsCmd[j]);
                }

                crc16.crc16 crcObj = new crc16.crc16();
                crcObj.IniCard();

                long lData = crcObj.CRC16_check(intsCmd, intsCmd.Length - 2);

                int iHigh = (int)lData / 256;
                int iLow  = (int)lData & 255;

                intsCmd[intsCmd.Length - 2] = iHigh;
                intsCmd[intsCmd.Length - 1] = iLow;

                for (int j = 0; j < btsCmd.Length; j++)
                {
                    btsCmd[j] = Convert.ToByte(intsCmd[j]);
                }

                strCmd = "";

                for (int j = 0; j < btsCmd.Length; j++)
                {
                    strCmd = strCmd.Trim() + " " + btsCmd[j].ToString("x").Trim();
                }

                //
                this.m_frmCom.farCmd(strCmd);
                this.sleep(int.Parse(strSleep));
            }

            if (this.m_arrBackInfo.Count == 1)
            {
                if ((this.m_arrBackInfo[0].ToString().IndexOf("成功") >= 0) && (this.m_arrBackInfo[0].ToString().IndexOf("成功") >= 0))
                {
                    MessageBox.Show("清零成功!");
                    return;
                }
            }

            MessageBox.Show("等待超时!");
        }
Exemple #11
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);
            }
        }
Exemple #12
0
 public static int crc16(int[] ints,int iLen)
 {
     crc16.crc16  crc16Obj=new crc16.crc16();
     crc16Obj.IniCard();
     long lCrc16=crc16Obj.CRC16_check(ints,iLen);
     int iCrc16=Convert.ToInt32(lCrc16);
     return iCrc16;
 }
Exemple #13
0
        public static bool checkCrc(int[] ints,int iLen)
        {
            if(ints.Length<3)
            {
                return false;
            }

            crc16.crc16  crc16Obj=new crc16.crc16();
            crc16Obj.IniCard();
            long lCrc16=crc16Obj.CRC16_check(ints,iLen-2);
            int iCrc16=Convert.ToInt32(lCrc16);

            int i1=iCrc16/256;
            int i2=iCrc16&255;

            if(ints[iLen-2]==i1)
            {
                if(ints[iLen-1]==i2)
                {
                    return true;
                }
            }
            return false;
        }
Exemple #14
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;
            }
        }