Пример #1
0
        private void writeButton_Click(object sender, EventArgs e)
        {
            this.FormClosing += RFIDDumpForm_FormClosing;
            if (_programmer.IsBusy || (_programmer == null))
            {
                return;
            }

            string ems    = EM4100Support.Get64BitSequense(((DynamicByteProvider)(hexBox.ByteProvider)).Bytes.ToArray());
            string block1 = "100" + ems.Substring(0, 32) + "001";
            string block2 = "100" + ems.Substring(32) + "010";

            string Coding   = "01000";
            string DataRate = "101";

            if (rf16datarateRadioButton.Checked)
            {
                DataRate = "001";
            }
            else if (rf32datarateRadioButton.Checked)
            {
                DataRate = "010";
            }
            else if (rf64datarateRadioButton.Checked)
            {
                DataRate = "101";
            }

            if (manchesterRadioButton.Checked)
            {
                Coding = "01000";
            }
            else if (biphaseRadioButton.Checked)
            {
                Coding = "10000";
            }

            string block0 = "10000010000000" + DataRate + "0" + Coding + "000001000000000";

            byte[] block1bytes = GetWriteSequense(block1);
            byte[] block2bytes = GetWriteSequense(block2);
            byte[] block0bytes = GetWriteSequense(block0);

            List <byte[]> request = new List <byte[]>();

            byte[] req1 = new byte[65];
            req1[1] = 0x13;
            req1[2] = 0x23;
            req1[3] = 0x26;
            req1[4] = 38;

            Array.Copy(block1bytes, 0, req1, 5, block1bytes.Length);
            request.Add(req1);

            byte[] req2 = new byte[65];
            req2[1] = 0x13;
            req2[2] = 0x23;
            req2[3] = 0x26;
            req2[4] = 38;

            Array.Copy(block2bytes, 0, req2, 5, block2bytes.Length);
            request.Add(req2);

            byte[] req0 = new byte[65];
            req0[1] = 0x13;
            req0[2] = 0x23;
            req0[3] = 0x26;
            req0[4] = 38;

            Array.Copy(block0bytes, 0, req0, 5, block0bytes.Length);
            request.Add(req0);

            Action <ProgrammingCompleteInfo, MemoryRegion> completedRead =
                delegate(ProgrammingCompleteInfo pcInfo, MemoryRegion region)
            {
                if (pcInfo.error != null)
                {
                    infoPanel.SetErrorState(pcInfo.error.Message);
                }
                else
                {
                    RFDemodulator demod = new RFDemodulator(region.Data);
                    if (!demod.IsValid)
                    {
                        infoPanel.SetErrorState("No transponder");
                    }
                    else
                    {
                        EM4100Support em = new EM4100Support(demod);
                        em.DecoderProcess();
                        if (em.IsValid)
                        {
                            byte[] wdata = ((DynamicByteProvider)(hexBox.ByteProvider)).Bytes.ToArray();
                            bool   ok    = true;
                            for (int i = 0; i < 5; i++)
                            {
                                if (wdata[i] != em.Data[i])
                                {
                                    infoPanel.SetErrorState("Verification error");
                                    ok = false;
                                    break;
                                }
                            }

                            if (ok)
                            {
                                infoPanel.SetOkState("Write complete");
                            }
                        }
                        else
                        {
                            infoPanel.SetErrorState("Verification error " + em.ErrorInfo);
                        }
                    }
                }
                this.FormClosing -= RFIDDumpForm_FormClosing;
            };

            Action <ProgrammingCompleteInfo, MemoryRegion> completed =
                delegate(ProgrammingCompleteInfo pcInfo, MemoryRegion region)
            {
                if (pcInfo.error != null)
                {
                    infoPanel.SetErrorState(pcInfo.error.Message);
                    this.FormClosing -= RFIDDumpForm_FormClosing;
                }
                else
                {
                    infoPanel.SetProgressState("Verification");
                    byte[] request2 = new byte[65];

                    request2[1] = Constants.RFID125_READ;
                    request2[2] = 0x23;
                    request2[3] = 0x26;

                    //Thread.Sleep(500);
                    _programmer.Read(request2, completedRead, infoPanel.GetProgressDelegate());
                }
            };


            infoPanel.SetProgressState("Write");

            _programmer.Write(request, completed, infoPanel.GetProgressDelegate());
        }
Пример #2
0
        private void readButton_Click(object sender, EventArgs e)
        {
            this.FormClosing += RFIDDumpForm_FormClosing;
            if (_programmer.IsBusy || (_programmer == null))
            {
                return;
            }
            byte[] request = new byte[65];

            request[1] = Constants.RFID125_READ;
            request[2] = 0x23;
            request[3] = 0x26;


            Action <ProgrammingCompleteInfo, MemoryRegion> completed =
                delegate(ProgrammingCompleteInfo pcInfo, MemoryRegion region)
            {
                if (pcInfo.error != null)
                {
                    infoPanel.SetErrorState(pcInfo.error.Message);
                }
                else
                {
                    RFDemodulator demod = new RFDemodulator(region.Data);
                    if (!demod.IsValid)
                    {
                        infoPanel.SetErrorState("No transponder");
                    }
                    else
                    {
                        EM4100Support em = new EM4100Support(demod);
                        em.DecoderProcess();
                        if (em.IsValid)
                        {
                            infoPanel.SetOkState("Read complete");
                            this.hexBox.ByteProvider = new DynamicByteProvider(em.Data);
                            if (demod.DataRate == 16)
                            {
                                rf16datarateRadioButton.Checked = true;
                            }
                            else if (demod.DataRate == 32)
                            {
                                rf32datarateRadioButton.Checked = true;
                            }
                            else if (demod.DataRate == 64)
                            {
                                rf64datarateRadioButton.Checked = true;
                            }

                            if (em.CodingMethod == "Manchester")
                            {
                                manchesterRadioButton.Checked = true;
                            }
                            if (em.CodingMethod == "Bi-phase")
                            {
                                biphaseRadioButton.Checked = true;
                            }

                            hexBox.ByteProvider.Changed += HexBoxChanged;
                            Text = "EM4100 DUMP " + "It is read from transponder";
                        }
                        else
                        {
                            infoPanel.SetErrorState(em.ErrorInfo);
                        }
                    }
                }
                this.FormClosing -= RFIDDumpForm_FormClosing;
            };


            infoPanel.SetProgressState("Read");

            _programmer.Read(request, completed, infoPanel.GetProgressDelegate());
        }
Пример #3
0
 public EM4100Support(RFDemodulator demod)
 {
     _demod = demod;
     _decoders.Add(ManchesterDecoder);
     _decoders.Add(BiphaseDecoder);
 }