Ejemplo n.º 1
0
        //写一个Page的数据到输出路径下
        private void PageDataWrite(PathAndOffert FileName, byte[] Data)
        {
            int flag = FileName.Offert;       //脚本中offset参数

            ReadPageNum /= FileName.PlaneNum; //脚本中的plane数量,最多支持4plane
            for (int i = 0; i < FileName.PlaneNum; i++)
            {
                string   FilePath = FileName.FilePath[i];
                FileInfo fileInfo = new FileInfo(FilePath); //输出文件信息
                long     size     = fileInfo.Length;        //输出文件初始长度
                int      offert   = GetIndexOffert(size, flag);

                if (size == 0)//文件当前为空
                {
                    FileStream   WriteStream = new FileStream(FilePath, FileMode.Append, FileAccess.Write);
                    BinaryWriter Writer      = new BinaryWriter(WriteStream);
                    Writer.Write(Data, i * ReadPageNum, ReadPageNum);
                    Writer.Close();
                    WriteStream.Close();
                }
                else//文件当前长度不为0
                {
                    if (offert * ReadPageNum >= size)//偏移量大于文件长度,转为追加
                    {
                        FileStream   WriteStream = new FileStream(FilePath, FileMode.Append, FileAccess.Write);
                        BinaryWriter Writer      = new BinaryWriter(WriteStream);
                        Writer.Write(Data, i * ReadPageNum, ReadPageNum);
                        Writer.Close();
                        WriteStream.Close();
                    }
                    else//在文件中进行插入
                    {
                        string       NewFile     = fileInfo.DirectoryName + @"/MyTempNewPageYang.bin";
                        FileStream   ReadStream  = new FileStream(FilePath, FileMode.Open, FileAccess.Read);
                        BinaryReader Reader      = new BinaryReader(ReadStream);
                        FileStream   WriteStream = new FileStream(NewFile, FileMode.Create, FileAccess.Write);//创建一个临时文件接受数据
                        BinaryWriter Writer      = new BinaryWriter(WriteStream);
                        byte[]       tmpData     = new byte[ReadPageNum];
                        for (int j = 0; j < offert; j++)//先将offset前的原始文件拷贝到临时文件
                        {
                            Reader.Read(tmpData, 0, ReadPageNum);
                            Writer.Write(tmpData, 0, ReadPageNum);
                        }
                        Writer.Write(Data, i * ReadPageNum, ReadPageNum); //再将Data中的一个page的数据写到临时文件
                        for (int j = offert; j < size / ReadPageNum; j++) //再将原始文件Offset后面的数据拷贝到临时文件中去
                        {
                            Reader.Read(tmpData, 0, ReadPageNum);
                            Writer.Write(tmpData, 0, ReadPageNum);
                        }
                        Reader.Close();
                        ReadStream.Close();
                        Writer.Close();
                        WriteStream.Close();
                        File.Delete(FilePath);
                        File.Move(NewFile, FilePath);//再将临时文件和原始文件进行替换
                    }
                }
            }
        }
Ejemplo n.º 2
0
        //判断文件是否存在,以及坐标偏移
        private void FileExsits(string path, int offert, string Block, int RBFlag)
        {
            string tmpStr   = string.Empty;
            string FilePath = string.Empty;

            PathAndOffert temp = new PathAndOffert(null, null, null, null, offert, 1, 0);

            string[] FileName = path.Split(','); //FileName[0]必定是文件夹的名字
            string[] Blocks   = Block.Split(',');
            if (!Directory.Exists(FileName[0]))  //判断文件夹是否存在,没有则新建
            {
                Directory.CreateDirectory(FileName[0]);
            }
            if (Blocks.Count() != FileName.Count() - 1)//OutPath中的逗号数目比Block中的多1个
            {
                throw new Exception("ReadPage 中Block和plane数应该和数据路径对应!!!");
            }
            if (FileName.Count() == 2)//单plane
            {
                tmpStr           = FileName[0] + @"/" + FileName[1];
                temp.FilePath[0] = tmpStr;
                temp.PlaneNum    = 1;
            }
            else if (FileName.Count() == 3)//两个Plane
            {
                tmpStr           = FileName[0] + @"/" + FileName[1];
                temp.FilePath[0] = tmpStr;
                tmpStr           = FileName[0] + @"/" + FileName[2];
                temp.FilePath[1] = tmpStr;
                temp.PlaneNum    = 2;
            }
            else if (FileName.Count() == 5)//4个Plane
            {
                tmpStr           = FileName[0] + @"/" + FileName[1];
                temp.FilePath[0] = tmpStr;
                tmpStr           = FileName[0] + @"/" + FileName[2];
                temp.FilePath[1] = tmpStr;
                tmpStr           = FileName[0] + @"/" + FileName[3];
                temp.FilePath[2] = tmpStr;
                tmpStr           = FileName[0] + @"/" + FileName[4];
                temp.FilePath[3] = tmpStr;
                temp.PlaneNum    = 4;
            }
            else
            {
                throw new Exception("ReadPage 路径格式错误!!!");
            }
            if (RBFlag == 1)//如果统计R/B#拉低时间,则新建一个csv文件
            {
                try
                {
                    FileStream stream = new FileStream(FileName[0] + @"/" + @"R/B_Falling_Duration.csv", FileMode.Create, FileAccess.Write);
                    stream.Close();
                }
                catch
                {
                    throw new Exception("R/B统计表格创建失败!");
                }
            }
            if (PortList.Keys.Count == 1)
            {
                string name = PortList.FirstOrDefault().Key;
                if (!ComDataPath.Keys.Contains(name))
                {
                    List <PathAndOffert> tmpList = new List <PathAndOffert>();
                    ComDataPath.Add(name, tmpList);
                }
                for (int i = 0; i < temp.PlaneNum; i++)
                {
                    try
                    {
                        //temp.FilePath[i] += ".bin";
                        if (!File.Exists(temp.FilePath[i]))
                        {
                            //File.Create(temp.FilePath[i]).Dispose();
                            FileStream stream = new FileStream(temp.FilePath[i], FileMode.Create, FileAccess.Write);
                            stream.Close();
                        }
                    }
                    catch
                    {
                        throw new Exception("文件路径不正确!!!");
                    }
                }
                ComDataPath[name].Add(temp);
            }
            else
            {
                foreach (string name in PortList.Keys)
                {
                    PathAndOffert Privious = temp;
                    temp = Privious;
                    if (!ComDataPath.Keys.Contains(name))
                    {
                        List <PathAndOffert> tmpList = new List <PathAndOffert>();
                        ComDataPath.Add(name, tmpList);
                    }
                    for (int i = 0; i < Privious.PlaneNum; i++)
                    {
                        temp.FilePath[i] += name;
                        if (!File.Exists(temp.FilePath[i]))
                        {
                            //File.Create(temp.FilePath[i]).Dispose();
                            FileStream stream = new FileStream(temp.FilePath[i], FileMode.Create, FileAccess.Write);
                            stream.Close();
                        }
                    }
                    ComDataPath[name].Add(temp);
                }
            }
        }
Ejemplo n.º 3
0
        /**
         * 参数个数:13个
         *
         */
        public void PageProgram(int Chan, int Chip, int Mode, string Block, int Page, string ProgramDataPath, int offert, int Manual, int DelayTime, int Reset_flag, int CMD_Code, int CMD1_Flag, int SendData)
        {
            /*
             * if (ManualFlag == -1)
             * {
             *  ManualFlag = Manual;
             * }
             * else
             * {
             *  if (ManualFlag != Manual)
             *  {
             *      throw new Exception("当前脚本中只能包含一种SDMA或Manual方式!!!");
             *  }
             * }
             */
            if (SendData != 0 && SendData != 1)
            {
                throw new Exception("SendData 只能为0或者1!");
            }
            if (SendData == 0 && Manual == 0)
            {
                throw new Exception("只支持Manual方式编程时不发数据!");
            }
            if (!(CMD_Code >= 0 && CMD_Code <= 3))
            {
                throw new Exception("CMD_Code 只能为0,1,2!");
            }
            if (CMD1_Flag != 0 && CMD1_Flag != 1)
            {
                throw new Exception("CMD1_Flag 只能为0或者1!");
            }
            if (Reset_flag != 1 && Reset_flag != 0)
            {
                throw new Exception("Reset_flag 只能为0或者1!");
            }
            Int32  args  = ((Chan & 0xFF) << 24) | ((Chip & 0xFF) << 16) | ((Mode & 0xFF) << 8) | (Manual & 0xFF);
            Int32  args1 = ((CMD_Code & 0xFF) << 24) | ((CMD1_Flag & 0xFF) << 16) | ((SendData & 0xFF) << 8);
            string temp  = "flash pageprogram" + " " + Block + " " + Page.ToString() + " " + args.ToString("X") + " " + DelayTime.ToString() + " " + Reset_flag.ToString() + " " + args1.ToString("X") + '\n';

            //Console.WriteLine(temp);
            foreach (string name in CmdList.Keys)
            {
                CmdList[name].Add(temp);
            }
            int num = 0;

            if (Manual == 1)
            {
                num = FlashManualSize;
            }
            else if (Manual == 0)
            {
                num = FlashDmaSize;
            }

            if (File.Exists(ProgramDataPath))
            {
                PathAndOffert tmpPath = new PathAndOffert(ProgramDataPath, "", "", "", offert, 0, num);
                foreach (string port in PortList.Keys)
                {
                    if (!WriteDataList.ContainsKey(port))
                    {
                        List <PathAndOffert> path = new List <PathAndOffert>();
                        WriteDataList.Add(port, path);
                    }
                    WriteDataList[port].Add(tmpPath);
                }
            }
            else
            {
                throw new Exception("文件路径不存在,请检查!");
            }
        }