int IM24CXXProgrammer.ReadChip(string chip, MemoryRegionInfo regionInfo, Action <ProgrammingCompleteInfo, MemoryRegion> completed, Action <ProgrammingProgressInfo> progress)
        {
            _isBusy = true;


            AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(new Guid());

            Action <int, int> progressAct = delegate(int val, int max)
            {
                asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, val, max))); }, null);
            };



            ThreadStart start = delegate()
            {
                asyncOp.Post(delegate(object args) { OnBusy(); }, null);
                //MemoryRegion region = null;
                ProgrammingCompleteInfo pcInfo = new ProgrammingCompleteInfo();

                I2CReadPacketsFactory pf = new I2CReadPacketsFactory(regionInfo);

                try
                {
                    ExchangeWithDevice(pf, progressAct);
                }
                catch (Exception e)
                {
                    pcInfo.error = e;
                }
                pcInfo.Message = "Read complete";
                asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, 0, 1))); }, null);

                asyncOp.Post(delegate(object args) { completed(pcInfo, pf.GetRegion()); }, null);
                _isBusy = false;
                asyncOp.PostOperationCompleted(delegate(object args) { OnReady(); }, null);
            };

            (new Thread(start)).Start();

            return(0);
        }
Exemple #2
0
        public override void ProgramFirmware(List <MemoryRegion> regions, Action <ProgrammingCompleteInfo> completed, Action <ProgrammingProgressInfo> progress)
        {
            AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(new Guid());

            Action <int, int> progressAct = delegate(int val, int max)
            {
                asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, val, max))); }, null);
            };

            ThreadStart start = delegate()
            {
                ProgrammingCompleteInfo pcInfo = new ProgrammingCompleteInfo();

                try
                {
                    SafeFileHandle handle = CreateFile(_hardwarePath, Win32HardwareIOSupport.GENERIC_WRITE | Win32HardwareIOSupport.GENERIC_READ,
                                                       Win32HardwareIOSupport.FILE_SHARE_WRITE | Win32HardwareIOSupport.FILE_SHARE_READ, IntPtr.Zero, Win32HardwareIOSupport.OPEN_EXISTING, 0, IntPtr.Zero);

                    if (handle.IsInvalid)
                    {
                        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    }

                    using (FileStream harwareStream = new FileStream(handle, FileAccess.ReadWrite, 65))
                    {
                        //UpdateCurrentMemRegConfig(harwareStream);

                        if (_currentMemoryRegionsConfig.Count != 4)
                        {
                            Exception e1      = Marshal.GetExceptionForHR((int)((Convert.ToUInt32(4319) | 0x80070000)));
                            Exception e2      = Marshal.GetExceptionForHR((int)((Convert.ToUInt32(1784) | 0x80070000)));
                            string    message = e1.Message.Substring(0, e1.Message.IndexOf("(")) +
                                                e2.Message.Substring(0, e2.Message.IndexOf("("));
                            throw new Exception(message);
                        }

                        EraseHardware(harwareStream);

                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo("Config data programming")); }, null);
                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, 0, 1))); }, null);
                        ProgramRegion(harwareStream, regions[1], progressAct);

                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo("Program data programming")); }, null);
                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, 0, 1))); }, null);
                        ProgramRegion(harwareStream, regions[0], progressAct);

                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo("Setting data programming")); }, null);
                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, 0, 1))); }, null);
                        ProgramRegion(harwareStream, regions[2], progressAct);

                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo("EEPROM programming")); }, null);
                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, 0, 1))); }, null);
                        ProgramRegion(harwareStream, regions[3], progressAct);
                    }
                }
                catch (Exception e)
                {
                    pcInfo.error = e;
                }
                pcInfo.Message = "Programming complete";
                asyncOp.PostOperationCompleted(delegate(object args) { completed(pcInfo); }, null);
            };

            (new Thread(start)).Start();
        }
Exemple #3
0
        int IAT88Programmer.ReadChip(string crumType, List <MemoryRegionInfo> regionsInfo, Action <ProgrammingCompleteInfo, List <MemoryRegion> > completed, Action <ProgrammingProgressInfo> progress)
        {
            _isBusy = true;
            AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(new Guid());

            Action <int, int> progressAct = delegate(int val, int max)
            {
                asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, val, max))); }, null);
            };

            ThreadStart start = delegate()
            {
                asyncOp.Post(delegate(object args) { OnBusy(); }, null);
                List <MemoryRegion>     regions = null;
                ProgrammingCompleteInfo pcInfo  = new ProgrammingCompleteInfo();

                try
                {
                    SafeFileHandle handle = CreateFile(_hardwarePath, Win32HardwareIOSupport.GENERIC_WRITE | Win32HardwareIOSupport.GENERIC_READ,
                                                       Win32HardwareIOSupport.FILE_SHARE_WRITE | Win32HardwareIOSupport.FILE_SHARE_READ, IntPtr.Zero, Win32HardwareIOSupport.OPEN_EXISTING, 0, IntPtr.Zero);

                    if (handle.IsInvalid)
                    {
                        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    }

                    using (FileStream harwareStream = new FileStream(handle, FileAccess.ReadWrite, 65))
                    {
                        SetTaskNumber(harwareStream, _at88PasswordSet[crumType]);

                        UpdateCurrentMemRegConfig(harwareStream);

                        if ((_currentMemoryRegionsConfig.Count != 2))
                        {
                            Exception e1      = Marshal.GetExceptionForHR((int)((Convert.ToUInt32(4319) | 0x80070000)));
                            Exception e2      = Marshal.GetExceptionForHR((int)((Convert.ToUInt32(1784) | 0x80070000)));
                            string    message = e1.Message.Substring(0, e1.Message.IndexOf("(")) +
                                                e2.Message.Substring(0, e2.Message.IndexOf("("));
                            throw new Exception(message);
                        }
                        regions = new List <MemoryRegion>()
                        {
                            new MemoryRegion(_currentMemoryRegionsConfig[0]), new MemoryRegion(_currentMemoryRegionsConfig[1])
                        };

                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo("Read user data")); }, null);
                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, 0, 1))); }, null);
                        ReadRegion(harwareStream, regions[0], progressAct);

                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo("Read config data")); }, null);
                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, 0, 1))); }, null);
                        ReadRegion(harwareStream, regions[1], progressAct);
                    }
                }
                catch (Exception e)
                {
                    pcInfo.error = e;
                }
                pcInfo.Message = "Read complete";
                asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, 0, 1))); }, null);
                asyncOp.Post(delegate(object args) { completed(pcInfo, regions); }, null);
                _isBusy = false;
                asyncOp.PostOperationCompleted(delegate(object args) { OnReady(); }, null);
            };

            (new Thread(start)).Start();

            return(0);
        }
Exemple #4
0
        int IM24CXXProgrammer.ProgramChip(string chip, MemoryRegion region, Action <ProgrammingCompleteInfo> completed, Action <ProgrammingProgressInfo> progress)
        {
            _isBusy = true;
            AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(new Guid());

            if (chip == "24C02")
            {
                byte[] regdata = new byte[256];
                region.ReadData(0, regdata);
                region = new MemoryRegion(0, 512, 1);
                region.WriteData(0, regdata);
            }


            Action <int, int> progressAct = delegate(int val, int max)
            {
                asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, val, max))); }, null);
            };

            ThreadStart start = delegate()
            {
                asyncOp.Post(delegate(object args) { OnBusy(); }, null);

                ProgrammingCompleteInfo pcInfo = new ProgrammingCompleteInfo();

                try
                {
                    SafeFileHandle handle = CreateFile(_hardwarePath, Win32HardwareIOSupport.GENERIC_WRITE | Win32HardwareIOSupport.GENERIC_READ,
                                                       Win32HardwareIOSupport.FILE_SHARE_WRITE | Win32HardwareIOSupport.FILE_SHARE_READ, IntPtr.Zero, Win32HardwareIOSupport.OPEN_EXISTING, 0, IntPtr.Zero);

                    if (handle.IsInvalid)
                    {
                        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    }

                    using (FileStream harwareStream = new FileStream(handle, FileAccess.ReadWrite, 65))
                    {
                        SetTaskNumber(harwareStream, _m24CXXChipSet[chip]);

                        UpdateCurrentMemRegConfig(harwareStream);

                        if ((_currentMemoryRegionsConfig.Count != 1) || (_currentMemoryRegionsConfig[0] != region.GetRegionInfo()))
                        {
                            Exception e1      = Marshal.GetExceptionForHR((int)((Convert.ToUInt32(4319) | 0x80070000)));
                            Exception e2      = Marshal.GetExceptionForHR((int)((Convert.ToUInt32(1784) | 0x80070000)));
                            string    message = e1.Message.Substring(0, e1.Message.IndexOf("(")) +
                                                e2.Message.Substring(0, e2.Message.IndexOf("("));
                            throw new Exception(message);
                        }


                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo("Programming")); }, null);

                        ProgramRegion(harwareStream, region, progressAct);

                        MemoryRegion testRegion = new MemoryRegion(_currentMemoryRegionsConfig[0]);

                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo("Verification")); }, null);
                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, 0, 1))); }, null);

                        ReadRegion(harwareStream, testRegion, progressAct);

                        for (int i = 0; i < region.Size; i++)
                        {
                            if (region.Data[i] != testRegion.Data[i])
                            {
                                throw new VerificationException(region.Address + (uint)i, region.Data[i], testRegion.Data[i]);
                            }
                        }
                    }
                }
                catch (VerificationException ve)
                {
                    if ((chip == "24C02") && (ve.ErrorAddress >= 256))
                    {
                    }
                    else
                    {
                        pcInfo.error = ve;
                    }
                }
                catch (Exception e)
                {
                    pcInfo.error = e;
                }
                pcInfo.Message = "Programming complete";
                asyncOp.Post(delegate(object args) { completed(pcInfo); }, null);
                _isBusy = false;
                asyncOp.PostOperationCompleted(delegate(object args) { OnReady(); }, null);
            };

            (new Thread(start)).Start();

            return(0);
        }
        int IRFIDProgrammer.Adjust(Action <ProgrammingCompleteInfo, MemoryRegion> completed, Action <ProgrammingProgressInfo> progress)
        {
            _isBusy = true;



            AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(new Guid());

            Action <int, int> progressAct = delegate(int val, int max)
            {
                asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, val, max))); }, null);
            };

            ThreadStart start = delegate()
            {
                asyncOp.Post(delegate(object args) { OnBusy(); }, null);
                ProgrammingCompleteInfo pcInfo = new ProgrammingCompleteInfo();
                MemoryRegion            region = new MemoryRegion(0, 256, 0);


                try
                {
                    SafeFileHandle WriteHandle = CreateFile(_hardwarePath, Win32HardwareIOSupport.GENERIC_WRITE,
                                                            Win32HardwareIOSupport.FILE_SHARE_WRITE | Win32HardwareIOSupport.FILE_SHARE_READ, IntPtr.Zero, Win32HardwareIOSupport.OPEN_EXISTING, 0, IntPtr.Zero);

                    if (WriteHandle.IsInvalid)
                    {
                        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    }
                    SafeFileHandle ReadHandle = CreateFile(_hardwarePath, Win32HardwareIOSupport.GENERIC_READ,
                                                           Win32HardwareIOSupport.FILE_SHARE_WRITE | Win32HardwareIOSupport.FILE_SHARE_READ, IntPtr.Zero, Win32HardwareIOSupport.OPEN_EXISTING, 0, IntPtr.Zero);

                    if (ReadHandle.IsInvalid)
                    {
                        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    }

                    uint wrBytes;

                    byte[] request = new byte[65];

                    byte[] response = new byte[65];

                    byte maxTime = 0;
                    byte minTime = 0xFF;

                    for (int i = 0; i < 20; i++)
                    {
                        request[1] = Constants.RFID125_TEST;


                        if (!WriteFile(WriteHandle, request, 65, out wrBytes, IntPtr.Zero))
                        {
                            Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                        }

                        if (!ReadFile(ReadHandle, response, 65, out wrBytes, IntPtr.Zero))
                        {
                            Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                        }

                        if (response[3] > maxTime)
                        {
                            maxTime = response[3];
                        }
                        if (response[3] < minTime)
                        {
                            minTime = response[3];
                        }

                        progressAct(i, 20);
                    }

                    response[3] = maxTime;
                    response[4] = minTime;

                    region.WriteData(0, response);
                }
                catch (Exception e)
                {
                    pcInfo.error = e;
                }
                pcInfo.Message = "Complete";
                asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, 0, 1))); }, null);

                asyncOp.Post(delegate(object args) { completed(pcInfo, region); }, null);
                _isBusy = false;
                asyncOp.PostOperationCompleted(delegate(object args) { OnReady(); }, null);
            };

            (new Thread(start)).Start();

            return(0);
        }
        int IRFIDProgrammer.Write(List <byte[]> request, Action <ProgrammingCompleteInfo, MemoryRegion> completed, Action <ProgrammingProgressInfo> progress)
        {
            _isBusy = true;


            AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(new Guid());

            Action <int, int> progressAct = delegate(int val, int max)
            {
                asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, val, max))); }, null);
            };

            ThreadStart start = delegate()
            {
                asyncOp.Post(delegate(object args) { OnBusy(); }, null);
                ProgrammingCompleteInfo pcInfo = new ProgrammingCompleteInfo();
                MemoryRegion            region = new MemoryRegion(0, 256, 0);


                try
                {
                    SafeFileHandle WriteHandle = CreateFile(_hardwarePath, Win32HardwareIOSupport.GENERIC_WRITE,
                                                            Win32HardwareIOSupport.FILE_SHARE_WRITE | Win32HardwareIOSupport.FILE_SHARE_READ, IntPtr.Zero, Win32HardwareIOSupport.OPEN_EXISTING, 0, IntPtr.Zero);

                    if (WriteHandle.IsInvalid)
                    {
                        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    }
                    SafeFileHandle ReadHandle = CreateFile(_hardwarePath, Win32HardwareIOSupport.GENERIC_READ,
                                                           Win32HardwareIOSupport.FILE_SHARE_WRITE | Win32HardwareIOSupport.FILE_SHARE_READ, IntPtr.Zero, Win32HardwareIOSupport.OPEN_EXISTING, 0, IntPtr.Zero);

                    if (ReadHandle.IsInvalid)
                    {
                        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                    }

                    uint wrBytes;

                    byte[] respdata;

                    int step = 1;

                    foreach (byte[] req in request)
                    {
                        if (!WriteFile(WriteHandle, req, 65, out wrBytes, IntPtr.Zero))
                        {
                            Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                        }

                        respdata = new byte[65];


                        if (!ReadFile(ReadHandle, respdata, 65, out wrBytes, IntPtr.Zero))
                        {
                            Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                        }

                        if (respdata[1] != 0)
                        {
                            throw new Exception("Write error: " + respdata[1].ToString("X2"));
                        }

                        progressAct(step++, request.Count);
                    }
                }
                catch (Exception e)
                {
                    pcInfo.error = e;
                }
                pcInfo.Message = "Complete";
                asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(new ProgressBarData(0, 0, 1))); }, null);

                asyncOp.Post(delegate(object args) { completed(pcInfo, region); }, null);
                _isBusy = false;
                asyncOp.PostOperationCompleted(delegate(object args) { OnReady(); }, null);
            };

            (new Thread(start)).Start();

            return(0);
        }
        int I921Programmer.ReadChip(string mode, MemoryRegionInfo regionInfo, Action <ProgrammingCompleteInfo, MemoryRegion> completed, Action <ProgrammingProgressInfo> progress)
        {
            _isBusy = true;

            AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(new Guid());

            string infoString = "";
            string errString  = "";

            DataReceivedEventHandler processOutput = delegate(Object sender, DataReceivedEventArgs drea)
            {
                if ((drea.Data != null) && drea.Data.Contains(_readingSequense[_readingStep]))
                {
                    if (drea.Data.Contains("Done"))
                    {
                        if (infoString == "")
                        {
                            infoString += (_readingSequense[_readingStep] + " Ok");
                        }
                        else
                        {
                            infoString += ("\r\n" + _readingSequense[_readingStep] + " Ok");
                        }
                        _readingStep++;
                        asyncOp.Post(delegate(object args) { progress(new ProgrammingProgressInfo(infoString)); }, null);
                    }
                    else
                    {
                        errString = _readingSequense[_readingStep] + " Error";
                    }
                }
            };
            ThreadStart start = delegate()
            {
                asyncOp.Post(delegate(object args) { OnBusy(); }, null);
                MemoryRegion            region = new MemoryRegion(regionInfo);
                ProgrammingCompleteInfo pcInfo = new ProgrammingCompleteInfo();
                _readingStep = 0;
                try
                {
                    string path = Application.ExecutablePath;
                    path = path.Substring(0, path.LastIndexOf("\\"));
                    Directory.SetCurrentDirectory(path);


                    Process p = new Process();
                    p.StartInfo.UseShellExecute        = false;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.StartInfo.FileName       = "ps3cc921.exe";
                    p.StartInfo.CreateNoWindow = true;
                    p.OutputDataReceived      += processOutput;
                    p.Start();
                    p.BeginOutputReadLine();
                    p.WaitForExit();
                    p.Close();
                    if (errString != "")
                    {
                        throw new Exception(errString);
                    }
                    else
                    {
                        pcInfo.Message = "Reading Ok";
                        using (BinaryReader file = new BinaryReader(File.OpenRead("RS3CC921.BIN")))
                        {
                            file.BaseStream.Position = 0;

                            for (int i = 0; i < region.Data.Length; i++)
                            {
                                region.Data[i] = file.ReadByte();
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    pcInfo.error = e;
                }

                asyncOp.Post(delegate(object args) { completed(pcInfo, region); }, null);
                _isBusy = false;
                asyncOp.PostOperationCompleted(delegate(object args) { OnReady(); }, null);
            };

            (new Thread(start)).Start();

            return(0);
        }