public bool Lcd_Set(byte state) { appinf0 appinf = new appinf0(); Readdata.Readdata_ReadApp0(ref appinf); if ((state % 2) == 0) { this.myapp.upapp.lcddev.guidire = state; base.Width = appinf.lcdscreenw; base.Height = appinf.lcdscreenh; this.myapp.upapp.lcddev.width = (ushort)base.Width; this.myapp.upapp.lcddev.height = (ushort)base.Height; this.myapp.upapp.Myscr.Endx = base.Width - 1; this.myapp.upapp.Myscr.Endy = base.Height - 1; this.myapp.upapp.Screenbm = new Bitmap(base.Width, base.Height); this.gc = base.CreateGraphics(); this.selectbm = new Bitmap(base.Width, base.Height); return(true); } this.myapp.upapp.lcddev.guidire = state; base.Width = appinf.lcdscreenh; base.Height = appinf.lcdscreenw; this.myapp.upapp.lcddev.width = (ushort)base.Width; this.myapp.upapp.lcddev.height = (ushort)base.Height; this.myapp.upapp.Myscr.Endx = base.Width - 1; this.myapp.upapp.Myscr.Endy = base.Height - 1; this.myapp.upapp.Screenbm = new Bitmap(base.Width, base.Height); this.gc = base.CreateGraphics(); this.selectbm = new Bitmap(base.Width, base.Height); return(true); }
private ushort getbinver(ushort cpuid) { gujianinf gujianinf = default(gujianinf); int num; ushort result; if (cpuid == 61488 || cpuid == 61489) { num = 180; } else { if (cpuid != 61699) { MessageOpen.Show("No Find Cpu Model"); result = 65535; return(result); } num = 236; } StreamReader streamReader = new StreamReader(this.binpath); appinf0 appinf = default(appinf0); byte[] array = new byte[Marshal.SizeOf(default(appinf0))]; streamReader.BaseStream.Read(array, 0, array.Length); appinf = (appinf0)array.BytesTostruct(default(appinf0).GetType()); streamReader.BaseStream.Position = (long)((ulong)appinf.hexaddr); hexhead hexhead = default(hexhead); array = new byte[Marshal.SizeOf(default(hexhead))]; streamReader.BaseStream.Read(array, 0, array.Length); hexhead = (hexhead)array.BytesTostruct(default(hexhead).GetType()); array = new byte[Marshal.SizeOf(default(FIRMWARE_TABLE))]; FIRMWARE_TABLE fIRMWARE_TABLE = default(FIRMWARE_TABLE); for (int i = 0; i < (int)hexhead.Count; i++) { streamReader.BaseStream.Read(array, 0, array.Length); fIRMWARE_TABLE = (FIRMWARE_TABLE)array.BytesTostruct(default(FIRMWARE_TABLE).GetType()); if (fIRMWARE_TABLE.CPUID == cpuid) { streamReader.BaseStream.Position = (long)((ulong)(appinf.hexaddr + fIRMWARE_TABLE.addr) + (ulong)((long)num)); array = new byte[Marshal.SizeOf(default(gujianinf))]; streamReader.BaseStream.Read(array, 0, array.Length); result = ((gujianinf)array.BytesTostruct(default(gujianinf).GetType())).ver; return(result); } } result = 65535; return(result); }
private void USARTUP_Load(object sender, EventArgs e) { StreamReader streamReader = new StreamReader(this.binpath); this.allsize = (int)streamReader.BaseStream.Length; ushort num = (ushort)Marshal.SizeOf(default(appinf0)); if (streamReader.BaseStream.Length < (long)(num + 3)) { MessageOpen.Show("错误的资源文件或者资源文件已经受损".Language()); streamReader.Close(); streamReader.Dispose(); base.Close(); } byte[] array = new byte[(int)num]; streamReader.BaseStream.Read(array, 0, (int)num); this.thisapp0 = (appinf0)array.BytesTostruct(default(appinf0).GetType()); if (this.thisapp0.mark != datasize.hmibiaoshiL) { MessageOpen.Show("错误的资源文件或者资源文件已经受损".Language()); streamReader.Close(); streamReader.Dispose(); base.Close(); } streamReader.Close(); streamReader.Dispose(); this.comboBox2.Items.Clear(); this.comboBox2.Items.Add("2400"); this.comboBox2.Items.Add("4800"); this.comboBox2.Items.Add("9600"); this.comboBox2.Items.Add("19200"); this.comboBox2.Items.Add("38400"); this.comboBox2.Items.Add("57600"); this.comboBox2.Items.Add("115200"); this.comboBox2.Text = "115200"; this.getports(); this.mycom.com1 = this.com1; }
private void ComUpdata(bool iscrc) { uint num = uint.Parse(this.comboBox2.Text); this.jieshu = false; this.isupdata = false; Win32.timeBeginPeriod(1); int num2 = 0; appinf0 appinf = default(appinf0); try { int num3 = this.mycom.getlianji(this.textBox2, this.comboBox3.Text, 0, true, true, iscrc); string text2; if (num3 == 1) { if (this.getxinghaocrc(this.mycom.xinghao.Trim()) != this.thisapp0.Modelcrc) { string text = this.mycom.xinghao.Trim(); if (text.Length > 1) { string a = text.Substring(text.Length - 1, 1); if (a == "R" || a == "N" || a == "C") { text = text.Substring(0, text.Length - 1); } } MessageOpen.Show(string.Concat(new string[] { "当前连接设备的型号与本资源文件中配置的型号不匹配,请重新配置正确的型号后再重新编译资源文件。".Language(), "\r\n", datasize.Getmodelxinxi(this.thisapp0.Modelcrc, (int)this.thisapp0.xilie).Modelstring, " (", "资源文件配置型号".Language(), ")\r\n", text, " (", "设备型号".Language(), ")" })); this.endsend(); return; } if (this.getbinver(this.mycom.cpuchip) != this.mycom.gujianver) { MessageOpen.Show("当前连接设备的固件版本号与当前软件不匹配,你可以忽略此警告,当你使用当前软件制作的资源文件下载一次到设备之后设备将会自动升级(升级过程会白屏5-10秒,属于正常现象),之后不会再出现此提示。".Language()); } this.islianji = true; TextBox expr_1FA = this.textBox2; text2 = expr_1FA.Text; expr_1FA.Text = string.Concat(new string[] { text2, "强制下载波特率:".Language(), num.ToString(), " ", "开始下载".Language(), "\r\n" }); } else if (num3 != 2) { if (num3 != 3) { this.endsend(); return; } if (this.mycom.gujianver <= 50 || this.mycom.gujianver >= 55 || !this.isqiangzhi(this.mycom.xinghao)) { this.endsend(); return; } if (MessageOpen.Show("检测到非法型号,是否需要强制下载?".Language(), "提示".Language(), MessageBoxButtons.YesNo) != DialogResult.Yes) { this.endsend(); return; } string text = this.getpeizhistr(); if (text.Length < 5) { this.endsend(); return; } this.com1.sendstring_End("00", false, null); this.com1.sendstring_End(text, false, null); for (num3 = 0; num3 != 1; num3 = this.mycom.getlianji(this.textBox2, this.comboBox3.Text, 0, false, true, iscrc)) { if (MessageOpen.Show("请给设备重新上电,重新上电之后可能出现花屏或者黑屏现象是正常的,重新上电后继续强制下载点击 是 退出强制下载点击 否 ".Language(), "提示".Language(), MessageBoxButtons.YesNo) == DialogResult.No) { this.endsend(); return; } } num3 = 3; } if (num3 == 1 || num3 == 3) { StreamReader streamReader = new StreamReader(this.binpath); this.allsize = (int)streamReader.BaseStream.Length; this.Lbytes = new byte[this.allsize]; streamReader.BaseStream.Read(this.Lbytes, 0, this.Lbytes.Length); streamReader.Close(); if (num3 == 3) { byte[] bytes = this.Lbytes.subbytes(0, datasize.appxinxisize0); appinf = (appinf0)bytes.BytesTostruct(default(appinf0).GetType()); appinf.Modelcrc = "123".GetbytesssASCII().getcrc(0); appinf.structToBytes().CopyTo(this.Lbytes, 0); uint num4 = this.Lbytes.getcrc(4294967295u, 0, this.Lbytes.Length - 4); num4 ^= (uint)((byte)appinf.Modelcrc); num4 ^= (uint)appinf.mark; num4 ^= (uint)((byte)appinf.datasize); num4.structToBytes().CopyTo(this.Lbytes, this.Lbytes.Length - 4); } string text = string.Concat(new string[] { "whmi-wri ", this.allsize.ToString(), ",", num.ToString(), ",", this.thisapp0.banbenh.ToString() }); this.com1.sendstring_End("00", false, null); this.com1.sendstring_End(text, false, null); if (this.com1.BaudRate != (int)num) { Thread.Sleep(100); this.com1.Close(); this.com1.BaudRate = (int)num; this.com1.Open(); } } this.sendsize = 0; this.btnBeginDownLoad.Enabled = true; this.btnBeginDownLoad.Text = "停止".Language(); this.sk = 0; this.isupdata = true; while (true) { Application.DoEvents(); if (this.jieshu) { break; } this.sk = 0; while (this.sk != 5) { Application.DoEvents(); Thread.Sleep(2); num2++; if (num2 > 500) { if (this.sendsize == 0) { this.com1.Close(); this.com1.BaudRate = this.mycom.botelv; this.com1.Open(); Thread.Sleep(100); string text = string.Concat(new string[] { "tjchmi-wri ", this.allsize.ToString(), ",", num.ToString(), ",", this.thisapp0.banbenh.ToString() }); this.com1.sendstring_End("00", false, null); this.com1.sendstring_End(text, false, null); Thread.Sleep(100); this.com1.Close(); this.com1.BaudRate = (int)num; this.com1.Open(); } num2 = 0; } if (this.jieshu) { goto Block_26; } while (this.com1.BytesToRead > 0) { int num5 = this.com1.ReadByte(); if (num5 == 5) { this.sk = 5; } else if (num5 == 6) { goto Block_28; } } } Thread.Sleep(5); if (this.com1.IsOpen) { while (this.com1.BytesToRead > 0) { int num5 = this.com1.ReadByte(); if (num5 == 5) { this.sk = 5; } } } this.sk = 0; if (this.sendsize >= this.allsize) { goto Block_32; } if (this.sendsize == 0) { Thread.Sleep(400); this.lastsendsize.Clear(); this.lastsendsize.Add(new USARTUP.lasttime { lastsendsize = 0, dt = DateTime.Now }); this.uptime = DateTime.Now; this.timer1.Enabled = true; } if (this.allsize - this.sendsize >= 4096) { if (num >= 57600u) { this.com1.Write(this.Lbytes, this.sendsize, 4096); this.sendsize += 4096; } else { this.com1.Write(this.Lbytes, this.sendsize, 1024); this.sendsize += 1024; Application.DoEvents(); this.com1.Write(this.Lbytes, this.sendsize, 1024); this.sendsize += 1024; Application.DoEvents(); this.com1.Write(this.Lbytes, this.sendsize, 1024); this.sendsize += 1024; Application.DoEvents(); this.com1.Write(this.Lbytes, this.sendsize, 1024); this.sendsize += 1024; Application.DoEvents(); } } else { this.com1.Write(this.Lbytes, this.sendsize, this.allsize - this.sendsize); this.sendsize = this.allsize; } } this.endsend(); return; Block_26: this.endsend(); return; Block_28: MessageOpen.Show("串口通讯产生错误".Language()); this.jieshu = true; this.endsend(); return; Block_32: TimeSpan timeSpan = DateTime.Now.Subtract(this.uptime); this.showdown(); this.com1.Close(); this.isupdata = false; this.islianji = false; TextBox expr_8AF = this.textBox2; text2 = expr_8AF.Text; expr_8AF.Text = string.Concat(new string[] { text2, "下载完成!总耗时:".Language(), timeSpan.Hours.ToString(), "时".Language(), timeSpan.Minutes.ToString(), "分".Language(), timeSpan.Seconds.ToString(), "秒".Language(), "\r\n" }); this.button2.Enabled = true; this.timer1.Enabled = false; this.comboBox3.Enabled = true; this.comboBox2.Enabled = true; this.btnBeginDownLoad.Enabled = true; this.btnBeginDownLoad.Text = "联机并开始下载".Language(); if (num3 == 3) { MessageOpen.Show("强制下载已经结束,请给设备重新上电".Language() + "\r\n" + "设备重新上电之后可能会白屏5-10秒(内部固件升级),然后会出现提示:Please re download the resource file 如果看到此提示说明强制下载成功,再次按正常流程下载一次即可!".Language()); } } catch (Exception ex) { this.endsend(); MessageOpen.Show(ex.Message); } }