Esempio n. 1
0
 public RFIDReader(EnumPSite site, string ip, int port = 3001)
 {
     Site               = site;
     IPAddress          = ip;
     Port               = port;
     HFReader           = new HFReader();
     HFReader.CommEvent = new CommEventCS();
     ConnectAsync();
 }
Esempio n. 2
0
        private void DoRequest()
        {
            short  icdev = 0x0000;
            int    status;
            byte   bcnt = 0x04; //mifare
            IntPtr pSnr;
            byte   len  = 255;
            sbyte  size = 0;

            pSnr = Marshal.AllocHGlobal(1024);

            for (int i = 0; i < 2; i++)
            {
                //
                status = HFReader.rf_anticoll(icdev, bcnt, pSnr, ref len);
                if (status != 0)
                {
                    continue;
                }

                status = HFReader.rf_select(icdev, pSnr, len, ref size);
                if (status != 0)
                {
                    continue;
                }

                byte[] szBytes = new byte[len];

                for (int j = 0; j < len; j++)
                {
                    szBytes[j] = Marshal.ReadByte(pSnr, j);
                }

                String m_cardNo = String.Empty;

                for (int q = 0; q < len; q++)
                {
                    m_cardNo += Utils.byteHEX(szBytes[q]);
                }
                txtSearchPurse.Text = m_cardNo;

                break;
            }

            Marshal.FreeHGlobal(pSnr);
        }
Esempio n. 3
0
        private void btnReadSector3_Click(object sender, EventArgs e)
        {
            short icdev = 0x0000;
            int   status;
            byte  mode  = 0x60;
            byte  secnr = 0x00;

            txtDataOne3.Text   = "";
            txtDataTwo3.Text   = "";
            txtDataThree3.Text = "";
            txtKeyA3.Text      = "";
            txtKey3.Text       = "";
            txtKeyB3.Text      = "";

            if (rbtKeyB3.Checked)
            {
                mode = 0x61;
            }

            secnr = Convert.ToByte(cbxMass3.Text);

            IntPtr keyBuffer = Marshal.AllocHGlobal(1024);

            byte[] bytesKey = Utils.ToDigitsBytes(txtInputKey3.Text);
            for (int i = 0; i < bytesKey.Length; i++)
            {
                Marshal.WriteByte(keyBuffer, i, bytesKey[i]);
            }
            status = HFReader.rf_M1_authentication2(icdev, mode, (byte)(secnr * 4), keyBuffer);
            Marshal.FreeHGlobal(keyBuffer);
            if (status != 0)
            {
                MessageBox.Show("rf_M1_authentication2 failed!!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            IntPtr dataBuffer = Marshal.AllocHGlobal(1024);

            for (int i = 0; i < 4; i++)
            {
                int  j;
                byte cLen = 0;
                status = HFReader.rf_M1_read(icdev, (byte)((secnr * 4) + i), dataBuffer, ref cLen);

                if (status != 0 || cLen != 16)
                {
                    MessageBox.Show("rf_M1_read failed!!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Marshal.FreeHGlobal(dataBuffer);
                    return;
                }

                byte[] bytesData = new byte[16];
                for (j = 0; j < bytesData.Length; j++)
                {
                    bytesData[j] = Marshal.ReadByte(dataBuffer, j);
                }

                if (i == 0)
                {
                    txtDataOne3.Text = Utils.ToHexString(bytesData);
                }
                else if (i == 1)
                {
                    txtDataTwo3.Text = Utils.ToHexString(bytesData);
                }
                else if (i == 2)
                {
                    txtDataThree3.Text = Utils.ToHexString(bytesData);
                }
                else if (i == 3)
                {
                    byte[] byteskeyA = new byte[6];
                    byte[] byteskey  = new byte[4];
                    byte[] byteskeyB = new byte[6];

                    for (j = 0; j < 16; j++)
                    {
                        if (j < 6)
                        {
                            byteskeyA[j] = bytesData[j];
                        }
                        else if (j >= 6 && j < 10)
                        {
                            byteskey[j - 6] = bytesData[j];
                        }
                        else
                        {
                            byteskeyB[j - 10] = bytesData[j];
                        }
                    }

                    txtKeyA3.Text = ""; // Utils.ToHexString(byteskeyA);
                    txtKey3.Text  = Utils.ToHexString(byteskey);
                    txtKeyB3.Text = Utils.ToHexString(byteskeyB);
                }
            }
            Marshal.FreeHGlobal(dataBuffer);
        }
Esempio n. 4
0
        private void DoWriteBlock(int blockNo)
        {
            short icdev = 0x0000;
            int   status;
            byte  mode  = 0x60;
            byte  secnr = 0x00;
            byte  adr;
            int   i;

            if (rbtKeyB3.Checked)
            {
                mode = 0x61;
            }

            secnr = Convert.ToByte(cbxMass3.Text);
            adr   = (byte)(blockNo + secnr * 4);

            if (blockNo == 3)
            {
                if (DialogResult.No == MessageBox.Show("Are you sure you want to overwrite block3!", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
                {
                    return;
                }
            }

            IntPtr keyBuffer = Marshal.AllocHGlobal(1024);

            byte[] bytesKey = Utils.ToDigitsBytes(txtInputKey3.Text);
            for (i = 0; i < bytesKey.Length; i++)
            {
                Marshal.WriteByte(keyBuffer, i, bytesKey[i]);
            }
            status = HFReader.rf_M1_authentication2(icdev, mode, (byte)(secnr * 4), keyBuffer);
            Marshal.FreeHGlobal(keyBuffer);
            if (status != 0)
            {
                MessageBox.Show("rf_M1_authentication2 failed!!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //
            byte[] bytesBlock;
            if (blockNo == 0)
            {
                bytesBlock = Utils.ToDigitsBytes(txtDataOne3.Text);
            }
            else if (blockNo == 1)
            {
                bytesBlock = Utils.ToDigitsBytes(txtDataTwo3.Text);
            }
            else if (blockNo == 2)
            {
                bytesBlock = Utils.ToDigitsBytes(txtDataThree3.Text);
            }
            else
            {
                if (string.IsNullOrEmpty(txtKeyA3.Text) || txtKeyA3.Text.Length < 12)
                {
                    MessageBox.Show("Please enter keyA (12 symbols)");
                    return;
                }
                String strBlock3 = txtKeyA3.Text;
                strBlock3 += txtKey3.Text;
                strBlock3 += txtKeyB3.Text;
                bytesBlock = Utils.ToDigitsBytes(strBlock3);
            }

            IntPtr dataBuffer = Marshal.AllocHGlobal(1024);

            for (i = 0; i < bytesBlock.Length; i++)
            {
                Marshal.WriteByte(dataBuffer, i, bytesBlock[i]);
            }
            status = HFReader.rf_M1_write(icdev, adr, dataBuffer);
            Marshal.FreeHGlobal(dataBuffer);

            if (status != 0)
            {
                MessageBox.Show("rf_M1_write failed!!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Esempio n. 5
0
 public string ReadHexString()
 {
     return(Status_enum.SUCCESS == HFReader.ReadMBlock(ReaderID, Opcode, UID, StartBlock, BlockCnt, ref Data, ref DataLen, Antenna) ? BytesToHexString(Data, DataLen) : string.Empty);
 }
Esempio n. 6
0
 public byte[] ReadBytes()
 {
     return(Status_enum.SUCCESS == HFReader.ReadMBlock(ReaderID, Opcode, UID, StartBlock, BlockCnt, ref Data, ref DataLen, Antenna) ? Data.Take(DataLen).ToArray() : null);
 }
Esempio n. 7
0
 /// <summary>
 /// 写数据(32 Byte)
 /// </summary>
 /// <param name="data">32 Byte</param>
 /// <returns></returns>
 public bool WriteBytes(byte[] data)
 {
     return(Status_enum.SUCCESS == HFReader.WriteMBlock(ReaderID, Opcode, UID, StartBlock, BlockCnt, (int)BlockSize, data, Antenna));
 }
Esempio n. 8
0
 public async Task DisconnectAsync()
 {
     await Task.Run(() => HFReader.DisConnect());
 }
Esempio n. 9
0
 public async Task <bool> ConnectAsync()
 {
     return(await Task.Run(() => HFReader.Connect(IPAddress, Port)));
 }