コード例 #1
0
        public void ExcuteTest()
        {
            using (var client = PcbTesterClient.Create(PortName, BaudRate))
            {
                client.Open();

                var           eraseCommand   = new EraseSPIFlashCommand();
                var           eraseParameter = new AddressCommandParameter(0x0u);
                CommandResult eraseResult    = eraseCommand.Execute(client, eraseParameter, null);

                var readcommand0   = new ReadSPIFlashCommand();
                var readParameter0 = new AddressCommandParameter(0x0u, 4);

                CommandResult readResult0 = readcommand0.Execute(client, readParameter0, null);

                client.Write("0-0:199.128.8", new byte[] { 0x10 }, 0x0u);
#if false
                var readcommand0   = new ReadSPIFlashCommand();
                var readParameter0 = new AddressCommandParameter(0x00020000u, 4);

                CommandResult readResult0 = readcommand0.Execute(client, readParameter0, null);

                var           eraseCommand   = new EraseSPIFlashCommand();
                var           eraseParameter = new AddressCommandParameter(0x00020000u);
                CommandResult eraseResult    = eraseCommand.Execute(client, eraseParameter, null);

                var readcommand = new ReadSPIFlashCommand();
                // var parameter = new AddressCommandParameter(0x00u, 2, "FFFF");
                //var parameter = new AddressCommandParameter(0x00020000u, 4, "FFFFFFFF");
                var readParameter = new AddressCommandParameter(0x00020000u, 4);

                CommandResult readResult = readcommand.Execute(client, readParameter, null);

                var command = new WriteSPIFlashCommand();

                // var parameter = new AddressCommandParameter(0x00020000u, "00000000");

                //string writeData = "000000000000000000000000000000000000000000000000000001A650000000505000000050500000005050000000505000000050500000005050000000505000000050500000005050000000505000000050500000005050000000505000000050500000005050000000505000000050000000000000000000000000000000";
                string        writeData      = "FF";
                var           writeParameter = new AddressCommandParameter(0x00020000u, writeData);
                CommandResult result         = command.Execute(client, writeParameter, null);

                //writeParameter = new AddressCommandParameter(0x01, writeData);
                //result = command.Execute(client, writeParameter, null);


                var readcommand1 = new ReadSPIFlashCommand();
                // var parameter = new AddressCommandParameter(0x00u, 2, "FFFF");
                //var parameter = new AddressCommandParameter(0x00020000u, 4, "FFFFFFFF");
                var readParameter1 = new AddressCommandParameter(0x00020000u, 1);

                CommandResult readResult1 = readcommand.Execute(client, readParameter1, null);
#endif
                // Assert.AreEqual(result.Success, true);
                //Assert.AreEqual(result.Message, "");
            }
        }
コード例 #2
0
        public void ExecuteTest()
        {
            using (var client = PcbTesterClient.Create(PortName, BaudRate))
            {
                client.Open();


                var command = new EraseSPIFlashCommand();
                //var parameter = new AddressCommandParameter(0x00);
                var parameter = new AddressCommandParameter(0x00);

                CommandResult result = command.Execute(client, parameter, null);

                Assert.AreEqual(result.Success, true);
            }
        }
コード例 #3
0
        /// <summary>
        /// 往SPI Flash写入bin文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void writeSpiBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

            using (var client = PcbTesterClient.Create(Settings.Default.PortName, Settings.Default.BaudRate))
            {
                client.Open();

                var addressParameter = new AddressCommandParameter();
                if (e.Argument != null)
                {
                    addressParameter = (AddressCommandParameter)e.Argument;
                }

                //1.擦除选中SPI 地址上的内容
                var eraseSpiFlashCommand = new EraseSPIFlashCommand();

                var eraseResult = eraseSpiFlashCommand.Execute(client, new AddressCommandParameter(addressParameter.Address), null);
                if (!eraseResult.Success)
                {
                    e.Result = eraseResult;
                    return;
                }

                //2.将文件逐帧写入Flash
                using (FileStream stream = File.Open(this.fileNameTextBox.Text, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader binaryReader = new BinaryReader(stream);
                    byte[]       readBytes    = binaryReader.ReadBytes((int)stream.Length);

                    int framesCount = readBytes.Length / bytesPerTransmit;  //算出共多少帧

                    StringBuilder builder = new StringBuilder();
                    var           writeSPIFlashCommand = new WriteSPIFlashCommand();
                    for (int i = 0; i < readBytes.Length; i += bytesPerTransmit)
                    {
                        //如果用户取消了任务就跳出
                        if (backgroundWorker.CancellationPending)
                        {
                            e.Cancel = true;
                            break;
                        }

                        backgroundWorker.ReportProgress(i / bytesPerTransmit + 1, framesCount);

                        builder.Clear();
                        for (int j = 0; j < bytesPerTransmit; j++)
                        {
                            builder.AppendFormat("{0:X2}", readBytes[i + j]);
                        }

                        var writeResult = writeSPIFlashCommand.Execute(client, new AddressCommandParameter(addressParameter.Address, builder.ToString()), null);
                        addressParameter.Address += (uint)bytesPerTransmit; //更新下次写的SPI起始地址
                        if (!writeResult.Success)                           //写入失败
                        {
                            e.Result = writeResult;
                            return;
                        }
                    }
                }
            }
        }