本文整理汇总了C#中Pager.Write方法的典型用法代码示例。如果您正苦于以下问题:C# Pager.Write方法的具体用法?C# Pager.Write怎么用?C# Pager.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pager
的用法示例。
在下文中一共展示了Pager.Write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static int Main(string[] args)
{
if (args.Length < 1) {
PrintUsage();
return 0;
}
string fw = null, portName = null, baudStr = null;
foreach (var a in args) {
if (a.StartsWith("-")) {
if (a.StartsWith("-p=")) {
portName = a.Substring(3);
} else if (a.StartsWith("-b=")) {
baudStr = a.Substring(3);
} else {
Console.Error.WriteLine("Unknown option: '{0}'", a);
}
} else {
if (fw != null) {
Console.Error.WriteLine("Bad argument: '{0}'", a);
return 1;
}
fw = a;
}
}
if (fw == null) {
Console.Error.WriteLine("No firmware file spicified");
return 1;
}
if (portName == null) {
Console.Error.WriteLine("No port spicified");
return 1;
}
var baud = baudStr != null ? int.Parse(baudStr) : 115200;
var hex = new HexFile(fw);
var pgmRegions = hex.Regions.Where(r => r.StartAddr < MAX_MEM).ToList();
var erase = new List<EraseBlock>();
foreach (var r in pgmRegions) {
var eraseStart = (r.StartAddr / ERASE_PAGE) * ERASE_PAGE;
var eraseEnd = r.NextAddr;
while (eraseStart < eraseEnd) {
var pages = Math.Min((eraseEnd - eraseStart - 1) / ERASE_PAGE + 1, MAX_ERASE_PAGES);
erase.Add(new EraseBlock { StartAddr = eraseStart, Pages = pages });
eraseStart += pages * ERASE_PAGE;
}
}
var wrPager = new Pager<byte>(32, 0xFF);
foreach (var r in pgmRegions) {
wrPager.Write((int)r.StartAddr, r.Data);
}
var write = wrPager.GetContiguousPages(MAX_WRITE / WRITE_PAGE).ToList();
port = new SerialPort(portName, baud, Parity.None, 8, StopBits.One) {
ReadTimeout = 1000,
NewLine = "\r\n",
DiscardNull = false,
};
#if !LOOPBACK
port.DataReceived += port_DataReceived;
#endif
try {
port.Open();
} catch (Exception ex) {
Console.Error.WriteLine(ex.Message + "Can’t open port");
return 1;
}
Console.WriteLine("Port {0}:{1} open, press any key when ready", port.PortName, port.BaudRate);
while (!Console.KeyAvailable) {
port.Write(new string((char)0x55, 100));
}
port.Write("\0");
Console.WriteLine("Started");
#if LOOPBACK
while (!port.ReadExisting().EndsWith("\0")) {
Thread.Sleep(1);
}
#else
Thread.Sleep(1000);
#endif
port.DiscardInBuffer();
Console.WriteLine("Erasing...");
SendErase(erase);
foreach (var w in write) {
Console.WriteLine("Writing 0x{0:X}...", w.Offset);
SendWrite(w);
}
Console.WriteLine("Finishing...");
SendFinish();
return 0;
}