Example #1
0
        private int CardConnect(int connType)
        {
            //bool functionReturnValue = false;

            if (connActive)
            {
                retCode = ModWinsCard.SCardDisconnect(hCard, ModWinsCard.SCARD_UNPOWER_CARD);
            }

            //Connect
            retCode = ModWinsCard.SCardConnect(hContext, cbReader.Text, ModWinsCard.SCARD_SHARE_SHARED, ModWinsCard.SCARD_PROTOCOL_T0 | ModWinsCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                if (connType != 1)
                {
                    displayOut(1, retCode, "");
                }
                connActive = false;
                return(retCode);
            }

            else
            {
                if (connType != 1)
                {
                    displayOut(0, 0, "Successful connection to " + cbReader.Text);
                }

                //functionReturnValue = retCode;
            }
            return(retCode);
        }
Example #2
0
        private void bConnect_Click(object sender, EventArgs e)
        {
            retCode = ModWinsCard.SCardConnect(hContext, cbReader.SelectedItem.ToString(), ModWinsCard.SCARD_SHARE_SHARED,
                                               ModWinsCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                retCode = ModWinsCard.SCardConnect(hContext, cbReader.SelectedItem.ToString(), ModWinsCard.SCARD_SHARE_DIRECT,
                                                   0, ref hCard, ref Protocol);


                if (retCode != ModWinsCard.SCARD_S_SUCCESS)
                {
                    displayOut(1, retCode, "");
                }
                else
                {
                    displayOut(0, 0, "Successful connection to " + cbReader.Text);
                }
            }
            else
            {
                displayOut(0, 0, "Successful connection to " + cbReader.Text);
            }

            GetFirmware();
        }
Example #3
0
        private void bConnect_Click(object sender, EventArgs e)
        {
            retCode = ModWinsCard.SCardConnect(hContext, cbReader.SelectedItem.ToString(), ModWinsCard.SCARD_SHARE_SHARED,
                                               ModWinsCard.SCARD_PROTOCOL_T0 | ModWinsCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                displayOut(1, retCode, "");
            }
            else
            {
                displayOut(0, 0, "Successful connection to " + cbReader.Text);
            }
            connActive         = true;
            bClear.Enabled     = true;
            cbOpt1.Checked     = true;
            cbOpt2.Checked     = true;
            cbOpt3.Checked     = true;
            cbOpt4.Checked     = true;
            cbOpt5.Checked     = true;
            cbOpt6.Checked     = true;
            cbOpt7.Checked     = true;
            gbPollOpt.Enabled  = true;
            bStartPoll.Enabled = true;
            opt250.Checked     = true;
        }
Example #4
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            retCode = ModWinsCard.SCardConnect(hContext, ddlReaderList.SelectedItem.ToString(), ModWinsCard.SCARD_SHARE_SHARED,
                                               ModWinsCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                retCode = ModWinsCard.SCardConnect(hContext, ddlReaderList.SelectedItem.ToString(), ModWinsCard.SCARD_SHARE_DIRECT,
                                                   0, ref hCard, ref Protocol);
                if (retCode != ModWinsCard.SCARD_S_SUCCESS)
                {
                    WriteLog(1, retCode, "");
                }
                else
                {
                    WriteLog(0, 0, "Connected to " + ddlReaderList.Text);//Successful connection to
                }
            }
            else
            {
                WriteLog(0, 0, "Connected to " + ddlReaderList.Text);//Successful connection to
            }

            GetUID();

            connActive = true;
        }
Example #5
0
        private void bConnect_Click(object sender, EventArgs e)
        {
            retCode = ModWinsCard.SCardConnect(hContext, cbReader.SelectedItem.ToString(), ModWinsCard.SCARD_SHARE_SHARED,
                                               ModWinsCard.SCARD_PROTOCOL_T0 | ModWinsCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                displayOut(1, retCode, "");
            }
            else
            {
                displayOut(0, 0, "Successful connection to " + cbReader.Text);
            }
            connActive                  = true;
            bGetFW.Enabled              = true;
            gbAntenna.Enabled           = true;
            gbRed.Enabled               = true;
            gbGreen.Enabled             = true;
            gbBlinkDuration.Enabled     = true;
            bSetLED.Enabled             = true;
            bGetFW.Enabled              = true;
            rbAntOn.Checked             = true;
            rbRedFinalOff.Checked       = true;
            rbRedStateMaskOff.Checked   = true;
            rbRedInitOff.Checked        = true;
            rbRedBlinkMaskOff.Checked   = true;
            rbGreenFinalOff.Checked     = true;
            rbGreenStateMaskOff.Checked = true;
            rbGreenInitOff.Checked      = true;
            rbGreenBlinkMaskOff.Checked = true;
            rbLinkToBuzzOpt1.Checked    = true;
            tT1.Text     = "00";
            tT2.Text     = "00";
            tRepeat.Text = "01";
        }
        private void bConnect_Click(object sender, EventArgs e)
        {
            retCode = ModWinsCard.SCardConnect(hContext, cbReader.SelectedItem.ToString(), ModWinsCard.SCARD_SHARE_SHARED,
                                               ModWinsCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                retCode = ModWinsCard.SCardConnect(hContext, cbReader.SelectedItem.ToString(), ModWinsCard.SCARD_SHARE_DIRECT,
                                                   0, ref hCard, ref Protocol);
                if (retCode != ModWinsCard.SCARD_S_SUCCESS)
                {
                    displayOut(1, retCode, "");
                }
                else
                {
                    displayOut(0, 0, "成功连接到" + cbReader.Text);//Successful connection to
                }
            }
            else
            {
                displayOut(0, 0, "成功连接到" + cbReader.Text);
            }
            GetUID();
            connActive         = true;
            gbLoadKeys.Enabled = true;
            gbAuth.Enabled     = true;
            gbBinOps.Enabled   = true;
            groupBox1.Enabled  = true;
            tKeyNum.Focus();
            rbKType1.Checked = true;
            btnClear.Enabled = true;
            btnRead.Enabled  = true;
            btnWrite.Enabled = true;
        }
Example #7
0
        private bool Connect()
        {
            bool ReturnedValue;

            retCode = ModWinsCard.SCardConnect(hContext, cbReader.SelectedItem.ToString(), ModWinsCard.SCARD_SHARE_SHARED,
                                               ModWinsCard.SCARD_PROTOCOL_T0 | ModWinsCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                if (retCode == ModWinsCard.SCARD_W_REMOVED_CARD)
                {
                    displayOut(0, 0, "Error: There is no card on the reader.");
                }
                else
                {
                    displayOut(0, 0, "Error: Unxepected error.");
                }
                ReturnedValue = false;
            }
            else
            {
                displayOut(0, 0, "Successful connection to " + cbReader.Text);
                ReturnedValue = true;
            }
            connActive = true;
            return(ReturnedValue);
        }
Example #8
0
        private void CardCk()
        {
            bool absent = false;

            //Establish Context
            retCode = ModWinsCard.SCardEstablishContext(ModWinsCard.SCARD_SCOPE_USER, 0, 0, ref hContext);

            if (retCode == ModWinsCard.SCARD_S_SUCCESS)
            {
                while (!Present)
                {
                    Success          = true;
                    RdrState.RdrName = "ACS ACR122 0";
                    //Check Card Status
                    retCode = ModWinsCard.SCardGetStatusChangeA(this.hContext, 0, ref RdrState, 1);

                    if (retCode == ModWinsCard.SCARD_S_SUCCESS)
                    {
                        Success = true;
                        if ((Convert.ToUInt32(RdrState.RdrEventState) & ModWinsCard.SCARD_STATE_PRESENT) == ModWinsCard.SCARD_STATE_PRESENT)
                        {
                            retCode = ModWinsCard.SCardConnect(hContext, RdrState.RdrName, ModWinsCard.SCARD_SHARE_SHARED,
                                                               ModWinsCard.SCARD_PROTOCOL_T0 | ModWinsCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol);

                            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
                            {
                                Success = false;
                                MessageBox.Show(ModWinsCard.GetScardErrMsg(retCode));
                            }
                            else
                            {
                                Success    = true;
                                connActive = true;
                                Present    = true;
                            }
                        }
                        if ((Convert.ToUInt32(RdrState.RdrEventState) & ModWinsCard.SCARD_STATE_EMPTY) == ModWinsCard.SCARD_STATE_EMPTY &&
                            !absent)
                        {
                            absent     = true;
                            connActive = false;
                        }
                    }
                    else
                    {
                        Success = false;
                        MessageBox.Show(ModWinsCard.GetScardErrMsg(retCode));
                    }
                }
            }
            else
            {
                Success = false;
                MessageBox.Show(ModWinsCard.GetScardErrMsg(retCode));
            }

            OnCardPresent();
            OnCardAbsent();
        }
Example #9
0
        private void bConnect_Click(object sender, EventArgs e)
        {
            retCode = ModWinsCard.SCardConnect(hContext, cbReader.SelectedItem.ToString(), ModWinsCard.SCARD_SHARE_EXCLUSIVE,
                                               ModWinsCard.SCARD_PROTOCOL_T0 | ModWinsCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                displayOut(1, retCode, "");
            }
            else
            {
                displayOut(0, 0, "SCardConnect...OK");
            }
        }
Example #10
0
        private void bConnect_Click(object sender, EventArgs e)
        {
            retCode = ModWinsCard.SCardConnect(hContext, cbReader.SelectedItem.ToString(), ModWinsCard.SCARD_SHARE_SHARED,
                                               ModWinsCard.SCARD_PROTOCOL_T0 | ModWinsCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                displayOut(1, retCode, "");
            }
            else
            {
                displayOut(0, 0, "Successful connection to " + cbReader.Text);
            }
            connActive         = true;
            gbGetData.Enabled  = true;
            gbSendApdu.Enabled = true;
            tCLA.Focus();
        }
        private static void InitialiseSmartCardReader()
        {
            Array.Clear(SendBuff, 0, 262);
            Array.Clear(RecvBuff, 0, 262);

            //Establishes the context
            retCode = ModWinsCard.SCardEstablishContext(ModWinsCard.SCARD_SCOPE_USER, 0, 0, ref hContext);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                throw new Exception(retCode.ToString());
            }

            //Verify how many bytes does the reader name has
            retCode = ModWinsCard.SCardListReaders(hContext, null, null, ref Readercount);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                throw new Exception(retCode.ToString());
            }

            //Creates the byte array to receive the name
            ReaderListBuff = new byte[Readercount];
            //Gets the readers name
            retCode = ModWinsCard.SCardListReaders(hContext, ReaderGroupBuff, ReaderListBuff, ref Readercount);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                throw new Exception(retCode.ToString());
            }

            //Decodify the readers name
            sCard = System.Text.Encoding.ASCII.GetString(ReaderListBuff);

            //Connects to the reader
            retCode = ModWinsCard.SCardConnect(hContext, sCard, ModWinsCard.SCARD_SHARE_SHARED, ModWinsCard.SCARD_PROTOCOL_T0, ref hCard, ref Protocol);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                throw new Exception(retCode.ToString());
            }
        }
Example #12
0
        private void bConnect_Click(object sender, EventArgs e)
        {
            retCode = ModWinsCard.SCardConnect(hContext, cbReader.SelectedItem.ToString(), ModWinsCard.SCARD_SHARE_SHARED,
                                               ModWinsCard.SCARD_PROTOCOL_T0 | ModWinsCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                displayOut(1, retCode, "");
            }
            else
            {
                displayOut(0, 0, "Successful connection to " + cbReader.Text);
            }
            connActive         = true;
            gbLoadKeys.Enabled = true;
            gbAuth.Enabled     = true;
            gbBinOps.Enabled   = true;
            gbValBlk.Enabled   = true;
            tKeyNum.Focus();
            rbKType1.Checked = true;
        }
Example #13
0
        private void btnConnect_Click(object sender, System.EventArgs e)
        {
            // Connect to selected reader using hContext handle and obtain hCard handle
            if (connActive)
            {
                retcode = ModWinsCard.SCardDisconnect(hCard, ModWinsCard.SCARD_UNPOWER_CARD);
            }

            // Connect to the reader using hContext handle and obtain hCard handle
            retcode = ModWinsCard.SCardConnect(hContext, cbReader.Text, ModWinsCard.SCARD_SHARE_EXCLUSIVE, 0 | 1, ref hCard, ref ActiveProtocol);
            if (retcode != ModWinsCard.SCARD_S_SUCCESS)
            {
                displayOut(1, retcode, "");
                return;
            }
            else
            {
                displayOut(0, 0, "Connection OK");
                connActive = true;
            }

            btnFormat.Enabled = true;
            RBAA11.Checked    = true;
        }
Example #14
0
        private void Connect()
        {
            if (IsConnected)
            {
                _returnCode = ModWinsCard.SCardDisconnect(_hCard, ModWinsCard.SCARD_EJECT_CARD);

                IsConnected = false;
            }

            //_returnCode = APDUCommands.SetPICCParams(_piccParams);
            _returnCode = ModWinsCard.SCardConnect(_hContext, _name, ModWinsCard.SCARD_SHARE_SHARED, ModWinsCard.SCARD_PROTOCOL_T0 | ModWinsCard.SCARD_PROTOCOL_T1, ref _hCard, ref _protocol);

            if (_returnCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                _returnCode = ModWinsCard.SCardConnect(_hContext, _name, ModWinsCard.SCARD_SHARE_DIRECT, ModWinsCard.SCARD_PROTOCOL_UNDEFINED, ref _hCard, ref _protocol);

                if (_returnCode != ModWinsCard.SCARD_S_SUCCESS)
                {
                    throw new ApplicationException(@"Failed to connect to reader " + _name, new ApplicationException(ModWinsCard.GetScardErrMsg(_returnCode)));
                }
            }

            IsConnected = true;
        }