private void button3_Click(object sender, EventArgs e) { WaterCmd_36_2 cmd = new WaterCmd_36_2(); cmd.MsgList = wbms; string msg = cmd.ReadMsg(); if (msg == "") { if (cmd.iden_F3 != null) { byte[] bs = cmd.iden_F3.ImgContent; Image img = byteArrayToImage(bs); img.Save("temp.jpg"); MessageBox.Show("图片保存完成!"); } else { MessageBox.Show("未获取图片信息!"); } } else { MessageBox.Show("分析失败!" + msg); } }
private void button2_Click(object sender, EventArgs e) { byte[] bs = null; FileInfo fileInfo = new FileInfo(this.textBox1.Text); FileStream fs = null; if (fileInfo.Exists) { try { long len = fileInfo.Length; fs = fileInfo.OpenRead(); bs = new byte[len]; fs.Read(bs, 0, (int)len); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (fs != null) { fs.Close(); } } } if (bs == null) { MessageBox.Show("图片选择错误!"); } WaterCmd_36_2 cmd = new WaterCmd_36_2(); cmd.CenterStation = f1.GetCenterStation(); cmd.RemoteStation = f1.GetRemoteStation(); cmd.PW = f1.GetPW(); cmd.SerialNumber = f1.GetCount(); cmd.SendTime = DateTime.Now; Identifier_F1 iden_F1 = new Identifier_F1(); iden_F1.RemoteStation = cmd.RemoteStation; iden_F1.StationType = (byte)WaterBaseProtocol.StationType.River; Identifier_F0 iden_F0 = new Identifier_F0(); iden_F0.ObsTime = cmd.SendTime; Identifier_F3 iden_F3 = new Identifier_F3(); iden_F3.ImgContent = bs; cmd.List_Identifier = new List <Identifier>(); cmd.List_Identifier.Add(iden_F1); cmd.List_Identifier.Add(iden_F0); cmd.List_Identifier.Add(iden_F3); string msg = cmd.WriteMsg(); if (msg == "") { MessageBox.Show("命令数量:" + cmd.MsgList.Length); this.textBox2.Text = ""; wbms = cmd.MsgList; Thread t = new Thread(showMsg); t.Start(); } else { MessageBox.Show(msg); } }