2299 lines
		
	
	
		
			88 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			2299 lines
		
	
	
		
			88 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System; | |||
|  | using System.Collections.Generic; | |||
|  | using System.ComponentModel; | |||
|  | using System.Data; | |||
|  | using System.Drawing; | |||
|  | using System.Linq; | |||
|  | using System.Text; | |||
|  | using System.Windows.Forms; | |||
|  | using System.IO; | |||
|  |   | |||
|  | using DevExpress.XtraEditors.Controls; | |||
|  | using Microsoft.VisualBasic; | |||
|  | using System.Security.Cryptography; | |||
|  | namespace dn_wms | |||
|  | { | |||
|  |     public partial class basicFuncs : Form | |||
|  |     { | |||
|  |         public static dnrj aa ;//= new sjqh(); | |||
|  | 
 | |||
|  |         Dictionary<string, dnrj> coms = new Dictionary<string, dnrj>(); | |||
|  | 
 | |||
|  | 
 | |||
|  |        //public static sjqh aa1 = new sjqh(); | |||
|  |        // public static sjqh aa2 = new sjqh(); | |||
|  | 
 | |||
|  |         string[,] comment = new string[200, 5]; | |||
|  |         int[] order = new int[300]; | |||
|  |         delegate void dis_result(string state); | |||
|  |         delegate void receive_coun(Int16 count); | |||
|  |         delegate void receive_result(     model.uart_dis_data[] data); | |||
|  |         delegate void send_coun(Int16 count); | |||
|  |         int[] test_count = new int[255]; | |||
|  |         int test_order; | |||
|  |         int timer_2 = 0; | |||
|  |         int[] goods_send_id = new int[1300]; | |||
|  |         int[] goods_send_lid = new int[1300]; | |||
|  |         int[] goods_send_order = new int[1300]; | |||
|  | 
 | |||
|  |         //定时器,定时发送 | |||
|  |         byte TESTRUN = 0x5a; | |||
|  |         byte TESTSTOP = 0xa5; | |||
|  |         byte offset = 0; | |||
|  |         byte SendMode = 0; | |||
|  |         bool SendSeq = true; | |||
|  |         int test_elelab_start, test_elelab_stop, test_elelab_address, PackageNum = 0; | |||
|  |         int test_light_start, test_light_stop, test_light_address; | |||
|  |         int[] elelab_test_error = new int[9999]; | |||
|  |         int[] light_test_error = new int[9999]; | |||
|  |         model.dis_id SendData; | |||
|  |         int len_kzq_test = 0; | |||
|  |         byte offset_kzq_test, flag_kzq_test = 0; | |||
|  |         int[] count_bz = new int[255]; | |||
|  |         public const int MAX_LIGHT_NUM = 7700; | |||
|  |         public basicFuncs() | |||
|  |         { | |||
|  |             InitializeComponent(); | |||
|  |             | |||
|  |         } | |||
|  |         private void basicFuncs_Load(object sender, EventArgs e) | |||
|  |         { | |||
|  |             tbpanel.SelectedPageIndex = 0; | |||
|  |           // tbpanel.Pages[1].PageVisible = false; | |||
|  |             initComs(); | |||
|  |             initialCom(); | |||
|  |             meditLogs.ReadOnly = true; | |||
|  |         }  | |||
|  |          | |||
|  |         byte led_rgb = 0; | |||
|  |         private void btnSeeds_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |           | |||
|  | 
 | |||
|  | 
 | |||
|  |             int elelab_start, elelab_stop, count, num, seedsNum; | |||
|  |             int goods_add_start, goods_add_stop, goods_second; | |||
|  |             int tmp; | |||
|  |             try | |||
|  |             { | |||
|  |                 elelab_start = Convert.ToInt32(txtlbID1.Text); | |||
|  |                 elelab_stop = Convert.ToInt32(txtlbID2.Text); | |||
|  |                 goods_add_start = Convert.ToInt32(this.txtaddr1.Text); | |||
|  |                 goods_add_stop = goods_add_start; | |||
|  |                 | |||
|  |                 seedsNum = Convert.ToInt16(this.txtNum.Text); | |||
|  |                 // aa.bcdflag = false; | |||
|  | 
 | |||
|  |                 if ((elelab_stop < elelab_start) || (goods_add_stop < goods_add_start)) | |||
|  |                 { | |||
|  |                     throw new Exception(); | |||
|  |                 } | |||
|  |                 if (String.IsNullOrEmpty(txtaddr2.Text.Trim())) | |||
|  |                 { | |||
|  |                     goods_second = 0; | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     goods_second = Convert.ToInt32(txtaddr2.Text); | |||
|  |                 } | |||
|  |             } | |||
|  |             catch | |||
|  |             { | |||
|  |                 MessageBox.Show("请输入正确的标签ID范围与地址范围"); | |||
|  |                 return; | |||
|  |             } | |||
|  | 
 | |||
|  | 
 | |||
|  |             switch (combLbColor.Text) | |||
|  |             { | |||
|  |                 case "红": | |||
|  |                     led_rgb = 1; | |||
|  |                     break; | |||
|  |                 case "绿": | |||
|  |                     led_rgb = 2; | |||
|  |                     break; | |||
|  |                 case "蓝": | |||
|  |                     led_rgb = 3; | |||
|  |                     break; | |||
|  |                 case "红闪": | |||
|  |                     led_rgb = 4; | |||
|  |                     break; | |||
|  |                 case "绿闪": | |||
|  |                     led_rgb = 5; | |||
|  |                     break; | |||
|  |                 case "蓝闪": | |||
|  |                     led_rgb = 6; | |||
|  |                     break; | |||
|  |                 case "红绿": | |||
|  |                     led_rgb = 7; | |||
|  |                     break; | |||
|  |                 case "红蓝": | |||
|  |                     led_rgb = 8; | |||
|  |                     break; | |||
|  |                 case "绿蓝": | |||
|  |                     led_rgb = 9; | |||
|  |                     break; | |||
|  |                 case "红绿蓝": | |||
|  |                     led_rgb = 10; | |||
|  |                     break; | |||
|  |                 case "5": | |||
|  |                     led_rgb = 11; | |||
|  |                     break; | |||
|  |                 case "6": | |||
|  |                     led_rgb = 12; | |||
|  |                     break; | |||
|  |                 case "7": | |||
|  |                     led_rgb = 13; | |||
|  |                     break; | |||
|  |                 case "8": | |||
|  |                     led_rgb = 14; | |||
|  |                     break; | |||
|  |                 case "9": | |||
|  |                     led_rgb = 15; | |||
|  |                     break; | |||
|  | 
 | |||
|  | 
 | |||
|  |                 default: | |||
|  |                     led_rgb = 2; | |||
|  |                     break; | |||
|  |             } | |||
|  | 
 | |||
|  |             /*if (combLbColor.SelectedIndex==0) | |||
|  |             { | |||
|  |                 led_rgb += 1; | |||
|  |                 if (led_rgb > 10) | |||
|  |                 { | |||
|  |                     led_rgb = 0; | |||
|  |                 } | |||
|  |             }*/ | |||
|  |             tmp = test_order; | |||
|  |             // if (checkBox5.Checked == true) | |||
|  |             { | |||
|  |                 test_order++; | |||
|  |             } | |||
|  |             if (test_order >= 255) | |||
|  |                 test_order = 1; | |||
|  |             lbOrderNo.Text = test_order.ToString(); | |||
|  | 
 | |||
|  |             count = (elelab_stop - elelab_start + 1) * (goods_add_stop - goods_add_start + 1); | |||
|  |             count_bz[test_order] = count; | |||
|  |             //uart_dis_data[] comment = new uart_dis_data[count]; | |||
|  | 
 | |||
|  |             model.uart_dis_data[] comment = new model.uart_dis_data[count]; | |||
|  | 
 | |||
|  |             num = 0; | |||
|  | 
 | |||
|  |             for (int i = elelab_start; i <= elelab_stop; i++) | |||
|  |             { | |||
|  |                 for (int j = goods_add_start; j <= goods_add_stop; j++) | |||
|  |                 { | |||
|  |                     comment[num].dis_type = led_rgb;//Convert.ToByte(textBox4.Text); 电子标签灯的颜色 1 红色 2 绿色 3 蓝色 | |||
|  |                     comment[num].ele_id = i;     //电子标签id | |||
|  | 
 | |||
|  |                     comment[num].order = Convert.ToByte(test_order);//Convert.ToByte(textBox2.Text);  单号 | |||
|  |                     //  comment[num].port = comboBox1.Text;//textBox3.Text;// Convert.ToByte(textBox3.Text); 端口 不使用 | |||
|  |                     comment[num].receive_count = 0;  //为0 | |||
|  | 
 | |||
|  |                     // comment[num].bcdflag = false; | |||
|  |                     // comment[num].little_ele_idH1 = 0; | |||
|  |                     // comment[num].little_ele_idH1 = 0; | |||
|  |                     comment[num].little_ele_id = Convert.ToByte(j); // 货位号 | |||
|  |                     comment[num].send_count = seedsNum; | |||
|  |                     comment[num].little_ele_idH2 = Convert.ToByte(goods_second); ; | |||
|  |                     comment[num].state = 1;  //都为1 | |||
|  |                     num++; | |||
|  |                     //comment[i*j]. | |||
|  |                 } | |||
|  |             } | |||
|  |             if (chkClearOrder.Checked == true) | |||
|  |             { | |||
|  |                 model.clear_order ss = new model.clear_order(); | |||
|  |                 ss.order = Convert.ToByte(tmp); | |||
|  |                 ss.state = 1; | |||
|  |                 aa.clear_order(ss); | |||
|  |             } | |||
|  |             lbstate.Text = "正在播种..."; | |||
|  |             addLog("正在播种..."); | |||
|  |             for (int i = 0; i < 1300; i++) | |||
|  |             { | |||
|  |                 goods_send_id[i] = 0; | |||
|  |                 goods_send_lid[i] = 0; | |||
|  |                 goods_send_order[i] = 0; | |||
|  |             } | |||
|  |             test_count[test_order] = 0; | |||
|  | 
 | |||
|  | 
 | |||
|  |             //  System.Threading.Thread.Sleep(200);//by dhwu 141226 | |||
|  |             if (aa.write_dis_comment(comment) == true) | |||
|  |             { | |||
|  |                 // label10.Text = label10.Text + "成功"; | |||
|  |                 // | |||
|  |                 //textBox1.Text = textBox1.Text + "成功"; | |||
|  |                 addLog(" 播种成功"); | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 addLog(" 播种失败"); | |||
|  |                 //textBox1.Text = textBox1.Text + "失败"; | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  | 
 | |||
|  |         void addLog(string info) | |||
|  |         { | |||
|  |             if (this.meditLogs.Lines.Length > 100) | |||
|  |             { | |||
|  |                 this.meditLogs.Text = ""; | |||
|  | 
 | |||
|  |             } | |||
|  | 
 | |||
|  | 
 | |||
|  |             while (info.Length < 100) | |||
|  |             { | |||
|  |                 info += " "; | |||
|  |             } | |||
|  | 
 | |||
|  |             info += "    " + System.DateTime.Now; | |||
|  |             this.meditLogs.Text = info + "\r\n" + this.meditLogs.Text; | |||
|  |         } | |||
|  | 
 | |||
|  |         bool isTesting = false; | |||
|  |         private void btnTest_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             isTesting = !isTesting; | |||
|  |             addLog(isTesting ? "开始" : "结束" + " 测试..."); | |||
|  | 
 | |||
|  | 
 | |||
|  |             int i; | |||
|  |             if (SendMode == 0) | |||
|  |             { | |||
|  |                 try | |||
|  |                 { | |||
|  | 
 | |||
|  |                     if ((this.txtlbID1.Text == "") || (txtlbID2.Text == "")) | |||
|  |                     { | |||
|  |                         if ((this.txtChID1.Text == "") || (this.txtChID2.Text == "")) | |||
|  |                         { | |||
|  |                             MessageBox.Show("输入的地址错误"); | |||
|  |                             SendMode = 0; | |||
|  |                             return; | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             test_elelab_start = 0; | |||
|  |                             test_elelab_stop = 0; | |||
|  |                             try | |||
|  |                             { | |||
|  |                                 test_light_start = Convert.ToInt16(txtChID1.Text); | |||
|  |                                 test_light_stop = Convert.ToInt16(txtChID2.Text); | |||
|  |                             } | |||
|  |                             catch | |||
|  |                             { | |||
|  |                                 MessageBox.Show("输入的巷灯ID错误"); | |||
|  |                                 addLog("输入的巷灯ID错误"); | |||
|  |                                 return; | |||
|  |                             } | |||
|  |                             SendMode = 0x02; | |||
|  |                         } | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         if ((txtChID1.Text == "") || (txtChID2.Text == "")) | |||
|  |                         { | |||
|  |                             test_elelab_start = Convert.ToInt16(txtlbID1.Text); | |||
|  |                             test_elelab_stop = Convert.ToInt16(txtlbID2.Text); | |||
|  |                             test_light_start = 5000; | |||
|  |                             test_light_stop = 5000; | |||
|  |                             SendMode = 0x01; | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             test_elelab_start = Convert.ToInt16(txtlbID1.Text); | |||
|  |                             test_elelab_stop = Convert.ToInt16(txtlbID2.Text); | |||
|  |                             test_light_start = Convert.ToInt16(txtChID1.Text); | |||
|  |                             test_light_stop = Convert.ToInt16(txtChID2.Text); | |||
|  |                             SendMode = 0x03; | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |                 catch | |||
|  |                 { | |||
|  |                     MessageBox.Show("输入错误"); | |||
|  |                     addLog("输入错误"); | |||
|  |                     return; | |||
|  |                 } | |||
|  | 
 | |||
|  | 
 | |||
|  |                 test_elelab_address = test_elelab_start; | |||
|  |                 test_light_address = test_light_start; | |||
|  | 
 | |||
|  |                 if ((test_elelab_start > test_elelab_stop))// || (test_elelab_stop > 999))  | |||
|  |                 { | |||
|  |                     MessageBox.Show("输入的结束ID必须大于等于起始ID,且小于999"); | |||
|  |                     addLog("输入的结束ID必须大于等于起始ID,且小于999"); | |||
|  |                     SendMode = 0; | |||
|  |                 } | |||
|  |                 else if ((test_light_start > test_light_stop) || (test_light_start < 5000) || (test_light_stop > MAX_LIGHT_NUM)) | |||
|  |                 { | |||
|  |                     MessageBox.Show("输入的结束ID必须大于等于起始ID,且必须在5000到5100之间"); | |||
|  |                     addLog("输入的结束ID必须大于等于起始ID,且必须在5000到5100之间"); | |||
|  |                     SendMode = 0; | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     btnTest.Text = isTesting ? "结束测试" : "开始测试"; | |||
|  | 
 | |||
|  |                     if ((SendMode & 0x01) == 0x01) | |||
|  |                     { | |||
|  |                         for (i = test_elelab_start; i <= test_elelab_stop; i++) | |||
|  |                         { | |||
|  |                             SendData.order = TESTRUN; | |||
|  |                             SendData.ele_id = i; | |||
|  |                             SendData.state = 1; | |||
|  |                             aa.write_test_device(SendData, offset); | |||
|  |                             System.Threading.Thread.Sleep(100); | |||
|  |                         } | |||
|  |                     } | |||
|  |                     if ((SendMode & 0x02) == 0x02) | |||
|  |                     { | |||
|  |                         for (i = test_light_start; i <= test_light_stop; i++) | |||
|  |                         { | |||
|  |                             SendData.order = TESTRUN; | |||
|  |                             SendData.ele_id = i; | |||
|  |                             SendData.state = 1; | |||
|  |                             aa.write_test_device(SendData, offset); | |||
|  |                             System.Threading.Thread.Sleep(100); | |||
|  |                         } | |||
|  |                     } | |||
|  |                     SendMode = (byte)(SendMode | 0x10); | |||
|  |                 } | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 btnTest.Text = isTesting ? "结束测试" : "开始测试"; | |||
|  |                 if (SendMode != 0) | |||
|  |                 { | |||
|  |                     SendMode = (byte)(SendMode & 0x0f); | |||
|  |                     SendSeq = true; | |||
|  |                     if ((SendMode & 0x01) == 0x01) | |||
|  |                     { | |||
|  |                         for (i = test_elelab_start; i <= test_elelab_stop; i++) | |||
|  |                         { | |||
|  |                             SendData.order = TESTSTOP; | |||
|  |                             SendData.ele_id = i; | |||
|  |                             SendData.state = 1; | |||
|  |                             aa.write_test_device(SendData, offset); | |||
|  | 
 | |||
|  |                             if (elelab_test_error[i] > 0) | |||
|  |                             { | |||
|  |                                 addLog("#、标签" + i.ToString() + "丢包数: " + elelab_test_error[i].ToString()); | |||
|  |                                 // this.meditLogs.Focus();//获取焦点 | |||
|  |                                 //this.meditLogs.Select(this.meditLogs.TextLength, 0);//光标定位到文本最后 | |||
|  |                                 this.meditLogs.ScrollToCaret();//滚动到光标处                 | |||
|  |                             } | |||
|  |                             System.Threading.Thread.Sleep(100); | |||
|  |                         } | |||
|  |                     } | |||
|  |                     if ((SendMode & 0x02) == 0x02) | |||
|  |                     { | |||
|  |                         for (i = test_light_start; i <= test_light_stop; i++) | |||
|  |                         { | |||
|  |                             SendData.order = TESTSTOP; | |||
|  |                             SendData.ele_id = i; | |||
|  |                             SendData.state = 1; | |||
|  |                             aa.write_test_device(SendData, offset); | |||
|  | 
 | |||
|  |                             if (light_test_error[i - 5000] > 0) | |||
|  |                             { | |||
|  |                                 addLog("#、标签" + i.ToString() + "丢包数: " + light_test_error[i - 5000].ToString()); | |||
|  |                                 //  this.meditLogs.Focus();//获取焦点 | |||
|  |                                 // this.meditLogs.Select(this.meditLogs.TextLength, 0);//光标定位到文本最后 | |||
|  |                                 this.meditLogs.ScrollToCaret();//滚动到光标处                 | |||
|  |                             } | |||
|  |                             System.Threading.Thread.Sleep(100); | |||
|  |                         } | |||
|  |                     } | |||
|  |                     addLog("\r\n#、每个标签发送接收包数: " + (PackageNum + 1).ToString() + "; 每个标签发送接收字节数: " + ((PackageNum + 1) * 15).ToString()); | |||
|  |                     //  this.meditLogs.Focus();//获取焦点 | |||
|  |                     //this.meditLogs.Select(this.meditLogs.TextLength, 0);//光标定位到文本最后 | |||
|  |                     this.meditLogs.ScrollToCaret();//滚动到光标处 | |||
|  | 
 | |||
|  |                     for (i = 0; i < 999; i++) | |||
|  |                     { | |||
|  |                         elelab_test_error[i] = 0; | |||
|  |                         light_test_error[i] = 0; | |||
|  |                     } | |||
|  |                     PackageNum = 0; | |||
|  |                     SendMode = 0; | |||
|  |                 } | |||
|  | 
 | |||
|  | 
 | |||
|  |             } | |||
|  | 
 | |||
|  |         } | |||
|  | 
 | |||
|  |         bool isShowId; | |||
|  |         private void btnShowId_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             model.dis_id id; | |||
|  |             isShowId = !isShowId; | |||
|  | 
 | |||
|  |             /* //id.ele_id = Convert.ToInt16(new_id.Text); | |||
|  |              if (this.txtlbID1.Text == "") | |||
|  |              { | |||
|  |            | |||
|  |                  id.order = 0; | |||
|  | 
 | |||
|  |                  id.ele_id = 65535; | |||
|  |                  id.state = 1; | |||
|  |               //   aa.write_dis_id_comment(id); | |||
|  |              } | |||
|  |              else | |||
|  |              { | |||
|  |                  id.order = 1; | |||
|  |                  int eid = 0;  | |||
|  | 
 | |||
|  |                  try | |||
|  |                  { | |||
|  |                      eid = Convert.ToInt16(txtlbID1.Text); | |||
|  |                  } | |||
|  |                  catch | |||
|  |                  { | |||
|  |                      MessageBox.Show("请输入正确的ID"); | |||
|  |                      addLog("请输入正确的ID"); | |||
|  |                      return; | |||
|  |                  } | |||
|  | 
 | |||
|  | 
 | |||
|  |                  id.ele_id = eid;// Convert.ToInt16(txtlbID2.Text); | |||
|  |                  id.state = 1;   | |||
|  |              } | |||
|  |              */ | |||
|  |             id.order = 0; | |||
|  |             id.ele_id = 65535; | |||
|  |             id.state = 1; | |||
|  |             if (isShowId) | |||
|  |             { | |||
|  |                 aa.write_dis_id_comment(id); | |||
|  |                 btnShowId.Text = "清除ID显示"; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 aa.write_clear_comment(id); | |||
|  |                 btnShowId.Text = "显示标签ID"; | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         private void btnReset_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             resetDevices(); | |||
|  |         } | |||
|  | 
 | |||
|  |         private void resetDevices() | |||
|  |         { | |||
|  |             model.dis_id id; | |||
|  | 
 | |||
|  | 
 | |||
|  |             id.order = 0; | |||
|  |             id.ele_id = 65535; | |||
|  |             id.state = 1; | |||
|  |             aa.write_reset_device(id); | |||
|  | 
 | |||
|  | 
 | |||
|  |             System.Threading.Thread.Sleep(100); | |||
|  |             id.order = 1; | |||
|  |             id.ele_id = 0; | |||
|  |             id.state = 1; | |||
|  |             aa.write_reset_device(id); | |||
|  |         } | |||
|  | 
 | |||
|  |         private void btnSchChannel_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             bool ret; | |||
|  |             int i; | |||
|  |             model.modify_id id; | |||
|  | 
 | |||
|  |             if (SendMode != 0) | |||
|  |             { | |||
|  |                 MessageBox.Show("请停止测试再搜索"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             if ((this.txtChID1.Text == "") || (txtChID2.Text == "")) | |||
|  |             { | |||
|  |                 MessageBox.Show("请输入的巷灯ID范围"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             try | |||
|  |             { | |||
|  |                 test_light_start = Convert.ToInt16(txtChID1.Text); | |||
|  |                 test_light_stop = Convert.ToInt16(txtChID2.Text); | |||
|  |             } | |||
|  |             catch | |||
|  |             { | |||
|  | 
 | |||
|  |             } | |||
|  |             if ((test_light_start > test_light_stop) || (test_light_start < 5000) || (test_light_stop > MAX_LIGHT_NUM)) | |||
|  |             { | |||
|  |                 MessageBox.Show("输入的结束ID必须大于等于起始ID,且必须在5000到5100之间"); | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 this.lbstate.Text = "正在搜索"; | |||
|  |                 System.Threading.Thread.Sleep(50); | |||
|  |                 for (i = test_light_start; i <= test_light_stop; i++) | |||
|  |                 { | |||
|  |                     id.order = 0; | |||
|  |                     id.new_ele_id = 0; | |||
|  |                     id.old_ele_id = i; | |||
|  |                     id.state = 1; | |||
|  |                     ret = aa.search_light_id(id); | |||
|  |                     if (ret) | |||
|  |                     { | |||
|  |                         addLog("搜索到巷灯:" + i.ToString()); | |||
|  |                         // this.meditLogs.Focus();//获取焦点 | |||
|  |                         // this.meditLogs.Select(this.meditLogs.TextLength, 0);//光标定位到文本最后 | |||
|  |                         this.meditLogs.ScrollToCaret();//滚动到光标处 | |||
|  |                         System.Threading.Thread.Sleep(50); | |||
|  |                     } | |||
|  |                 } | |||
|  |                 this.lbstate.Text = "搜索结束"; | |||
|  |                 addLog("搜索结束"); | |||
|  |             } | |||
|  |         } | |||
|  |         bool isCloseLable = false; | |||
|  |         private void simpleButton10_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             int lbId = 0; | |||
|  | 
 | |||
|  |             try | |||
|  |             { | |||
|  |                 lbId = Convert.ToInt16(txtLbId11.Text); | |||
|  | 
 | |||
|  |                 model.dis_id id; | |||
|  |                 id.order = 1; | |||
|  |                 id.ele_id = lbId; | |||
|  |                 id.state = 1; | |||
|  |                 if (!isCloseLable) | |||
|  |                 { | |||
|  |                     aa.write_dis_id_comment(id); | |||
|  |                     isCloseLable = true; | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     // clear_comment cc; | |||
|  |                     // cc.order = 1; | |||
|  |                     //cc.ele_id = lbId; | |||
|  |                     //  cc.state = 1; | |||
|  |                     aa.write_clear_comment(id); | |||
|  |                     isCloseLable = false; | |||
|  |                 } | |||
|  | 
 | |||
|  |             } | |||
|  |             catch | |||
|  |             { | |||
|  |                 MessageBox.Show("请输入正确的ID"); | |||
|  |                 addLog("请输入正确的ID"); | |||
|  |                 return; | |||
|  |             } | |||
|  | 
 | |||
|  |             simpleButton10.Text = isCloseLable ? "关闭" : "显示"; | |||
|  | 
 | |||
|  |             // isCloseLable = !isCloseLable; | |||
|  | 
 | |||
|  | 
 | |||
|  |             //   readDevice(lbId); | |||
|  |         } | |||
|  | 
 | |||
|  |         void readDevice(int devId) | |||
|  |         { | |||
|  |             bool ret; | |||
|  |             int version; | |||
|  |             int ElelabCnt, temp; | |||
|  |             //byte ddata1,ddata2,ddata3; | |||
|  |             byte[] ddata = new byte[10];//, ddata2, ddata3; | |||
|  | 
 | |||
|  |             float voltage; | |||
|  |             String ElelabID; | |||
|  |             model.dis_id id; | |||
|  | 
 | |||
|  |             id.order = 0; | |||
|  |             id.ele_id = devId; | |||
|  |             id.state = 1; | |||
|  |             if ((id.ele_id < 0) || (id.ele_id > MAX_LIGHT_NUM)) | |||
|  |             { | |||
|  |                 MessageBox.Show("设备ID必须在0到5100之间"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             ret = aa.get_inf_device(id); | |||
|  |             if (!ret) | |||
|  |             { | |||
|  |                 MessageBox.Show("读取设备信息失败"); | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 version = (aa.command_test_buf[5] << 8) + aa.command_test_buf[6]; | |||
|  |                 if (id.ele_id >= 5000)//巷灯 | |||
|  |                 { | |||
|  |                     voltage = (aa.command_test_buf[7] << 8) + aa.command_test_buf[8]; | |||
|  |                     voltage = (voltage * 5 * 11) / 1024; | |||
|  |                     ElelabCnt = (aa.command_test_buf[9] << 8) + aa.command_test_buf[10]; | |||
|  |                     if (ElelabCnt > 0) | |||
|  |                     { | |||
|  |                         ElelabID = "绑定标签ID:"; | |||
|  |                         for (int i = 0; i < ElelabCnt; i++) | |||
|  |                         { | |||
|  |                             temp = (aa.command_test_buf[11 + i * 2] << 8) + aa.command_test_buf[12 + i * 2]; | |||
|  |                             ElelabID = ElelabID + temp.ToString() + ","; | |||
|  |                         } | |||
|  |                         // MessageBox.Show("巷灯设备" + "\r\n" + "版本:" + version.ToString() + "\r\n" + "输入电压:" + voltage.ToString("0.00") + "\r\n" + "绑定标签数:" + ElelabCnt.ToString() + "\r\n" + ElelabID); | |||
|  |                         addLog("巷灯设备" + "\r\n" + "版本:" + version.ToString() + "\r\n" + "输入电压:" + voltage.ToString("0.00") + "\r\n" + "绑定标签数:" + ElelabCnt.ToString() + "\r\n" + ElelabID); | |||
|  | 
 | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         // MessageBox.Show("巷灯设备" + "\r\n" + "版本:" + version.ToString() + "\r\n" + "输入电压:" + voltage.ToString("0.00") + "\r\n" + "绑定标签数:" + ElelabCnt.ToString()); | |||
|  |                         addLog("巷灯设备" + "\r\n" + "版本:" + version.ToString() + "\r\n" + "输入电压:" + voltage.ToString("0.00") + "\r\n" + "绑定标签数:" + ElelabCnt.ToString()); | |||
|  | 
 | |||
|  |                     } | |||
|  |                 } | |||
|  |                 else if (id.ele_id == 0)//控制器 | |||
|  |                 { | |||
|  |                     ElelabCnt = (aa.command_test_buf[7] << 8) + aa.command_test_buf[8]; | |||
|  |                     ddata[0] = aa.command_test_buf[9]; | |||
|  |                     ddata[1] = aa.command_test_buf[10]; | |||
|  |                     ddata[2] = aa.command_test_buf[11]; | |||
|  |                     ddata[3] = aa.command_test_buf[12]; | |||
|  |                     ddata[4] = aa.command_test_buf[13]; | |||
|  |                     ddata[5] = aa.command_test_buf[14]; | |||
|  |                     ddata[6] = aa.command_test_buf[15]; | |||
|  |                     ddata[7] = aa.command_test_buf[16]; | |||
|  |                     ddata[8] = aa.command_test_buf[17]; | |||
|  |                     ddata[9] = aa.command_test_buf[18]; | |||
|  | 
 | |||
|  |                     //   MessageBox.Show("控制器设备" + "\r\n" + "版本:" + version.ToString() + "\r\n" + "剩余空间数:" + ElelabCnt.ToString() + "\r\n" + | |||
|  |                     //                ddata[0].ToString() + ":" + ddata[1].ToString() + ":" + ddata[2].ToString() + ":" + | |||
|  |                     //                ddata[3].ToString() + ":" + ddata[4].ToString() + ":" + ddata[5].ToString() + ":" + | |||
|  |                     //                ddata[6].ToString() + ":" + ddata[7].ToString() + ":" + ddata[8].ToString() + ":" +  ddata[9].ToString() + ":"); | |||
|  | 
 | |||
|  |                     addLog("控制器设备" + "\r\n" + "版本:" + version.ToString() + "\r\n" + "剩余空间数:" + ElelabCnt.ToString() + "\r\n" + | |||
|  |                                ddata[0].ToString() + ":" + ddata[1].ToString() + ":" + ddata[2].ToString() + ":" + | |||
|  |                                ddata[3].ToString() + ":" + ddata[4].ToString() + ":" + ddata[5].ToString() + ":" + | |||
|  |                                ddata[6].ToString() + ":" + ddata[7].ToString() + ":" + ddata[8].ToString() + ":" + ddata[9].ToString() + ":"); | |||
|  | 
 | |||
|  |                 } | |||
|  |                 else if (aa.command_test_buf[8] == 0) //扫描枪 | |||
|  |                 { | |||
|  |                     MessageBox.Show("扫描枪设备" + "\r\n" + "版本:" + version.ToString()); | |||
|  |                 } | |||
|  |                 else if (aa.command_test_buf[8] == 0xaa)//标签 | |||
|  |                 { | |||
|  |                     version = aa.command_test_buf[5]; | |||
|  |                     if (aa.command_test_buf[6] == 0xaa) | |||
|  |                         addLog("标签设备" + "\r\n" + "版本:" + version.ToString() + "\r\n" + "剩余空间数:" + aa.command_test_buf[7].ToString() + "\r\n" + "显示模式:bcd码"); | |||
|  |                     else | |||
|  |                         addLog("标签设备" + "\r\n" + "版本:" + version.ToString() + "\r\n" + "剩余空间数:" + aa.command_test_buf[7].ToString() + "\r\n" + "显示模式:十进制"); | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         bool isCloseLight; | |||
|  |         private void simpleButton7_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             int temp = 0; | |||
|  |             if (this.txtChID21.Text == "") | |||
|  |             { | |||
|  |                 MessageBox.Show("请输入巷灯ID,在5000到5500之间"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 try | |||
|  |                 { | |||
|  |                     temp = Convert.ToInt16(txtChID21.Text); | |||
|  |                     if ((temp > MAX_LIGHT_NUM) || (temp < 5000)) | |||
|  |                     { | |||
|  |                         MessageBox.Show("巷灯ID必须在5000到5500之间"); | |||
|  |                         return; | |||
|  |                     } | |||
|  |                 } | |||
|  |                 catch | |||
|  |                 { | |||
|  |                     MessageBox.Show("巷灯ID必须在5000到5500之间"); | |||
|  |                     return; | |||
|  |                 } | |||
|  | 
 | |||
|  |             } | |||
|  | 
 | |||
|  |             openChannel(temp); | |||
|  | 
 | |||
|  |           //  simpleButton7.Text = isCloseLight ? "显示" : "关闭"; | |||
|  |           //  isCloseLight = !isCloseLight; | |||
|  | 
 | |||
|  |             //readDevice(temp); | |||
|  |         } | |||
|  | 
 | |||
|  | 
 | |||
|  |         void openChannel(int lightId) | |||
|  |         { | |||
|  | 
 | |||
|  |             byte led_rgb = getLedColor(); | |||
|  |             model.open_channel_led id; | |||
|  |             id.channel_id = lightId; | |||
|  |             id.config_word = led_rgb; | |||
|  |             id.state = 1; | |||
|  |             aa.write_open_channel_led(id); | |||
|  | 
 | |||
|  |         } | |||
|  | 
 | |||
|  |         private void simpleButton6_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             model.modify_id id; | |||
|  |             try | |||
|  |             { | |||
|  |                 id.old_ele_id = Convert.ToInt16(this.txtLbId11.Text); | |||
|  |                 id.order = 1; | |||
|  |                 id.new_ele_id = Convert.ToInt16(this.txtlbID12.Text); | |||
|  |                 id.state = 1; | |||
|  |                 aa.write_modify_id_comment(id); | |||
|  | 
 | |||
|  |                 addLog(string.Format("ID changed from {0} to {1} ", id.old_ele_id, id.new_ele_id)); | |||
|  |             } | |||
|  |             catch | |||
|  |             { | |||
|  |             } | |||
|  | 
 | |||
|  |         } | |||
|  | 
 | |||
|  |         private void simpleButton8_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             int temp = 0; | |||
|  |             if (txtChID21.Text == "") | |||
|  |             { | |||
|  |                 MessageBox.Show("请输入巷灯ID,在5000到5100之间"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 temp = Convert.ToInt16(txtChID21.Text); | |||
|  |                 if ((temp > MAX_LIGHT_NUM) || (temp < 5000)) | |||
|  |                 { | |||
|  |                     MessageBox.Show("巷灯ID必须在5000到5100之间"); | |||
|  |                     return; | |||
|  |                 } | |||
|  |             } | |||
|  | 
 | |||
|  |             MessageBoxButtons messButton = MessageBoxButtons.OKCancel; | |||
|  |             DialogResult dr = MessageBox.Show(String.Format("确定要清除绑定吗?"), "清除绑定", messButton); | |||
|  |             if (dr != DialogResult.OK) | |||
|  |             { | |||
|  |                 return; | |||
|  |             } | |||
|  |             model.close_channel_led id; | |||
|  |             id.channel_id = temp; | |||
|  |             id.config_word = led_rgb; | |||
|  |             id.state = 1; | |||
|  |             bool ret = aa.clear_channel_led(id);//write_config_channel_led | |||
|  |             if (ret) MessageBox.Show("清除巷灯成功"); | |||
|  |             else MessageBox.Show("清除巷灯失败"); | |||
|  |         } | |||
|  | 
 | |||
|  |         private void simpleButton9_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             MessageBoxButtons messButton = MessageBoxButtons.OKCancel; | |||
|  |             DialogResult dr = MessageBox.Show(String.Format("确定要清除所有绑定吗?"), "清除所有绑定", messButton); | |||
|  |             if (dr == DialogResult.OK) | |||
|  |             { | |||
|  |                 dr = MessageBox.Show(String.Format("真确定要清除所有绑定吗?"), "清除所有绑定", messButton); | |||
|  | 
 | |||
|  |                 if (dr != DialogResult.OK) | |||
|  |                 { | |||
|  |                     return; | |||
|  |                 } | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 return; | |||
|  |             } | |||
|  | 
 | |||
|  |             model.close_channel_led id; | |||
|  |             id.channel_id = 0xffff; | |||
|  |             id.config_word = led_rgb; | |||
|  |             id.state = 1; | |||
|  |             bool ret = aa.clear_channel_led(id);//write_config_channel_led | |||
|  |             if (ret) MessageBox.Show("清除巷灯成功"); | |||
|  |             else MessageBox.Show("清除巷灯失败"); | |||
|  |         } | |||
|  | 
 | |||
|  |         private void simpleButton12_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             bool ret; | |||
|  |             model.modify_id id; | |||
|  | 
 | |||
|  |             if (this.txtChID21.Text == "") | |||
|  |             { | |||
|  |                 MessageBox.Show("请输入的旧巷灯ID"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             if (txtChID22.Text == "") | |||
|  |             { | |||
|  |                 MessageBox.Show("请输入的新巷灯ID"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             id.order = 0; | |||
|  |             id.new_ele_id = Convert.ToInt16(txtChID22.Text); | |||
|  |             id.old_ele_id = Convert.ToInt16(txtChID21.Text); | |||
|  |             id.state = 1; | |||
|  |             if ((id.new_ele_id > MAX_LIGHT_NUM) || (id.new_ele_id < 5000) || (id.old_ele_id > MAX_LIGHT_NUM) || (id.old_ele_id < 5000)) | |||
|  |             { | |||
|  |                 MessageBox.Show("巷灯ID必须在5000到5500"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             ret = aa.change_light_id(id); | |||
|  |             if (!ret) | |||
|  |             { | |||
|  |                 //MessageBox.Show("修改巷灯ID失败"); | |||
|  |                 addLog("巷灯" + id.old_ele_id.ToString() + "修改成" + id.new_ele_id.ToString() + "失败"); | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 // MessageBox.Show("巷灯" + id.old_ele_id.ToString() + "修改成" + id.new_ele_id.ToString() + "成功"); | |||
|  |                 addLog("巷灯" + id.old_ele_id.ToString() + "修改成" + id.new_ele_id.ToString() + "成功"); | |||
|  |                 openChannel(id.new_ele_id); | |||
|  |                 txtChID22.Text = (id.new_ele_id + 1)+""; | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         private void simpleButton1_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             int temp = 0; | |||
|  |             if (this.txtChID21.Text == "") | |||
|  |             { | |||
|  |                 MessageBox.Show("请输入的旧巷灯ID"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 try | |||
|  |                 { | |||
|  |                     temp = Convert.ToInt16(txtChID21.Text); | |||
|  |                 } | |||
|  |                 catch { } | |||
|  |                 if ((temp > MAX_LIGHT_NUM) || (temp < 5000)) | |||
|  |                 { | |||
|  |                     MessageBox.Show("巷灯ID必须在5000到5100之间"); | |||
|  |                     return; | |||
|  |                 } | |||
|  |             } | |||
|  |             model.config_channel_led id; | |||
|  |             byte led_rgb = getLedColor(); | |||
|  |             | |||
|  |             id.channel_id = temp; | |||
|  |             id.config_word = led_rgb; | |||
|  |             id.state = 1; | |||
|  |             aa.write_config_channel_led(id);//write_config_channel_led | |||
|  |         } | |||
|  | 
 | |||
|  |         byte getLedColor() | |||
|  |         { | |||
|  |             byte led_rgb = 0; | |||
|  |             switch (combChcolor.Text) | |||
|  |             { | |||
|  |                 case "红": | |||
|  |                     led_rgb = 0; | |||
|  |                     break; | |||
|  |                 case "绿": | |||
|  |                     led_rgb = 1; | |||
|  |                     break; | |||
|  |                 case "蓝": | |||
|  |                     led_rgb = 2; | |||
|  |                     break; | |||
|  |                 case "黄": | |||
|  |                     led_rgb = 3; | |||
|  |                     break; | |||
|  |                 case "白": | |||
|  |                     led_rgb = 4; | |||
|  |                     break;     | |||
|  |                 default: | |||
|  |                     led_rgb = 0; | |||
|  |                     break; | |||
|  |             } | |||
|  |             return led_rgb; | |||
|  | 
 | |||
|  |         } | |||
|  | 
 | |||
|  |         void initComs() | |||
|  |         { | |||
|  |             String[] Portname = System.IO.Ports.SerialPort.GetPortNames(); | |||
|  | 
 | |||
|  |             combComs.Properties.TextEditStyle = TextEditStyles.DisableTextEditor; | |||
|  |             combComs.Properties.Items.Clear(); | |||
|  |             ComboBoxItemCollection col = combComs.Properties.Items; | |||
|  |             col.BeginUpdate(); | |||
|  | 
 | |||
|  |             try | |||
|  |             { | |||
|  | 
 | |||
|  |                 for (int i = 0; i < Portname.Length; i++) | |||
|  |                 { | |||
|  |                     //col.Add(i); | |||
|  |                     col.Add(Portname[i]); | |||
|  |                 } | |||
|  | 
 | |||
|  |             } | |||
|  |             finally | |||
|  |             { | |||
|  |                 col.EndUpdate(); | |||
|  |             } | |||
|  | 
 | |||
|  |             combComs.SelectedIndex = 0; | |||
|  | 
 | |||
|  |         } | |||
|  |         void initialCom() | |||
|  |         { | |||
|  |             bool ret = false; | |||
|  | 
 | |||
|  |             try | |||
|  |             { | |||
|  |                 aa = coms.Keys.Contains(combComs.Text) ? coms[combComs.Text] : new dnrj(); | |||
|  |                 if (coms.Keys.Contains(combComs.Text)) | |||
|  |                 { | |||
|  |                     aa = coms[combComs.Text]; | |||
|  |                     addLog(string.Format(combComs.Text + " 打开{0}", "成功")); | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     aa = new dnrj(); | |||
|  |                     ret = aa.init_wms_sys(1, combComs.Text); | |||
|  |                     if (ret) | |||
|  |                     { | |||
|  |                         coms[combComs.Text] = aa; | |||
|  |                         aa.check_state = true; | |||
|  |                         aa.on_dis_event += new dnrj.receive_dis_data(receive_dis_data); | |||
|  | 
 | |||
|  |                         aa.on_send_dis_result_event += new dn_wms.dnrj.send_dis_data_result(receive_dis_data_result); | |||
|  |                         aa.on_close_channel += new dn_wms.dnrj.close_channel(aa_on_close_channel); | |||
|  |                         aa.on_config_channel += new dnrj.config_channel(aa_on_config_channel); | |||
|  |                         aa.on_open_channel += new dnrj.open_channel(aa_on_open_channel); | |||
|  | 
 | |||
|  |                         timer1.Enabled = true;//设置为true开始计时             | |||
|  |                         timer1.Interval = 50;//设置timer1的执行周期为50毫秒 | |||
|  | 
 | |||
|  |                         model.dis_id id; | |||
|  |                         id.order = 0; | |||
|  |                         id.ele_id = 65535; | |||
|  |                         id.state = 1; | |||
|  |                         aa.write_reset_device(id); | |||
|  |                         System.Threading.Thread.Sleep(100); | |||
|  |                         id.order = 1; | |||
|  |                         id.ele_id = 0; | |||
|  |                         id.state = 1; | |||
|  |                         aa.write_reset_device(id); | |||
|  | 
 | |||
|  |                     } | |||
|  |                     addLog(string.Format(combComs.Text + "打开{0}", ret ? "成功" : "失败")); | |||
|  |                 } | |||
|  | 
 | |||
|  |             } | |||
|  |             catch | |||
|  |             { | |||
|  |             } | |||
|  |               | |||
|  |         } | |||
|  | 
 | |||
|  |         private void simpleButton2_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             initialCom(); | |||
|  |         } | |||
|  |         void aa_on_open_channel(model.open_channel_led data) | |||
|  |         { | |||
|  |          //   MessageBox.Show("打开巷灯 id = " + data.channel_id.ToString() + " 成功"); | |||
|  |             //throw new NotImplementedException(); | |||
|  |         } | |||
|  | 
 | |||
|  |         void aa_on_config_channel(model.config_channel_led data) | |||
|  |         { | |||
|  |          //  addLog("配置 id = " + data.channel_id.ToString() + "配置字 = " + data.config_word.ToString() + " 成功 "); | |||
|  |             //throw new NotImplementedException(); | |||
|  |         } | |||
|  | 
 | |||
|  |         void aa_on_close_channel(model.close_channel_led data) | |||
|  |         { | |||
|  |            // addLog("关闭巷灯 id = " + data.channel_id.ToString() + " 成功"); | |||
|  |             //throw new NotImplementedException(); | |||
|  |         } | |||
|  |         private void receive_dis_data_result(byte order, byte result, string result1) | |||
|  |         { | |||
|  |             if (this.lbstate.InvokeRequired) | |||
|  |             { | |||
|  |                 dis_result aa = new dis_result(manage_state); | |||
|  |                 lbstate.Invoke(aa, result.ToString()); | |||
|  |                 //lbstate.Invoke(result.ToString()); | |||
|  |                 if (result == 4) MessageBox.Show("数据部分发送成功", "title", MessageBoxButtons.OK, MessageBoxIcon.Error); | |||
|  |             } | |||
|  | 
 | |||
|  |         } | |||
|  |         private void receive_dis_data(model.uart_dis_data[] data) | |||
|  |         { | |||
|  |             if (data.Length == 1) | |||
|  |             { | |||
|  | 
 | |||
|  |                 if (meditLogs.InvokeRequired) | |||
|  |                 { | |||
|  |                     receive_result aa = new receive_result(receive_result1); | |||
|  |                     meditLogs.Invoke(aa, data); | |||
|  |                     //receive_result | |||
|  |                 } | |||
|  | 
 | |||
|  | 
 | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 if (lbstate.InvokeRequired) | |||
|  |                 { | |||
|  |                     dis_result aa = new dis_result(manage_state); | |||
|  |                     lbstate.Invoke(aa, "数据处理完毕"); | |||
|  |                     //lbstate.Invoke(result.ToString()); | |||
|  |                 }; | |||
|  |             } | |||
|  |             //MessageBox.Show("ok"); | |||
|  |         } | |||
|  |         private void receive_result1(model.uart_dis_data[] data) | |||
|  |         { | |||
|  |             try | |||
|  |             { | |||
|  |                 order[test_count[data[0].order] % 260] = data[0].ele_id; | |||
|  |                 for (int i = 0; i < 1300; i++) | |||
|  |                 { | |||
|  |                     if ((goods_send_id[i] == data[0].ele_id) && (goods_send_lid[i] == data[0].little_ele_id) && (goods_send_order[i] == data[0].order)) | |||
|  |                     { | |||
|  |                         break; | |||
|  |                     } | |||
|  |                     else if ((goods_send_id[i] == 0) && (goods_send_lid[i] == 0)) | |||
|  |                     { | |||
|  |                         goods_send_id[i] = data[0].ele_id; | |||
|  |                         goods_send_lid[i] = data[0].little_ele_id; | |||
|  |                         goods_send_order[i] = data[0].order; | |||
|  |                         test_count[data[0].order]++; | |||
|  |                         if (test_count[data[0].order] > 60000) | |||
|  |                             test_count[data[0].order] = 0; | |||
|  |                         //by dhwu 150529 if (checkBox3.Checked == true) | |||
|  |                         { | |||
|  |                             //   meditLogs.Text = meditLogs.Text + data[0].order.ToString() + "  " + data[0].ele_id.ToString() + "  " + data[0].little_ele_id.ToString() + "  " + data[0].receive_count.ToString() + "  " + test_count[data[0].order].ToString() + '\r' + '\n'; | |||
|  |                             //  addLog(  data[0].order.ToString() + "  " + data[0].ele_id.ToString() + "  " + data[0].little_ele_id.ToString() + "  " + data[0].receive_count.ToString() + "  " + test_count[data[0].order].ToString() + '\r' + '\n'); | |||
|  |                          //   addLog(String.Format("ID:{0}  LOC:{1}   CNT:{2}", data[0].ele_id.ToString(), | |||
|  |                           //      data[0].little_ele_id.ToString(), data[0].little_ele_idH2.ToString(), data[0].receive_count.ToString())); | |||
|  | 
 | |||
|  |                             addLog(String.Format("ID:{0}  LOC:{1}  LOC2: {2} ", data[0].ele_id.ToString(), | |||
|  |                                    data[0].little_ele_id.ToString(), data[0].little_ele_idH2.ToString() | |||
|  |                                   )); | |||
|  |                                | |||
|  |                             // meditLogs.Focus();//获取焦 | |||
|  |                             // meditLogs.Select(this.meditLogs.TextLength, 0);//光标定位到文本最后 | |||
|  |                             // meditLogs.ScrollToCaret();//滚动到光标处  | |||
|  |                         } | |||
|  |                         break; | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |             catch | |||
|  |             { | |||
|  |                 MessageBox.Show("异常数据" + data[0].ele_id.ToString()); | |||
|  | 
 | |||
|  |             } | |||
|  | 
 | |||
|  |         } | |||
|  |         private void receive_dis_data1(model.uart_dis_data[] data) | |||
|  |         { | |||
|  |             if (data.Length == 1) | |||
|  |             { | |||
|  | 
 | |||
|  |                 if (meditLogs.InvokeRequired) | |||
|  |                 { | |||
|  |                     receive_result aa = new receive_result(receive_result1); | |||
|  |                     meditLogs.Invoke(aa, data); | |||
|  |                     //receive_result | |||
|  |                 } | |||
|  | 
 | |||
|  | 
 | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 if (lbstate.InvokeRequired) | |||
|  |                 { | |||
|  |                     dis_result aa = new dis_result(manage_state); | |||
|  |                     lbstate.Invoke(aa, "数据处理完毕"); | |||
|  |                     //lbstate.Invoke(result.ToString()); | |||
|  |                 }; | |||
|  |             } | |||
|  |             //MessageBox.Show("ok"); | |||
|  |         } | |||
|  | 
 | |||
|  |         private void manage_state(string state) | |||
|  |         { | |||
|  |             //if() | |||
|  | 
 | |||
|  |             switch (state) | |||
|  |             { | |||
|  |                 case "1": | |||
|  |                     lbstate.Text = "数据发送成功,开始播种"; | |||
|  |                     break; | |||
|  |                 case "2": | |||
|  |                     lbstate.Text = "有相同的订单号在处理"; | |||
|  |                     break; | |||
|  |                 case "3": | |||
|  |                     lbstate.Text = "控制器没有空间  稍后再发送数据"; | |||
|  |                     break; | |||
|  |                 case "4": | |||
|  |                     lbstate.Text = "数据部分发送成功,开始播种"; | |||
|  |                     break; | |||
|  |                 case "5": | |||
|  |                     lbstate.Text = "数据发送失败,开始播种"; | |||
|  |                     break; | |||
|  |                 case "数据处理完毕": | |||
|  |                     lbstate.Text = "播种完毕"; | |||
|  |                     break; | |||
|  |             } | |||
|  |             // lbstate.Text = state; | |||
|  | 
 | |||
|  |         } | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |         private void timer1_Tick(object sender, EventArgs e) | |||
|  |         { | |||
|  |             bool ret; | |||
|  |             // MessageBox.Show("你好,这是第" + n + "次打招呼哦");//弹出对话框告诉你             | |||
|  |             if (SendMode == 0x11) | |||
|  |             { | |||
|  |                 SendData.order = 0; | |||
|  |                 SendData.ele_id = test_elelab_address; | |||
|  |                 SendData.state = 1; | |||
|  |                 ret = aa.write_test_device(SendData, offset); | |||
|  |                 if (!ret) | |||
|  |                 { | |||
|  |                     //meditLogs.Text = meditLogs.Text + "标签" + test_elelab_address.ToString() + "通信错误" + "\r\n"; | |||
|  |                     addLog("标签" + test_elelab_address.ToString() + "通信错误"); | |||
|  |                     // this.meditLogs.Focus();//获取焦点 | |||
|  |                     // this.meditLogs.Select(this.meditLogs.TextLength, 0);//光标定位到文本最后 | |||
|  |                     this.meditLogs.ScrollToCaret();//滚动到光标处 | |||
|  |                     elelab_test_error[test_elelab_address]++; | |||
|  |                 } | |||
|  |                 test_elelab_address++; | |||
|  |                 if (test_elelab_address > test_elelab_stop) | |||
|  |                 { | |||
|  |                     test_elelab_address = test_elelab_start; | |||
|  |                     PackageNum++; | |||
|  |                     offset++; | |||
|  |                     if (offset > 240) offset = 0; | |||
|  | 
 | |||
|  |                     lbstate.Text = "发送包数" + PackageNum.ToString(); | |||
|  |                 } | |||
|  |             } | |||
|  |             else if (SendMode == 0x12) | |||
|  |             { | |||
|  |                 SendData.order = 0; | |||
|  |                 SendData.ele_id = test_light_address; | |||
|  |                 SendData.state = 1; | |||
|  |                 ret = aa.write_test_device(SendData, offset); | |||
|  |                 if (!ret) | |||
|  |                 { | |||
|  |                     // meditLogs.Text = meditLogs.Text + "巷灯" + test_light_address.ToString() + "通信错误" + "\r\n"; | |||
|  |                     addLog("巷灯" + test_light_address.ToString() + "通信错误"); | |||
|  |                     //this.meditLogs.Focus();//获取焦点 | |||
|  |                     // this.meditLogs.Select(this.meditLogs.TextLength, 0);//光标定位到文本最后 | |||
|  |                     this.meditLogs.ScrollToCaret();//滚动到光标处 | |||
|  |                     light_test_error[test_light_address - 5000]++; | |||
|  |                 } | |||
|  |                 test_light_address++; | |||
|  |                 if (test_light_address > test_light_stop) | |||
|  |                 { | |||
|  |                     test_light_address = test_light_start; | |||
|  |                     PackageNum++; | |||
|  |                     offset++; | |||
|  |                     if (offset > 240) offset = 0; | |||
|  | 
 | |||
|  |                     lbstate.Text = "发送包数" + PackageNum.ToString(); | |||
|  |                 } | |||
|  |             } | |||
|  |             else if (SendMode == 0x13) | |||
|  |             { | |||
|  |                 if (SendSeq) | |||
|  |                 { | |||
|  |                     SendData.order = 0; | |||
|  |                     SendData.ele_id = test_elelab_address; | |||
|  |                     SendData.state = 1; | |||
|  |                     ret = aa.write_test_device(SendData, offset); | |||
|  |                     if (!ret) | |||
|  |                     { | |||
|  |                         // meditLogs.Text = meditLogs.Text + "标签" + test_elelab_address.ToString() + "通信错误" + "\r\n"; | |||
|  |                         addLog("标签" + test_elelab_address.ToString() + "通信错误"); | |||
|  |                         // this.meditLogs.Focus();//获取焦点 | |||
|  |                         //  this.meditLogs.Select(this.meditLogs.TextLength, 0);//光标定位到文本最后 | |||
|  |                         this.meditLogs.ScrollToCaret();//滚动到光标处 | |||
|  |                         elelab_test_error[test_elelab_address]++; | |||
|  |                     } | |||
|  |                     test_elelab_address++; | |||
|  |                     if (test_elelab_address > test_elelab_stop) | |||
|  |                     { | |||
|  |                         test_elelab_address = test_elelab_start; | |||
|  |                         SendSeq = false; | |||
|  |                     } | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     SendData.order = 0; | |||
|  |                     SendData.ele_id = test_light_address; | |||
|  |                     SendData.state = 1; | |||
|  |                     ret = aa.write_test_device(SendData, offset); | |||
|  |                     if (!ret) | |||
|  |                     { | |||
|  |                         // meditLogs.Text = meditLogs.Text + "巷灯" + test_light_address.ToString() + "通信错误" + "\r\n"; | |||
|  |                         addLog("巷灯" + test_light_address.ToString() + "通信错误"); | |||
|  |                         // this.meditLogs.Focus();//获取焦点 | |||
|  |                         // this.meditLogs.Select(this.meditLogs.TextLength, 0);//光标定位到文本最后 | |||
|  |                         this.meditLogs.ScrollToCaret();//滚动到光标处 | |||
|  |                         light_test_error[test_light_address - 5000]++; | |||
|  |                     } | |||
|  |                     test_light_address++; | |||
|  |                     if (test_light_address > test_light_stop) | |||
|  |                     { | |||
|  |                         test_light_address = test_light_start; | |||
|  |                         PackageNum++; | |||
|  |                         offset++; | |||
|  |                         if (offset > 240) offset = 0; | |||
|  | 
 | |||
|  |                         lbstate.Text = "发送包数" + PackageNum.ToString(); | |||
|  |                         SendSeq = true; | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |             /* else if (aa.command_scan) | |||
|  |              { | |||
|  |                  aa.command_scan = false; | |||
|  |                  int tmp = (aa.command_test_buf[2] << 8) + aa.command_test_buf[3]; | |||
|  |                  label45.Text = tmp.ToString() + ": "; | |||
|  |                  for (int i = 0; i < aa.command_test_buf[6]; i++) | |||
|  |                  { | |||
|  |                      label45.Text += (char)aa.command_test_buf[7 + i]; | |||
|  |                  } | |||
|  |              }*/ | |||
|  |             else if ((aa.command_test_kzq) && (flag_kzq_test == 1)) | |||
|  |             { | |||
|  |                 aa.command_test_kzq = false; | |||
|  |                 int i; | |||
|  |                 for (i = 5; i < len_kzq_test + 5; i++) | |||
|  |                 { | |||
|  |                     if (aa.command_test_buf[i] != ((byte)(i + offset_kzq_test - 5))) | |||
|  |                     { | |||
|  |                         light_test_error[0]++; | |||
|  |                         meditLogs.Text = meditLogs.Text + "*************错误发生***********" + PackageNum.ToString() + "\r\n"; | |||
|  |                         // this.meditLogs.Focus();//获取焦点 | |||
|  |                         // this.meditLogs.Select(this.meditLogs.TextLength, 0);//光标定位到文本最后 | |||
|  |                         this.meditLogs.ScrollToCaret();//滚动到光标处 | |||
|  |                         break; | |||
|  |                     } | |||
|  |                 } | |||
|  |                 if (i >= (len_kzq_test + 5)) | |||
|  |                 { | |||
|  |                     lbstate.Text = "发送包数" + PackageNum.ToString(); | |||
|  |                 } | |||
|  |                 offset_kzq_test++; | |||
|  |                 if (offset_kzq_test == len_kzq_test) offset_kzq_test = 0; | |||
|  |                 ret = aa.send_kzq_test(offset_kzq_test, len_kzq_test); | |||
|  |                 if (!ret) | |||
|  |                 { | |||
|  |                     MessageBox.Show("测试控制器失败:" + offset_kzq_test.ToString()); | |||
|  |                 } | |||
|  |                 PackageNum++; | |||
|  |             } | |||
|  |             else if (aa.command_bz_ack > 0)//by dhwu 150122 修改lbstate显示 | |||
|  |             { | |||
|  |                 if (aa.command_bz_ack == 1) | |||
|  |                 { | |||
|  |                     lbstate.Text = "数据发送成功,开始播种"; | |||
|  |                     addLog("数据发送成功" + "\r\n"); | |||
|  |                 } | |||
|  |                 else if (aa.command_bz_ack == 4) | |||
|  |                 { | |||
|  |                     aa.command_bz_ack = 0; | |||
|  |                     lbstate.Text = "数据部分发送成功,开始播种"; | |||
|  |                     addLog("数据部分发送成功" + "\r\n"); | |||
|  |                     addLog("数据部分发送成功"); | |||
|  |                 } | |||
|  |                 else if (aa.command_bz_ack == 5) lbstate.Text = "数据发送失败,开始播种"; | |||
|  |                 else if (aa.command_bz_ack == 6) | |||
|  |                 { | |||
|  |                     aa.command_bz_ack = 0; | |||
|  |                     lbstate.Text = "播种完毕"; | |||
|  |                     addLog("播种完毕" + "\r\n"); | |||
|  |                     if (test_count != count_bz) | |||
|  |                         addLog("播种丢包"); | |||
|  |                 } | |||
|  |                 aa.command_bz_ack = 0; | |||
|  |                 //  this.meditLogs.Focus();//获取焦点 | |||
|  |                 // this.meditLogs.Select(this.meditLogs.TextLength, 0);//光标定位到文本最后 | |||
|  |                 this.meditLogs.ScrollToCaret();//滚动到光标处 | |||
|  |             } | |||
|  |             lbTranserror.Text = aa.crc_count.ToString(); | |||
|  |         } | |||
|  | 
 | |||
|  |         private void simpleButton11_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             readDevice(0); | |||
|  |         } | |||
|  | 
 | |||
|  |         | |||
|  | 
 | |||
|  |         private void simpleButton3_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  | 
 | |||
|  |             int startId = 0; //Convert.ToInt16(txtIDfrom.Text); | |||
|  |             int endId = 0;// Convert.ToInt16(txtIDto.Text); | |||
|  |             int newId = 0;//Convert.ToInt16(txtNewId.Text); | |||
|  | 
 | |||
|  |             try | |||
|  |             { | |||
|  |                 startId = Convert.ToInt16(txtIDfrom.Text); | |||
|  |                 endId = Convert.ToInt16(txtIDto.Text); | |||
|  |                 newId = Convert.ToInt16(txtNewId.Text); | |||
|  | 
 | |||
|  |                 if (endId < startId || newId <0 || endId >5500) | |||
|  |                 { | |||
|  |                     throw new Exception(); | |||
|  |                 } | |||
|  |             } | |||
|  |             catch | |||
|  |             { | |||
|  |                 addLog("请输入合法的ID"); | |||
|  |                 return; | |||
|  |             } | |||
|  | 
 | |||
|  | 
 | |||
|  |             MessageBoxButtons messButton = MessageBoxButtons.OKCancel; | |||
|  |             DialogResult dr = MessageBox.Show(String.Format("确定重新设定{0}--{1} ID为{2}吗?", startId, endId, newId), "重新设定ID", messButton); | |||
|  |             if (dr == DialogResult.OK) | |||
|  |             { | |||
|  |                 dr = MessageBox.Show(String.Format("真的确定要重新设定ID吗?"), "重新设定ID", messButton); | |||
|  | 
 | |||
|  |                 if (dr != DialogResult.OK) | |||
|  |                 { | |||
|  |                     return; | |||
|  |                 } | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 return; | |||
|  |             } | |||
|  | 
 | |||
|  |             model.modify_id id; | |||
|  |             for (int i = startId; i <= endId; i++) | |||
|  |             { | |||
|  |                 id.new_ele_id = newId;// Convert.ToInt16(new_id.Text); | |||
|  |                 id.order = 1; | |||
|  |                 id.old_ele_id = i;// Convert.ToInt16(ele_id.Text); | |||
|  |                 id.state = 1; | |||
|  | 
 | |||
|  |                 if (i >= 5000) //light | |||
|  |                 { | |||
|  |                     id.order = 0; | |||
|  |                     aa.change_light_id(id); | |||
|  |                 } | |||
|  |                 else //label | |||
|  |                 { | |||
|  |                     aa.write_modify_id_comment(id);  | |||
|  |                      | |||
|  |                 } | |||
|  |                System.Threading.Thread.Sleep(10); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         private void simpleButton4_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             initialCom(); | |||
|  |         } | |||
|  | 
 | |||
|  |         private void btnReadDev_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             bool ret; | |||
|  |             int version; | |||
|  |             int ElelabCnt, temp; | |||
|  |             //byte ddata1,ddata2,ddata3; | |||
|  |             byte[] ddata = new byte[20];//, ddata2, ddata3; | |||
|  | 
 | |||
|  |             float voltage; | |||
|  |             String ElelabID; | |||
|  |             model.dis_id id; | |||
|  | 
 | |||
|  |             if (txtID.Text == "") | |||
|  |             { | |||
|  |                 MessageBox.Show("请输入设备ID"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             id.order = 0; | |||
|  |             id.ele_id = Convert.ToInt16(txtID.Text); | |||
|  |             id.state = 1; | |||
|  |             if ((id.ele_id < 0) || (id.ele_id > 7700)) | |||
|  |             { | |||
|  |                // MessageBox.Show("设备ID必须在0到5100之间"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             if (id.ele_id == 999) | |||
|  |             { | |||
|  |                 id.ele_id = 0; | |||
|  |             } | |||
|  |             ret = aa.get_inf_device(id); | |||
|  |             if (!ret) | |||
|  |             { | |||
|  |                 MessageBox.Show("读取设备信息失败"); | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 version = (aa.command_test_buf[5] << 8) + aa.command_test_buf[6]; | |||
|  |                 if (id.ele_id >= 5000)//巷灯 | |||
|  |                 { | |||
|  |                     voltage = (aa.command_test_buf[7] << 8) + aa.command_test_buf[8]; | |||
|  |                     voltage = (voltage * 5 * 11) / 1024; | |||
|  |                     ElelabCnt = (aa.command_test_buf[9] << 8) + aa.command_test_buf[10]; | |||
|  |                     if (ElelabCnt > 0) | |||
|  |                     { | |||
|  |                         ElelabID = "绑定标签ID:"; | |||
|  |                         for (int i = 0; i < ElelabCnt; i++) | |||
|  |                         { | |||
|  |                             temp = (aa.command_test_buf[11 + i * 2] << 8) + aa.command_test_buf[12 + i * 2]; | |||
|  |                             ElelabID = ElelabID + temp.ToString() + ","; | |||
|  |                         } | |||
|  |                         addLog("巷灯设备" + "\r\n"  | |||
|  |                           //  + "版本:" + version.ToString()  | |||
|  |                             +/* "\r\n" + "输入电压:" + voltage.ToString("0.00") + */"\r\n" + "绑定标签数:" + ElelabCnt.ToString() + "\r\n" + ElelabID + "\r\n"); | |||
|  |                     } | |||
|  |                     else | |||
|  |                         addLog("巷灯设备" + "\r\n"  | |||
|  |                           // + "版本:" + version.ToString() | |||
|  |                             +/*"\r\n" + "输入电压:" + voltage.ToString("0.00") + */"\r\n" + "绑定标签数:" + ElelabCnt.ToString() + "\r\n"); | |||
|  |                 } | |||
|  |                 else if (id.ele_id == 0)//控制器 | |||
|  |                 { | |||
|  | 
 | |||
|  | 
 | |||
|  |                     /* | |||
|  |                     ElelabCnt = (aa.command_test_buf[7] << 8) + aa.command_test_buf[8]; | |||
|  |                     ddata[0] = aa.command_test_buf[9]; | |||
|  |                     ddata[1] = aa.command_test_buf[10]; | |||
|  |                     ddata[2] = aa.command_test_buf[11]; | |||
|  |                     ddata[3] = aa.command_test_buf[12]; | |||
|  |                     ddata[4] = aa.command_test_buf[13]; | |||
|  |                     ddata[5] = aa.command_test_buf[14]; | |||
|  |                     ddata[6] = aa.command_test_buf[15]; | |||
|  |                     ddata[7] = aa.command_test_buf[16]; | |||
|  |                     ddata[8] = aa.command_test_buf[17]; | |||
|  |                     ddata[9] = aa.command_test_buf[18]; | |||
|  | 
 | |||
|  |                     addLog("控制器设备" + "\r\n" + "版本:" + version.ToString() + "\r\n" + "可用空间数:" + ElelabCnt.ToString() + "\r\n" + | |||
|  |                         ddata[0].ToString() + ":" + ddata[1].ToString() + ":" + ddata[2].ToString() + ":" + | |||
|  |                         ddata[3].ToString() + ":" + ddata[4].ToString() + ":" + ddata[5].ToString() + ":" + | |||
|  |                         ddata[6].ToString() + ":" + ddata[7].ToString() + ":" + ddata[8].ToString() + ":" + | |||
|  |                         ddata[9].ToString() + ":" + "\r\n"); | |||
|  |                      *  | |||
|  |                      * */ | |||
|  | 
 | |||
|  |                     int j = 0; | |||
|  |                     int[] Month = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; | |||
|  |                      | |||
|  |                     ElelabCnt = (aa.command_test_buf[7] << 8) + aa.command_test_buf[8]; | |||
|  |                     ddata[0] = aa.command_test_buf[9]; | |||
|  |                     ddata[1] = aa.command_test_buf[10]; | |||
|  |                     ddata[2] = aa.command_test_buf[11]; | |||
|  |                     ddata[3] = (byte)((aa.command_test_buf[12] >> 4) * 10 + (aa.command_test_buf[12] & 0x0f));//year | |||
|  |                     ddata[4] = (byte)((aa.command_test_buf[13] >> 4) * 10 + (aa.command_test_buf[13] & 0x0f));//month | |||
|  |                     ddata[5] = (byte)((aa.command_test_buf[14] >> 4) * 10 + (aa.command_test_buf[14] & 0x0f));//date | |||
|  |                     ddata[6] = (byte)((aa.command_test_buf[15] >> 4) * 10 + (aa.command_test_buf[15] & 0x0f));//hour | |||
|  |                     ddata[7] = (byte)((aa.command_test_buf[16] >> 4) * 10 + (aa.command_test_buf[16] & 0x0f));//minutes | |||
|  |                     ddata[8] = aa.command_test_buf[17];//power | |||
|  |                     ddata[9] = aa.command_test_buf[18];//flag | |||
|  |                     ddata[10] = aa.command_test_buf[19];//lock | |||
|  |                     //start date | |||
|  |                     temp = aa.command_test_buf[20] * 256 + aa.command_test_buf[21]; | |||
|  |                     ddata[11] = (byte)(temp / 365);// | |||
|  |                     temp = temp % 365; | |||
|  |                     for (  j = 0; j < 12; j++) | |||
|  |                     { | |||
|  |                         if (Month[j] >= temp) break; | |||
|  |                     } | |||
|  |                     ddata[12] = (byte)(j);// | |||
|  |                     if (j > 0) | |||
|  |                         ddata[13] = (byte)(temp - Month[j - 1]);// | |||
|  |                     else | |||
|  |                         ddata[13] = 0; | |||
|  |                     //end date | |||
|  |                     temp = aa.command_test_buf[22] * 256 + aa.command_test_buf[23]; | |||
|  |                     ddata[14] = (byte)(temp / 365);// | |||
|  |                     temp = temp % 365; | |||
|  |                     for (j = 0; j < 12; j++) | |||
|  |                     { | |||
|  |                         if (Month[j] >= temp) break; | |||
|  |                     } | |||
|  |                     ddata[15] = (byte)(j);// | |||
|  |                     if (j > 0) | |||
|  |                         ddata[16] = (byte)(temp - Month[j - 1]);// | |||
|  |                     else | |||
|  |                         ddata[16] = 0; | |||
|  | 
 | |||
|  |                     addLog("控制器" + "\r\n" + | |||
|  |                        // "版本:" + version.ToString() + "\r\n" + | |||
|  |                       //  "剩余空间数:" + ElelabCnt.ToString() + "\r\n" + | |||
|  |                       //  "调试:" + ddata[0].ToString() + ":" + ddata[1].ToString() + ":" + ddata[2].ToString() + "\r\n" + | |||
|  |                       //  "电源:" + ddata[8].ToString() + "\r\n" + | |||
|  |                         "时间:" + ddata[6].ToString() + ":" + ddata[7].ToString() + "\r\n" +   | |||
|  |                         "锁死:" + ddata[9].ToString() + "\r\n" + | |||
|  |                          "预锁:" + ddata[10].ToString() + "\r\n" + | |||
|  |                          "开始日期:" + ddata[11].ToString() + ":" + ddata[12].ToString() + ":" + ddata[13].ToString() + "\r\n" + | |||
|  |                     "日期:" + ddata[3].ToString() + ":" + ddata[4].ToString() + ":" + ddata[5].ToString() + "\r\n" + | |||
|  |                     "结束日期:" + ddata[14].ToString() + ":" + ddata[15].ToString() + ":" + ddata[16].ToString()); | |||
|  |                 } | |||
|  |                 else if (aa.command_test_buf[8] == 0) //扫描枪 | |||
|  |                 { | |||
|  |                     MessageBox.Show("扫描枪设备" + "\r\n" + "版本:" + version.ToString()); | |||
|  |                 } | |||
|  |                 else if (aa.command_test_buf[8] == 0xaa)//标签 | |||
|  |                 { | |||
|  |                     version = aa.command_test_buf[5]; | |||
|  |                     addLog("标签设备" + "\r\n" + "版本:" + version.ToString() + "\r\n" + "可用空间数:" + aa.command_test_buf[7].ToString() + "\r\n"); | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         public struct YMD | |||
|  |         { | |||
|  |             public byte YearS; | |||
|  |             public byte MonthS; | |||
|  |             public byte DateS; | |||
|  |             public byte YearE; | |||
|  |             public byte MonthE; | |||
|  |             public byte DateE; | |||
|  |         } | |||
|  |         string Encrypt(string password)  | |||
|  |         { | |||
|  |             Byte[] clearBytes = new UnicodeEncoding().GetBytes(password); | |||
|  |             Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes); | |||
|  |             return BitConverter.ToString(hashedBytes); | |||
|  |         } | |||
|  |         YMD Release; | |||
|  |         string pd = "12-5F-3C-6F-DA-2E-D3-00-81-A0-E5-B9-DA-AB-67-C6"; | |||
|  |         private void simpleButton2_Click_1(object sender, EventArgs e) | |||
|  |         { | |||
|  |             string str = txtcode.Text;// Interaction.InputBox("??", "??", "", -1, -1); | |||
|  |             txtcode.Text = ""; | |||
|  |             byte[] tempbuf = new byte[12]; | |||
|  |             int temp1, temp2; | |||
|  |             int[] Month = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; | |||
|  | 
 | |||
|  |             string estr = Encrypt(str); | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |             if (estr != pd) | |||
|  |             { | |||
|  |                 MessageBox.Show("输入错误!!"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             Release.YearS = (byte)(dateTimePicker1.DateTime.Year % 2000); | |||
|  |             Release.MonthS = (byte)dateTimePicker1.DateTime.Month; | |||
|  |             Release.DateS = (byte)dateTimePicker1.DateTime.Day; | |||
|  |             Release.YearE = (byte)(dateTimePicker2.DateTime.Year % 2000); | |||
|  |             Release.MonthE = (byte)dateTimePicker2.DateTime.Month; | |||
|  |             Release.DateE = (byte)dateTimePicker2.DateTime.Day; | |||
|  | 
 | |||
|  |             temp1 = Release.YearS * 365 + Month[Release.MonthS - 1] + Release.DateS; | |||
|  |             temp2 = Release.YearE * 365 + Month[Release.MonthE - 1] + Release.DateE; | |||
|  |             if (temp2 > temp1) | |||
|  |             { | |||
|  |                 tempbuf[0] = (byte)(temp1 / 256); | |||
|  |                 tempbuf[1] = (byte)(temp1 % 256); | |||
|  | 
 | |||
|  |                 tempbuf[2] = (byte)(temp2 / 256); | |||
|  |                 tempbuf[3] = (byte)(temp2 % 256); | |||
|  |                 if (aa.write_lock(tempbuf, 4)) | |||
|  |                 { | |||
|  |                     MessageBox.Show("??成功"); | |||
|  |                 } | |||
|  |                 else MessageBox.Show("??失败"); | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 MessageBox.Show("请选择正确的日期"); | |||
|  |             } | |||
|  | 
 | |||
|  |            | |||
|  | 
 | |||
|  |         } | |||
|  | 
 | |||
|  |         private void simpleButton5_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  | 
 | |||
|  |             string str = txtcode.Text;// Interaction.InputBox("???", "???", "", -1, -1); | |||
|  |             txtcode.Text = ""; | |||
|  |             string estr=Encrypt(str); | |||
|  |             if (estr !=pd ) | |||
|  |             { | |||
|  |                 MessageBox.Show("输入错误!!"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             if (aa.write_unlock()) | |||
|  |             { | |||
|  |                 MessageBox.Show("成功"); | |||
|  |             } | |||
|  |             else MessageBox.Show("失败"); | |||
|  |             | |||
|  |         } | |||
|  | 
 | |||
|  |         private void basicFuncs_FormClosing(object sender, FormClosingEventArgs e) | |||
|  |         { | |||
|  |             Application.Exit(); | |||
|  |         } | |||
|  | 
 | |||
|  |         private void chkClearOrder_CheckedChanged(object sender, EventArgs e) | |||
|  |         { | |||
|  | 
 | |||
|  |         } | |||
|  | 
 | |||
|  |         private void combLbColor_SelectedIndexChanged(object sender, EventArgs e) | |||
|  |         { | |||
|  | 
 | |||
|  |         } | |||
|  | 
 | |||
|  |         private void btnCloseLight_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             int temp = 0; | |||
|  |             if (this.txtChID21.Text == "") | |||
|  |             { | |||
|  |                 MessageBox.Show("请输入巷灯ID,在5000到5500之间"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 try | |||
|  |                 { | |||
|  |                     temp = Convert.ToInt16(txtChID21.Text); | |||
|  |                     if ((temp > MAX_LIGHT_NUM) || (temp < 5000)) | |||
|  |                     { | |||
|  |                         MessageBox.Show("巷灯ID必须在5000到5500之间"); | |||
|  |                         return; | |||
|  |                     } | |||
|  |                 } | |||
|  |                 catch | |||
|  |                 { | |||
|  |                     MessageBox.Show("巷灯ID必须在5000到5500之间"); | |||
|  |                     return; | |||
|  |                 } | |||
|  | 
 | |||
|  |             } | |||
|  |                byte led_rgb = getLedColor(); | |||
|  |                 model.close_channel_led id; | |||
|  |                 id.channel_id = temp; | |||
|  |                 id.config_word = led_rgb; | |||
|  |                 id.state = 1; | |||
|  |                 aa.write_close_channel_led(id);//write_config_channel_led | |||
|  | 
 | |||
|  |              | |||
|  |             | |||
|  |         } | |||
|  | 
 | |||
|  |         /* | |||
|  |         // update driver | |||
|  |         //升级标签程序 | |||
|  |         dn_wms.model.updt_id sendUpdateData; | |||
|  |         byte BOOTLDR_CONNECT = 1; | |||
|  |         byte BOOTLDR_SEND_FLASH = 2; | |||
|  |         byte BOOTLDR_SEND_EEPROM = 3; | |||
|  |         byte BOOTLDR_GET_STATE = 4; | |||
|  |         byte BOOTLDR_COMPLETE = 5; | |||
|  |         String szEepPath = ""; | |||
|  |         String szHexPath = ""; | |||
|  |         String szBinPath = ""; | |||
|  |         private void btnUpdateLable_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             int i; | |||
|  |             int j = 0; | |||
|  |             byte[] tempbuf = new byte[128 + 7]; | |||
|  |             ushort verify = 0; | |||
|  |             byte packageNo = 0; | |||
|  |             int packageNoHex = 0; | |||
|  |             String szLine = ""; | |||
|  |             String szHex = ""; | |||
|  | 
 | |||
|  |             if (szHexPath == "") | |||
|  |             { | |||
|  |                 MessageBox.Show("请选择需要转换的hex文件!         ", "错误"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             if (this.chklbeep.Checked == true)//update eeprom | |||
|  |             { | |||
|  |                 if (szEepPath == "") | |||
|  |                 { | |||
|  |                     MessageBox.Show("请选择需要转换的eep文件!         ", "错误"); | |||
|  |                     return; | |||
|  |                 } | |||
|  |             } | |||
|  |             //读取bin文件 | |||
|  |             using (FileStream fsbin = File.OpenRead(szHexPath)) | |||
|  |             { | |||
|  |                 int Length = (int)fsbin.Length; | |||
|  |                 byte[] szBin = new byte[Length + 128]; | |||
|  |                 while (fsbin.Read(szBin, 0, szBin.Length) > 0) | |||
|  |                 { | |||
|  |                     ; | |||
|  |                 } | |||
|  |                 fsbin.Close(); //关闭目标文件 | |||
|  | 
 | |||
|  |                 for (i = 0; i < szBin.Length; i += 3) | |||
|  |                 { | |||
|  |                     szBin[i] = (byte)(szBin[i] ^ 0x5a); | |||
|  |                 } | |||
|  | 
 | |||
|  | 
 | |||
|  |                 try | |||
|  |                 { | |||
|  |                     test_elelab_start = Convert.ToInt16(txtlbID31.Text); | |||
|  |                     test_elelab_stop = Convert.ToInt16(txtlbID32.Text); | |||
|  |                 } | |||
|  |                 catch | |||
|  |                 { | |||
|  |                     MessageBox.Show("输入的地址错误"); | |||
|  |                     SendMode = 0; | |||
|  |                     return; | |||
|  |                 } | |||
|  | 
 | |||
|  | 
 | |||
|  |                 test_elelab_address = test_elelab_start; | |||
|  |                 test_light_address = test_light_start; | |||
|  | 
 | |||
|  |                 if ((test_elelab_start > test_elelab_stop) || (test_elelab_stop > 999))//vy dhwu 141107 | |||
|  |                 { | |||
|  |                     MessageBox.Show("输入的结束ID必须大于等于起始ID,且小于999"); | |||
|  |                     SendMode = 0; | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     SendData.order = 0; | |||
|  |                     sendUpdateData.order = 0; | |||
|  |                     addLog("开始升级标签"); | |||
|  |                     //复位,并建立连接,单播 | |||
|  |                     for (i = test_elelab_start; i <= test_elelab_stop; i++) | |||
|  |                     { | |||
|  |                         SendData.ele_id = i; | |||
|  |                         SendData.state = 0; | |||
|  |                         aa.write_reset_device(SendData); | |||
|  |                         System.Threading.Thread.Sleep(150); | |||
|  | 
 | |||
|  |                         sendUpdateData.ele_id = i; | |||
|  |                         sendUpdateData.state = 1; | |||
|  |                         if (aa.write_update_command(sendUpdateData, BOOTLDR_CONNECT) == false) | |||
|  |                         { | |||
|  |                             System.Threading.Thread.Sleep(10); | |||
|  |                             if (aa.write_update_command(sendUpdateData, BOOTLDR_CONNECT) == false) | |||
|  |                             { | |||
|  |                                 addLog("标签" + i.ToString() + "建立连接失败"); | |||
|  |                             } | |||
|  |                         } | |||
|  |                         System.Threading.Thread.Sleep(10); | |||
|  |                     } | |||
|  | 
 | |||
|  |                     packageNoHex = Length / 128; | |||
|  |                     if ((Length % 128) > 0) packageNoHex += 1; | |||
|  |                     for (j = 0; j < Length; j += 128) | |||
|  |                     { | |||
|  |                         //发送数据,广播 | |||
|  |                         sendUpdateData.ele_id = 0xffff; | |||
|  |                         sendUpdateData.state = 0; | |||
|  |                         tempbuf[5] = packageNo++; | |||
|  |                         for (i = 0; i < 128; i++) | |||
|  |                         { | |||
|  |                             tempbuf[i + 6] = szBin[j + i]; | |||
|  |                             verify += szBin[j + i]; | |||
|  |                         } | |||
|  |                         if (aa.write_update_data(sendUpdateData, BOOTLDR_SEND_FLASH, tempbuf, tempbuf.Length) == false) | |||
|  |                         { | |||
|  |                             addLog("数据包" + packageNo.ToString() + "发控制器数据失败"); | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             addLog("数据包" + packageNo.ToString() + "/" + packageNoHex.ToString()); | |||
|  |                             Application.DoEvents(); | |||
|  |                         } | |||
|  |                         //读取一包状态,单播 | |||
|  |                         for (i = test_elelab_start; i <= test_elelab_stop; i++) | |||
|  |                         { | |||
|  |                             sendUpdateData.ele_id = i; | |||
|  |                             sendUpdateData.state = 1; | |||
|  |                             if ((aa.write_update_command(sendUpdateData, BOOTLDR_GET_STATE) == false) || (aa.command_test_buf[7] != packageNo)) | |||
|  |                             { | |||
|  |                                 addLog("标签" + i.ToString() + "接收数据包" + packageNo.ToString() + "失败"); | |||
|  |                             } | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |             if (chklbeep.Checked)//update eeprom | |||
|  |             { | |||
|  |                 String szEep = ""; | |||
|  | 
 | |||
|  |                 //读取eep文件 | |||
|  |                 StreamReader EepReader = new StreamReader(szEepPath, Encoding.Default); | |||
|  | 
 | |||
|  |                 while (true) | |||
|  |                 { | |||
|  |                     szLine = EepReader.ReadLine(); //读取一行数据 | |||
|  | 
 | |||
|  |                     if (szLine == null) //读完所有行 | |||
|  |                     { | |||
|  |                         break; | |||
|  |                     } | |||
|  |                     if (szLine.Substring(0, 1) == ":") //判断第1字符是否是: | |||
|  |                     { | |||
|  | 
 | |||
|  |                         if (szLine.Substring(1, 8) == "00000001")//数据结束 | |||
|  |                         { | |||
|  |                             break; | |||
|  |                         } | |||
|  |                         szEep += szLine.Substring(9, szLine.Length - 11); //读取有效字符 | |||
|  |                     } | |||
|  | 
 | |||
|  |                 } | |||
|  |                 EepReader.Close(); //关闭目标文件 | |||
|  |                 j = 0; | |||
|  |                 int LengthEep = szEep.Length; | |||
|  |                 byte[] szBinEep = new byte[LengthEep]; | |||
|  |                 for (i = 0; i < LengthEep; i += 2) //两字符合并成一个16进制字节 | |||
|  |                 { | |||
|  |                     szBinEep[j] = (byte)Int16.Parse(szEep.Substring(i, 2), NumberStyles.HexNumber); | |||
|  |                     j++; | |||
|  |                 } | |||
|  |                 j = 0; | |||
|  |                 LengthEep /= 2; | |||
|  |                 int len; | |||
|  |                 int packageNoEep; | |||
|  |                 packageNoEep = LengthEep / 128; | |||
|  |                 if ((LengthEep % 128) > 0) packageNoEep += 1; | |||
|  |                 do | |||
|  |                 { | |||
|  |                     //发送数据,广播 | |||
|  |                     sendUpdateData.ele_id = 0xffff; | |||
|  |                     sendUpdateData.state = 0; | |||
|  |                     tempbuf[5] = packageNo++; ; | |||
|  |                     if ((j + 128) < LengthEep) | |||
|  |                     { | |||
|  |                         for (i = 0; i < 128; i++) | |||
|  |                         { | |||
|  |                             tempbuf[i + 6] = szBinEep[j + i]; | |||
|  |                             verify += szBinEep[j + i]; | |||
|  |                         } | |||
|  |                         j += 128; | |||
|  |                         len = 128 + 7; | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         for (i = 0; i < (LengthEep - j); i++) | |||
|  |                         { | |||
|  |                             tempbuf[i + 6] = szBinEep[j + i]; | |||
|  |                             verify += szBinEep[j + i]; | |||
|  |                         } | |||
|  |                         len = LengthEep - j + 7; | |||
|  |                         j = LengthEep; | |||
|  |                     } | |||
|  |                     if (aa.write_update_data(sendUpdateData, BOOTLDR_SEND_EEPROM, tempbuf, len) == false) | |||
|  |                     { | |||
|  |                         addLog("数据包" + packageNo.ToString() + "发控制器E数据失败"); | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         addLog("数据包" + (packageNo - packageNoHex).ToString() + "/" + packageNoEep.ToString()); | |||
|  |                         Application.DoEvents(); | |||
|  |                     } | |||
|  |                     //读取一包状态,单播 | |||
|  |                     System.Threading.Thread.Sleep(300); | |||
|  |                     for (i = test_elelab_start; i <= test_elelab_stop; i++) | |||
|  |                     { | |||
|  |                         sendUpdateData.ele_id = i; | |||
|  |                         sendUpdateData.state = 1; | |||
|  |                         if ((aa.write_update_command(sendUpdateData, BOOTLDR_GET_STATE) == false) || (aa.command_test_buf[7] != packageNo)) | |||
|  |                         { | |||
|  |                             addLog("标签" + i.ToString() + "接收E数据包" + packageNo.ToString() + "失败"); | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } while (j < LengthEep); | |||
|  |             } | |||
|  |             //发送完成,读取状态,单播 | |||
|  |             for (i = test_elelab_start; i <= test_elelab_stop; i++) | |||
|  |             { | |||
|  |                 sendUpdateData.ele_id = i; | |||
|  |                 sendUpdateData.state = 1; | |||
|  |                 sendUpdateData.verify = verify; | |||
|  |                 if ((aa.write_update_complete(sendUpdateData, BOOTLDR_COMPLETE) == false) || (aa.command_test_buf[7] != packageNo)) | |||
|  |                 { | |||
|  |                     addLog("标签" + i.ToString() + "升级失败"); | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     addLog("标签" + i.ToString() + "升级成功"); | |||
|  |                 } | |||
|  | 
 | |||
|  |             } | |||
|  | 
 | |||
|  |             szBinPath = ""; | |||
|  |             szEepPath = ""; | |||
|  |         } | |||
|  | 
 | |||
|  |         private void simpleButton18_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             OpenFileDialog fileDialog = new OpenFileDialog(); | |||
|  |             fileDialog.Multiselect = true; | |||
|  |             fileDialog.Title = "请选择文件"; | |||
|  |             fileDialog.Filter = "所有文件(*.bin)|*.bin"; | |||
|  |             if (fileDialog.ShowDialog() == DialogResult.OK) | |||
|  |             { | |||
|  |                 szBinPath = fileDialog.FileName; | |||
|  |                 addLog(string.Format("打开bin文件 {0}", szBinPath)); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         private void btnEep_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             OpenFileDialog fileDialog = new OpenFileDialog(); | |||
|  |             fileDialog.Multiselect = true; | |||
|  |             fileDialog.Title = "请选择文件"; | |||
|  |             fileDialog.Filter = "所有文件(*.eep)|*.eep"; | |||
|  |             if (fileDialog.ShowDialog() == DialogResult.OK) | |||
|  |             { | |||
|  |                 szEepPath = fileDialog.FileName; | |||
|  |                 addLog(string.Format("打开eep文件 {0}", szEepPath)); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         private void btnUpdateChannel_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             int i; | |||
|  |             int j = 0; | |||
|  |             byte[] tempbuf = new byte[128 + 7]; | |||
|  |             ushort verify = 0; | |||
|  |             byte packageNo = 0; | |||
|  |             int packageNoHex = 0; | |||
|  |             String szLine = ""; | |||
|  |             String szHex = ""; | |||
|  | 
 | |||
|  |             if (szHexPath == "") | |||
|  |             { | |||
|  |                 MessageBox.Show("请选择需要转换的hex文件!         ", "错误"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             if (this.chklighteep.Checked)//update eeprom | |||
|  |             { | |||
|  |                 if (szEepPath == "") | |||
|  |                 { | |||
|  |                     MessageBox.Show("请选择需要转换的eep文件!         ", "错误"); | |||
|  |                     return; | |||
|  |                 } | |||
|  |             } | |||
|  |             //读取bin文件 | |||
|  |             using (FileStream fsbin = File.OpenRead(szHexPath)) | |||
|  |             { | |||
|  |                 int Length = (int)fsbin.Length; | |||
|  |                 byte[] szBin = new byte[Length + 128]; | |||
|  |                 while (fsbin.Read(szBin, 0, szBin.Length) > 0) | |||
|  |                 { | |||
|  |                     ; | |||
|  |                 } | |||
|  |                 fsbin.Close(); //关闭目标文件 | |||
|  |                 for (i = 0; i < szBin.Length; i += 3) | |||
|  |                 { | |||
|  |                     szBin[i] = (byte)(szBin[i] ^ 0x5a); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 try | |||
|  |                 { | |||
|  |                     test_light_start = Convert.ToInt16(this.txtChID31.Text); | |||
|  |                     test_light_stop = Convert.ToInt16(txtChID31.Text); | |||
|  |                 } | |||
|  |                 catch | |||
|  |                 { | |||
|  |                     MessageBox.Show("输入的地址错误"); | |||
|  |                     SendMode = 0; | |||
|  |                     return; | |||
|  |                 } | |||
|  | 
 | |||
|  | 
 | |||
|  |                 test_elelab_address = test_elelab_start; | |||
|  |                 test_light_address = test_light_start; | |||
|  | 
 | |||
|  |                 if ((test_light_start > test_light_stop) || (test_light_start < 5000) || (test_light_stop > MAX_LIGHT_NUM)) | |||
|  |                 { | |||
|  |                     MessageBox.Show("输入的结束ID必须大于等于起始ID,且必须在5000到5100之间"); | |||
|  |                     SendMode = 0; | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     SendData.order = 0; | |||
|  |                     sendUpdateData.order = 0; | |||
|  |                     addLog("开始升级通道灯"); | |||
|  |                     //复位,并建立连接,单播 | |||
|  |                     for (i = test_light_start; i <= test_light_stop; i++) | |||
|  |                     { | |||
|  |                         SendData.ele_id = i; | |||
|  |                         SendData.state = 0; | |||
|  |                         aa.write_reset_device(SendData); | |||
|  |                         System.Threading.Thread.Sleep(150); | |||
|  | 
 | |||
|  |                         sendUpdateData.ele_id = i; | |||
|  |                         sendUpdateData.state = 1; | |||
|  |                         if (aa.write_update_command(sendUpdateData, BOOTLDR_CONNECT) == false) | |||
|  |                         { | |||
|  |                             System.Threading.Thread.Sleep(10); | |||
|  |                             if (aa.write_update_command(sendUpdateData, BOOTLDR_CONNECT) == false) | |||
|  |                             { | |||
|  |                                 addLog("通道灯" + i.ToString() + "建立连接失败"); | |||
|  |                             } | |||
|  |                         } | |||
|  |                         System.Threading.Thread.Sleep(10); | |||
|  |                     } | |||
|  |                     packageNoHex = Length / 128; | |||
|  |                     if ((Length % 128) > 0) packageNoHex += 1; | |||
|  |                     for (j = 0; j < Length; j += 128) | |||
|  |                     { | |||
|  |                         //发送数据,广播 | |||
|  |                         sendUpdateData.ele_id = 0xffff; | |||
|  |                         sendUpdateData.state = 0; | |||
|  |                         tempbuf[5] = packageNo++; | |||
|  |                         for (i = 0; i < 128; i++) | |||
|  |                         { | |||
|  |                             tempbuf[i + 6] = szBin[j + i]; | |||
|  |                             verify += szBin[j + i]; | |||
|  |                         } | |||
|  |                         if (aa.write_update_data(sendUpdateData, BOOTLDR_SEND_FLASH, tempbuf, tempbuf.Length) == false) | |||
|  |                         { | |||
|  |                             addLog("数据包" + packageNo.ToString() + "发控制器数据失败"); | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             addLog("数据包" + packageNo.ToString() + "/" + packageNoHex.ToString()); | |||
|  |                             Application.DoEvents(); | |||
|  |                         } | |||
|  |                         //读取一包状态,单播 | |||
|  |                         for (i = test_light_start; i <= test_light_stop; i++) | |||
|  |                         { | |||
|  |                             sendUpdateData.ele_id = i; | |||
|  |                             sendUpdateData.state = 1; | |||
|  |                             if ((aa.write_update_command(sendUpdateData, BOOTLDR_GET_STATE) == false) || (aa.command_test_buf[7] != packageNo)) | |||
|  |                             { | |||
|  |                                 addLog("通道灯" + i.ToString() + "接收数据包" + packageNo.ToString() + "失败"); | |||
|  |                             } | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |             if (chklighteep.Checked)//update eeprom | |||
|  |             { | |||
|  |                 String szEep = ""; | |||
|  | 
 | |||
|  |                 //读取eep文件 | |||
|  |                 StreamReader EepReader = new StreamReader(szEepPath, Encoding.Default); | |||
|  | 
 | |||
|  |                 while (true) | |||
|  |                 { | |||
|  |                     szLine = EepReader.ReadLine(); //读取一行数据 | |||
|  | 
 | |||
|  |                     if (szLine == null) //读完所有行 | |||
|  |                     { | |||
|  |                         break; | |||
|  |                     } | |||
|  |                     if (szLine.Substring(0, 1) == ":") //判断第1字符是否是: | |||
|  |                     { | |||
|  | 
 | |||
|  |                         if (szLine.Substring(1, 8) == "00000001")//数据结束 | |||
|  |                         { | |||
|  |                             break; | |||
|  |                         } | |||
|  |                         szEep += szLine.Substring(9, szLine.Length - 11); //读取有效字符 | |||
|  |                     } | |||
|  | 
 | |||
|  |                 } | |||
|  |                 EepReader.Close(); //关闭目标文件 | |||
|  |                 j = 0; | |||
|  |                 int LengthEep = szEep.Length; | |||
|  |                 byte[] szBinEep = new byte[LengthEep]; | |||
|  |                 for (i = 0; i < LengthEep; i += 2) //两字符合并成一个16进制字节 | |||
|  |                 { | |||
|  |                     szBinEep[j] = (byte)Int16.Parse(szEep.Substring(i, 2), NumberStyles.HexNumber); | |||
|  |                     j++; | |||
|  |                 } | |||
|  |                 j = 0; | |||
|  |                 LengthEep /= 2; | |||
|  |                 int len; | |||
|  |                 int packageNoEep; | |||
|  |                 packageNoEep = LengthEep / 128; | |||
|  |                 if ((LengthEep % 128) > 0) packageNoEep += 1; | |||
|  |                 do | |||
|  |                 { | |||
|  |                     //发送数据,广播 | |||
|  |                     sendUpdateData.ele_id = 0xffff; | |||
|  |                     sendUpdateData.state = 0; | |||
|  |                     tempbuf[5] = packageNo++; ; | |||
|  |                     if ((j + 128) < LengthEep) | |||
|  |                     { | |||
|  |                         for (i = 0; i < 128; i++) | |||
|  |                         { | |||
|  |                             tempbuf[i + 6] = szBinEep[j + i]; | |||
|  |                             verify += szBinEep[j + i]; | |||
|  |                         } | |||
|  |                         j += 128; | |||
|  |                         len = 128 + 7; | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         for (i = 0; i < (LengthEep - j); i++) | |||
|  |                         { | |||
|  |                             tempbuf[i + 6] = szBinEep[j + i]; | |||
|  |                             verify += szBinEep[j + i]; | |||
|  |                         } | |||
|  |                         len = LengthEep - j + 7; | |||
|  |                         j = LengthEep; | |||
|  |                     } | |||
|  |                     if (aa.write_update_data(sendUpdateData, BOOTLDR_SEND_EEPROM, tempbuf, len) == false) | |||
|  |                     { | |||
|  |                         addLog("数据包" + packageNo.ToString() + "发控制器E数据失败"); | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         addLog("数据包" + (packageNo - packageNoHex).ToString() + "/" + packageNoEep.ToString()); | |||
|  |                         Application.DoEvents(); | |||
|  |                     } | |||
|  |                     //读取一包状态,单播 | |||
|  |                     System.Threading.Thread.Sleep(300); | |||
|  |                     for (i = test_light_start; i <= test_light_stop; i++) | |||
|  |                     { | |||
|  |                         sendUpdateData.ele_id = i; | |||
|  |                         sendUpdateData.state = 1; | |||
|  |                         if ((aa.write_update_command(sendUpdateData, BOOTLDR_GET_STATE) == false) || (aa.command_test_buf[7] != packageNo)) | |||
|  |                         { | |||
|  |                             addLog("通道灯" + i.ToString() + "接收E数据包" + packageNo.ToString() + "失败"); | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } while (j < LengthEep); | |||
|  |             } | |||
|  |             //发送完成,读取状态,单播 | |||
|  |             for (i = test_light_start; i <= test_light_stop; i++) | |||
|  |             { | |||
|  |                 sendUpdateData.ele_id = i; | |||
|  |                 sendUpdateData.state = 1; | |||
|  |                 sendUpdateData.verify = verify; | |||
|  |                 if ((aa.write_update_complete(sendUpdateData, BOOTLDR_COMPLETE) == false) || (aa.command_test_buf[7] != packageNo)) | |||
|  |                 { | |||
|  |                     addLog("通道灯" + i.ToString() + "升级失败"); | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     addLog("通道灯" + i.ToString() + "升级成功"); | |||
|  |                 } | |||
|  | 
 | |||
|  |             }//for | |||
|  | 
 | |||
|  |             szBinPath = ""; | |||
|  |             szEepPath = ""; | |||
|  |         } | |||
|  | 
 | |||
|  |         private void btnUpDateControl_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             int i; | |||
|  | 
 | |||
|  |             if (szHexPath == "") | |||
|  |             { | |||
|  |                 MessageBox.Show("请选择需要转换的bin文件!         ", "错误"); | |||
|  |                 return; | |||
|  |             } | |||
|  |             //读取bin文件 | |||
|  |             using (FileStream fsbin = File.OpenRead(szHexPath)) | |||
|  |             { | |||
|  |                 int Length = (int)fsbin.Length; | |||
|  |                 byte[] szBin = new byte[Length + 128]; | |||
|  |                 while (fsbin.Read(szBin, 0, szBin.Length) > 0) | |||
|  |                 { | |||
|  |                     ; | |||
|  |                 } | |||
|  |                 fsbin.Close(); //关闭目标文件 | |||
|  |                 for (i = 0; i < szBin.Length; i += 3) | |||
|  |                 { | |||
|  |                     szBin[i] = (byte)(szBin[i] ^ 0x5a); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (SendMode == 0) | |||
|  |                 { | |||
|  |                     SendData.order = 0; | |||
|  |                     sendUpdateData.order = 0; | |||
|  |                     addLog("开始升级控制器"); | |||
|  |                     //复位,并建立连接,单播 | |||
|  |                     SendData.ele_id = 0; | |||
|  |                     SendData.state = 0; | |||
|  |                     aa.write_reset_device(SendData); | |||
|  |                     System.Threading.Thread.Sleep(100); | |||
|  | 
 | |||
|  |                     sendUpdateData.ele_id = 0; | |||
|  |                     sendUpdateData.state = 1; | |||
|  |                     if (aa.write_update_command(sendUpdateData, BOOTLDR_CONNECT) == false) | |||
|  |                     { | |||
|  |                         addLog("控制器" + "建立连接失败"); | |||
|  |                     } | |||
|  |                     int j = 0; | |||
|  |                     byte[] tempbuf = new byte[128 + 7]; | |||
|  |                     ushort verify = 0; | |||
|  |                     byte packageNo = 0; | |||
|  |                     int packageNoHex = Length / 128; | |||
|  |                     if ((Length % 128) > 0) packageNoHex += 1; | |||
|  |                     for (j = 0; j < Length; j += 128) | |||
|  |                     { | |||
|  |                         //发送数据,广播 | |||
|  |                         sendUpdateData.ele_id = 0; | |||
|  |                         sendUpdateData.state = 0; | |||
|  |                         tempbuf[5] = packageNo++; | |||
|  |                         for (i = 0; i < 128; i++) | |||
|  |                         { | |||
|  |                             tempbuf[i + 6] = szBin[j + i]; | |||
|  |                             verify += szBin[j + i]; | |||
|  |                         } | |||
|  |                         if (aa.write_updatekzq_data(sendUpdateData, BOOTLDR_SEND_FLASH, tempbuf, tempbuf.Length) == false) | |||
|  |                         { | |||
|  |                             addLog("数据包" + packageNo.ToString() + "发控制器数据失败"); | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             addLog("数据包" + packageNo.ToString() + "/" + packageNoHex.ToString()); | |||
|  |                             Application.DoEvents(); | |||
|  |                         } | |||
|  |                         System.Threading.Thread.Sleep(100); | |||
|  |                         //读取一包状态,单播 | |||
|  |                         sendUpdateData.ele_id = 0; | |||
|  |                         sendUpdateData.state = 1; | |||
|  |                         if ((aa.write_update_command(sendUpdateData, BOOTLDR_GET_STATE) == false) || (aa.command_test_buf[7] != packageNo)) | |||
|  |                         { | |||
|  |                             addLog("控制器" + "接收数据包失败"); | |||
|  |                         } | |||
|  |                     } | |||
|  |                     //发送完成,读取状态,单播 | |||
|  |                     sendUpdateData.ele_id = 0; | |||
|  |                     sendUpdateData.state = 1; | |||
|  |                     sendUpdateData.verify = verify; | |||
|  |                     if ((aa.write_update_complete(sendUpdateData, BOOTLDR_COMPLETE) == false) || (aa.command_test_buf[7] != packageNo)) | |||
|  |                     { | |||
|  |                         addLog("控制器" + "升级失败"); | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         addLog("控制器" + "升级成功"); | |||
|  |                     } | |||
|  | 
 | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  |         */ | |||
|  | 
 | |||
|  | 
 | |||
|  |     } | |||
|  | } |