public Dictionary <string, string> ToArgs() { var dict = new Dictionary <string, string>(); if (Page.HasValue) { dict.Add(PropertyPath + PageSuffix, Page.ToString()); } if (PageLength.HasValue) { dict.Add(PropertyPath + PageLengthSuffix, PageLength.ToString()); } if (!string.IsNullOrEmpty(SortKey)) { dict.Add(PropertyPath + SortKeySuffix, SortKey); } if (!string.IsNullOrEmpty(FilterExpression)) { dict.Add(PropertyPath + FilterSuffix, FilterExpression); } return(dict); }
/** * 参数个数:13 */ public void PageRead(int Chan, int Chip, int Mode, string Block, int PageAddr, int PageNum, string OutPath, int Offset, int Manual, int SaveFlag, int From, int Column_Flag, int CMD1, int RB_Flag) { /* * if (ManualFlag == -1) * { * ManualFlag = Manual; * } * else * { * if (ManualFlag != Manual) * { * throw new Exception("当前脚本中只能包含一种SDMA或Manual方式!!!"); * } * } * /* * if(PageNum == 0) * { * throw new Exception("读取的page数量不能为0!"); * }*/ //FromCache = 0,不发00-30h指令,直接读取寄存器上的数据, //FromArray = 1,先从Array读到cache if (RB_Flag != 1 && RB_Flag != 0) { throw new Exception("RBFlag只支持0或者1!"); } if (From != 1 && From != 0) { throw new Exception("From参数只能为0或者1!"); } if (Column_Flag != 0 && Column_Flag != 1) { throw new Exception("Column_Flag参数只能为0或者1!"); } //if(CMD1 != 0x30 && CMD1 != 0x31) //{ // throw new Exception("Readpage的CMD1只支持30h或31h"); //} if (SaveFlag == 1 && PageNum > 1) { throw new Exception("数据传输仅支持1个page读!"); } if (FlashFlag == 0) //B05A { if (Mode == 0 && ((PageAddr + PageNum) > 768)) //TLC { throw new Exception("page数量超出范围!"); } else if (Mode == 1 && (PageAddr + PageNum > (768 / 3)))//SLC { throw new Exception("page数量超出范围!"); } } else if (FlashFlag == 1) //GCG { if (Mode == 0 && (PageAddr + PageNum > 792)) //MLC { throw new Exception("page数量超出范围!"); } else if (Mode == 1 && ((PageAddr + PageNum) > (792 / 2)))//SLC { throw new Exception("page数量超出范围!"); } } if ((PageAddr + PageNum) > 792) { throw new Exception("page数量超出范围!"); } //进行参数的拼接:31-24为channel 23-16为chip 15-8为SLC(1)|MLC(0) 7-0为Manual(1)|DMA(0) Int32 args = ((Chan & 0xFF) << 24) | ((Chip & 0xFF) << 16) | ((Mode & 0xFF) << 8) | (Manual & 0xFF); //args1: RB_flag|column_flag | CMD1 Int32 args1 = ((RB_Flag & 0xFF) << 16) | ((Column_Flag & 0xFF) << 8) | (CMD1 & 0xFF); //Console.WriteLine(Column_Flag+" "+CMD1); string temp = "flash readpage " + Block + " " + PageAddr.ToString() + " " + PageNum.ToString() + " " + args.ToString("X") + " " + SaveFlag.ToString() + " " + From.ToString() + " " + args1.ToString("X") + '\n'; foreach (string name in CmdList.Keys) { CmdList[name].Add(temp); } int num = 0; if (Manual == 1) { num = FlashManualSize; } else if (Manual == 0) { num = FlashDmaSize; } else { throw new Exception("SDMA或Manual方式错误!!!"); } //如果Block中存在","逗号就说明是多plane,此时需要禁用读Block和读到SD卡中 if (((Regex.Matches(Block, ",").Count) > 0)) { if (PageNum > 1) { throw new Exception("多plane读方式只支持读取一个page"); } else if (SaveFlag == 0) { throw new Exception("多plane读方式不支持写入SD卡!!!"); } } //读的大小为两个Block num *= (Regex.Matches(Block, ",").Count + 1); PageLength.Add(num); ReadPageNum = PageLength[0]; try { if (SaveFlag == 1) { FileExsits(OutPath, Offset, Block, RB_Flag);//保存到本地时需要对脚本中的输出路径进行验证 } } catch (Exception ex) { throw new Exception(ex.Message); } }
//发送数据辅助线程执行代码 private void SendData_DoWork(object sender, DoWorkEventArgs e) { string str = "flash start 1 " + FlashFlag + '\n'; //首先发送start验证是否上电 foreach (SerialPort port in PortList.Values) { CmdList[port.PortName].Insert(0, str); } Thread.Sleep(200); int count = 0; while (true) { try { foreach (string name in PortList.Keys) //对于每一个串口 { if (CmdList[name].Count == 0) //如果该串口要发送的指令数量为0 { this.BeginInvoke(new System.Threading.ThreadStart(delegate() { RunBtn.Enabled = true; flashToolStripMenuItem.Enabled = true; SendToolStripButton.Enabled = true; })); count++; } if (count == CmdList.Count) { return; } } if (IsRecvSingle) { lock (locker) { IsRecvSingle = false; } //轮询所有串口判断是否需要发送数据, string tmpCmd = string.Empty; Thread.Sleep(100); foreach (SerialPort port in PortList.Values) { if (IsSendData[port.PortName]) { tmpCmd = CmdList[port.PortName].FirstOrDefault(); port.Write(tmpCmd);//打印当前执行的函数要下发的命令 lock (locker) { IsSendData[port.PortName] = false; //处理一个要发送数据的指令的时候,将发送信号置为false } IsPageRead[port.PortName] = false; // if (tmpCmd.Substring(6, 4).CompareTo("page") == 0) //flash pageprogram { Thread.Sleep(100); WritePageNum = WriteDataList[port.PortName].FirstOrDefault().ProgramPageSize;//获取当前串口要编程的字节数 byte[] tmpBuf = new byte[WritePageNum]; FileStream stream = null; BinaryReader reader = null; try { stream = new FileStream( WriteDataList[port.PortName].FirstOrDefault().FilePath[0], FileMode.Open); int Seek = GetFileOffert(WriteDataList[port.PortName].FirstOrDefault().FilePath[0], WriteDataList[port.PortName].FirstOrDefault().Offert); if (Seek != 0) { stream.Seek(Seek, SeekOrigin.Begin); //指定stream的偏移量 } FileInfo info = new FileInfo(WriteDataList[port.PortName].FirstOrDefault().FilePath[0]); //获取源文件的info reader = new BinaryReader(stream); if (info.Length < WritePageNum) { reader.Read(tmpBuf, 0, (int)info.Length); } else { reader.Read(tmpBuf, 0, (int)WritePageNum); } reader.Close(); stream.Close(); } catch (Exception ex) { } for (int i = 0; i < WritePageNum / 1024; i++) { port.Write(tmpBuf, i * 1024, 1024);//每次通过串口发送1K数据 Thread.Sleep(200); } WriteDataList[port.PortName].RemoveAt(0); } else if (tmpCmd.Substring(6, 4).CompareTo("read") == 0)//发送的"flash readpage" { lock (locker) { ReadPageNum = PageLength[0]; //当前要读的字节数 IsPageRead[port.PortName] = true; //读页信号置为true,详见另一个接收数据线程 PageLength.RemoveAt(0); //当前要读的字节数 } } } CmdList[port.PortName].RemoveAt(0); } } } catch { continue; } } }