/*
         * READING CODE
         */
        private void button2_Click(object sender, EventArgs e)
        {
            results.Clear();
            CSC.sCARD_SearchExtTag SearchExtender;
            int Status;

            byte[] ATR;
            ATR = new byte[200];
            int lgATR;

            lgATR = 200;
            int Com = 0;
            int SearchMask;

            txtCom.Text  = "";
            txtCard.Text = "";

            try
            {
                CSC.SearchCSC();
                // user can also use line below to speed up coupler connection
                //AskReaderLib.CSC.Open ("COM2");

                // Define type of card to be detected: number of occurence for each loop
                SearchExtender.CONT   = 0;
                SearchExtender.ISOB   = 2;
                SearchExtender.ISOA   = 2;
                SearchExtender.TICK   = 0;
                SearchExtender.INNO   = 0;
                SearchExtender.MIFARE = 0;
                SearchExtender.MV4k   = 0;
                SearchExtender.MV5k   = 0;
                SearchExtender.MONO   = 0;
                Status = CSC.CSC_EHP_PARAMS_EXT(1, 1, 0, 0, 0, 0, 0, 0, null, 0, 0);
                // Define type of card to be detected
                SearchMask = CSC.SEARCH_MASK_ISOB | CSC.SEARCH_MASK_ISOA;
                Status     = CSC.SearchCardExt(ref SearchExtender, SearchMask, 1, 20, ref Com, ref lgATR, ATR);
                Console.WriteLine("lgATr " + lgATR);
                Console.WriteLine("SearchExtender " + SearchExtender.ISOA + " " + SearchExtender.ISOB);
                Console.WriteLine("ATR", CSC.ToStringN(ATR));
                Console.WriteLine("Status " + Status);
                if (Status != CSC.RCSC_Ok)
                {
                    txtCom.Text = "Error :" + Status.ToString("X");
                }
                else
                {
                    txtCom.Text = Com.ToString("X");
                }
                if (Com == 2)
                {
                    txtCard.Text = "ISO14443A-4 no Calypso";
                }
                else if (Com == 3)
                {
                    txtCard.Text = "INNOVATRON";
                }
                else if (Com == 4)
                {
                    txtCard.Text = "ISOB14443B-4 Calypso";
                }
                else if (Com == 5)
                {
                    txtCard.Text = "Mifare";
                }
                else if (Com == 6)
                {
                    txtCard.Text = "CTS or CTM";
                }
                else if (Com == 8)
                {
                    txtCard.Text = "ISO14443A-3 ";
                }
                else if (Com == 9)
                {
                    txtCard.Text = "ISOB14443B-4 Calypso";
                }
                else if (Com == 12)
                {
                    txtCard.Text = "ISO14443A-4 Calypso";
                }
                else if (Com == 0x6F)
                {
                    txtCard.Text = "Card not found";
                }
                else
                {
                    txtCard.Text = "";
                }


                select_appli();
                select_file(new byte[] { 0xE1, 0x03 });
                var result = read_binary(0x0F);

                byte[] buffOut   = result.Key;
                int    read      = result.Value;
                short  maxLe     = (short)(buffOut[3] << 8 | buffOut[4]);
                int    maxLc     = buffOut[5] << 8 | buffOut[6];
                byte[] lid       = new byte[] { buffOut[9], buffOut[10] };
                int    maxLength = buffOut[11] << 8 | buffOut[12];

                select_file(new byte[] { lid[0], lid[1] });
                Console.WriteLine("maxLength : " + maxLength);
                Console.WriteLine("maxLe : " + maxLe);
                Console.WriteLine("maxLc : " + maxLc);

                //multiple readbinary in order to have the complete message
                var fileData = new List <byte>();
                for (Int16 i = 0; i < maxLength; i += maxLe)
                {
                    result = read_binary((Int16)Math.Min(maxLe, maxLength - i), i);
                    fileData.AddRange(result.Key);
                }


                Console.WriteLine(CSC.ToStringN(fileData.ToArray()) + "\n aa" + fileData.Count);
                readContent(fileData.ToArray());
            }
            catch (Exception exp)
            {
                Console.WriteLine("error :" + exp);
                MessageBox.Show("Error on trying do deal with reader");
            }

            AskReaderLib.CSC.Close();
        }
        /*
         * WRITING CODE
         */
        private void Button1_Click(object sender, EventArgs e)
        {
            results.Clear();
            CSC.sCARD_SearchExtTag SearchExtender;
            int Status;

            byte[] ATR;
            ATR = new byte[200];
            int lgATR;

            lgATR = 200;
            int Com = 0;
            int SearchMask;

            txtCom.Text  = "";
            txtCard.Text = "";

            try
            {
                CSC.SearchCSC();
                // user can also use line below to speed up coupler connection
                //AskReaderLib.CSC.Open ("COM2");

                // Define type of card to be detected: number of occurence for each loop
                SearchExtender.CONT   = 0;
                SearchExtender.ISOB   = 2;
                SearchExtender.ISOA   = 2;
                SearchExtender.TICK   = 0;
                SearchExtender.INNO   = 0;
                SearchExtender.MIFARE = 0;
                SearchExtender.MV4k   = 0;
                SearchExtender.MV5k   = 0;
                SearchExtender.MONO   = 0;
                Status = CSC.CSC_EHP_PARAMS_EXT(1, 1, 0, 0, 0, 0, 0, 0, null, 0, 0);
                // Define type of card to be detected
                SearchMask = CSC.SEARCH_MASK_ISOB | CSC.SEARCH_MASK_ISOA;
                Status     = CSC.SearchCardExt(ref SearchExtender, SearchMask, 1, 20, ref Com, ref lgATR, ATR);
                Console.WriteLine("lgATr " + lgATR);
                Console.WriteLine("SearchExtender " + SearchExtender.ISOA + " " + SearchExtender.ISOB);
                Console.WriteLine("ATR", CSC.ToStringN(ATR));
                Console.WriteLine("Status " + Status);
                if (Status != CSC.RCSC_Ok)
                {
                    txtCom.Text = "Error :" + Status.ToString("X");
                }
                else
                {
                    txtCom.Text = Com.ToString("X");
                }
                if (Com == 2)
                {
                    txtCard.Text = "ISO14443A-4 no Calypso";
                }
                else if (Com == 3)
                {
                    txtCard.Text = "INNOVATRON";
                }
                else if (Com == 4)
                {
                    txtCard.Text = "ISOB14443B-4 Calypso";
                }
                else if (Com == 5)
                {
                    txtCard.Text = "Mifare";
                }
                else if (Com == 6)
                {
                    txtCard.Text = "CTS or CTM";
                }
                else if (Com == 8)
                {
                    txtCard.Text = "ISO14443A-3 ";
                }
                else if (Com == 9)
                {
                    txtCard.Text = "ISOB14443B-4 Calypso";
                }
                else if (Com == 12)
                {
                    txtCard.Text = "ISO14443A-4 Calypso";
                }
                else if (Com == 0x6F)
                {
                    txtCard.Text = "Card not found";
                }
                else
                {
                    txtCard.Text = "";
                }


                select_appli();
                select_file(new byte[] { 0xE1, 0x03 });
                var result = read_binary(0x0F);

                byte[] buffOut   = result.Key;
                int    read      = result.Value;
                short  maxLe     = (short)(buffOut[3] << 8 | buffOut[4]);
                int    maxLc     = buffOut[5] << 8 | buffOut[6];
                byte[] lid       = new byte[] { buffOut[9], buffOut[10] };
                int    maxLength = buffOut[11] << 8 | buffOut[12];

                select_file(new byte[] { lid[0], lid[1] });
                Console.WriteLine("maxLength : " + maxLength);
                Console.WriteLine("maxLe : " + maxLe);
                Console.WriteLine("maxLc : " + maxLc);

                //get infos from box in UI
                string texte    = RawBox.Text;
                string data     = TextBox.Text;
                string uri      = UriBox.Text;
                string protocol = listBox1.Text;


                writeContent(maxLc, uri, texte, data, protocol);
                //testWriteContent();

                Console.WriteLine("outOfwrite");
            }
            catch (Exception exp)
            {
                Console.WriteLine("error :" + exp);
                MessageBox.Show("Error on trying do deal with reader");
            }

            AskReaderLib.CSC.Close();
        }