2011 lines
		
	
	
		
			77 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			2011 lines
		
	
	
		
			77 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System;
 | ||
| using System.Collections.Generic;
 | ||
| using System.ComponentModel;
 | ||
| using System.Data;
 | ||
| using System.Drawing;
 | ||
| using System.Text;
 | ||
| using System.Linq;
 | ||
| using System.Windows.Forms;
 | ||
| using DevExpress.XtraBars;
 | ||
| using elelabTest;
 | ||
| //using Model;
 | ||
| using DevExpress.XtraEditors.Controls;
 | ||
| using System.IO;
 | ||
| using System.Globalization;
 | ||
| 
 | ||
| namespace DeiNiu.wms.win
 | ||
| {   
 | ||
|     public partial class EleConfig :   BasicRibbonForm
 | ||
|     {
 | ||
|         public static sjqh aa ;//= new sjqh();
 | ||
| 
 | ||
|         Dictionary<string, sjqh> coms = new Dictionary<string, sjqh>();
 | ||
| 
 | ||
| 
 | ||
|        //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(   elelabTest.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[999];
 | ||
|         int[] light_test_error = new int[999];
 | ||
|         elelabTest.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 = 5100;
 | ||
|         public EleConfig()
 | ||
|         {
 | ||
|             InitializeComponent();
 | ||
|             initComs();
 | ||
|             initialCom();
 | ||
|             meditLogs.ReadOnly = true;
 | ||
|         }
 | ||
| 
 | ||
|         private void btnSeeds_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             byte led_rgb = 2;
 | ||
| 
 | ||
|             
 | ||
|             int elelab_start, elelab_stop, count, num, seedsNum;
 | ||
|             int goods_add_start, goods_add_stop;
 | ||
|             int tmp;
 | ||
|             try
 | ||
|             {
 | ||
|                 elelab_start = Convert.ToInt16(txtlbID1.Text);
 | ||
|                 elelab_stop = Convert.ToInt16(txtlbID2.Text);
 | ||
|                 goods_add_start = Convert.ToInt16(this.txtaddr1.Text);
 | ||
|                 goods_add_stop = Convert.ToInt16(txtaddr2.Text);
 | ||
|                 seedsNum = Convert.ToInt16(this.txtNum.Text);
 | ||
|                 // aa.bcdflag = false;
 | ||
| 
 | ||
|                 if ((elelab_stop < elelab_start) || (goods_add_stop < goods_add_start))
 | ||
|                 {
 | ||
|                     throw new Exception();
 | ||
|                 }
 | ||
|             }
 | ||
|             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 "1":
 | ||
|                     led_rgb = 7;
 | ||
|                     break;
 | ||
|                 case "2":
 | ||
|                     led_rgb = 8;
 | ||
|                     break;
 | ||
|                 case "3":
 | ||
|                     led_rgb = 9;
 | ||
|                     break;
 | ||
|                 case "4":
 | ||
|                     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;
 | ||
|             }
 | ||
| 
 | ||
|             
 | ||
|             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];
 | ||
| 
 | ||
|               uart_dis_data[] comment = new  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].state = 1;  //都为1
 | ||
|                     num++;
 | ||
|                     //comment[i*j].
 | ||
|                 }
 | ||
|             }
 | ||
|             if (chkClearOrder.Checked == true)
 | ||
|             {
 | ||
|                 clear_order ss = new  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 > 5000)
 | ||
|             {
 | ||
|                 this.meditLogs.Text = "";
 | ||
| 
 | ||
|             }
 | ||
|             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))//vy dhwu 141107
 | ||
|                 {
 | ||
|                     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)
 | ||
|         {
 | ||
|          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)
 | ||
|         {
 | ||
|           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;
 | ||
|              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);
 | ||
|                 
 | ||
|                 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;
 | ||
|             dis_id id; 
 | ||
|           
 | ||
|             id.order = 0;
 | ||
|             id.ele_id = devId;
 | ||
|             id.state = 1;
 | ||
|             if ((id.ele_id < 0) || (id.ele_id > 5100))
 | ||
|             {
 | ||
|                 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到5100之间");
 | ||
|                 return;
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 try
 | ||
|                 {
 | ||
|                       temp = Convert.ToInt16(txtChID21.Text);
 | ||
|                     if ((temp > 5100) || (temp < 5000))
 | ||
|                     {
 | ||
|                         MessageBox.Show("通道灯ID必须在5000到5100之间");
 | ||
|                         return;
 | ||
|                     }
 | ||
|                 }
 | ||
|                 catch
 | ||
|                 {
 | ||
|                     MessageBox.Show("通道灯ID必须在5000到5100之间");
 | ||
|                     return;
 | ||
|                 }
 | ||
| 
 | ||
|             }
 | ||
| 
 | ||
|             if (isCloseLight)
 | ||
|             {
 | ||
|                 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
 | ||
| 
 | ||
|             }
 | ||
|             else
 | ||
|             { 
 | ||
|                 open_channel_led id;
 | ||
|                 id.channel_id = temp;
 | ||
|                 //id.config_word = led_rgb;
 | ||
|                 id.state = 1;
 | ||
|                 aa.write_open_channel_led(id);
 | ||
|             }
 | ||
|             
 | ||
|             simpleButton7.Text = isCloseLight ? "显示" : "关闭";
 | ||
|             isCloseLight = !isCloseLight;
 | ||
| 
 | ||
|             //readDevice(temp);
 | ||
|         }
 | ||
| 
 | ||
|         private void simpleButton6_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             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 > 5100) || (temp < 5000))
 | ||
|                 {
 | ||
|                     MessageBox.Show("通道灯ID必须在5000到5100之间");
 | ||
|                     return;
 | ||
|                 }
 | ||
|             }
 | ||
| 
 | ||
|              MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
 | ||
|             DialogResult dr = MessageBox.Show(String.Format("确定要清除绑定吗?"), "清除绑定", messButton);
 | ||
|             if (dr != DialogResult.OK)
 | ||
|             {
 | ||
|                 return;
 | ||
|             }
 | ||
|             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;
 | ||
|             }
 | ||
| 
 | ||
|             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;
 | ||
|             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到5100");
 | ||
|                 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() + "成功");
 | ||
| 
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         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 > 5100) || (temp < 5000))
 | ||
|                 {
 | ||
|                     MessageBox.Show("通道灯ID必须在5000到5100之间");
 | ||
|                     return;
 | ||
|                 }
 | ||
|             }
 | ||
|             config_channel_led id;
 | ||
|             byte led_rgb = 0;
 | ||
|             switch (combChcolor.Text)
 | ||
|             {
 | ||
|                 case "红":
 | ||
|                     led_rgb = 0;
 | ||
|                     break;
 | ||
|                 case "绿":
 | ||
|                     led_rgb = 1;
 | ||
|                     break;
 | ||
|                 case "蓝":
 | ||
|                     led_rgb = 2;
 | ||
|                     break; 
 | ||
|                 default:
 | ||
|                     led_rgb = 0;
 | ||
|                     break;
 | ||
|             }
 | ||
|             id.channel_id = temp;
 | ||
|             id.config_word = led_rgb;
 | ||
|             id.state = 1;
 | ||
|             aa.write_config_channel_led(id);//write_config_channel_led
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|         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 sjqh();
 | ||
|                 if (coms.Keys.Contains(combComs.Text))
 | ||
|                 {
 | ||
|                     aa = coms[combComs.Text];
 | ||
|                     addLog(string.Format(combComs.Text + " 打开{0}", "成功"));
 | ||
|                 }
 | ||
|                 else
 | ||
|                 {
 | ||
|                     aa = new sjqh();
 | ||
|                     ret = aa.init_wms_sys(1, combComs.Text);
 | ||
|                     if (ret)
 | ||
|                     {
 | ||
|                         coms[combComs.Text] = aa;
 | ||
|                         aa.check_state = true;
 | ||
|                         aa.on_dis_event += new sjqh.receive_dis_data(receive_dis_data);
 | ||
| 
 | ||
|                         aa.on_send_dis_result_event += new sjqh.send_dis_data_result(receive_dis_data_result);
 | ||
|                         aa.on_close_channel += new sjqh.close_channel(aa_on_close_channel);
 | ||
|                         aa.on_config_channel += new sjqh.config_channel(aa_on_config_channel);
 | ||
|                         aa.on_open_channel += new sjqh.open_channel(aa_on_open_channel);
 | ||
| 
 | ||
|                         timer1.Enabled = true;//设置为true开始计时            
 | ||
|                         timer1.Interval = 50;//设置timer1的执行周期为50毫秒
 | ||
|                     }
 | ||
|                     addLog(string.Format(combComs.Text + "打开{0}", ret ? "成功" : "失败"));
 | ||
|                 }
 | ||
| 
 | ||
|             }
 | ||
|             catch
 | ||
|             {
 | ||
|             }
 | ||
| 
 | ||
|            
 | ||
|             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 simpleButton2_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             initialCom();
 | ||
|         }
 | ||
|         void aa_on_open_channel( open_channel_led data)
 | ||
|         {
 | ||
|             MessageBox.Show("打开通道灯 id = " + data.channel_id.ToString() + " 成功");
 | ||
|             //throw new NotImplementedException();
 | ||
|         }
 | ||
| 
 | ||
|         void aa_on_config_channel( config_channel_led data)
 | ||
|         {
 | ||
|             MessageBox.Show("配置 id = " + data.channel_id.ToString() + "配置字 = " + data.config_word.ToString() + " 成功 ");
 | ||
|             //throw new NotImplementedException();
 | ||
|         }
 | ||
| 
 | ||
|         void aa_on_close_channel( close_channel_led data)
 | ||
|         {
 | ||
|             MessageBox.Show("关闭通道灯 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( 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( 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( 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');
 | ||
|           
 | ||
|                            // meditLogs.Focus();//获取焦
 | ||
|                            // meditLogs.Select(this.meditLogs.TextLength, 0);//光标定位到文本最后
 | ||
|                             meditLogs.ScrollToCaret();//滚动到光标处 
 | ||
|                         }
 | ||
|                         break;
 | ||
|                     }
 | ||
|                 }
 | ||
|             }
 | ||
|             catch
 | ||
|             {
 | ||
|                 MessageBox.Show("异常数据" + data[0].ele_id.ToString());
 | ||
| 
 | ||
|             }
 | ||
| 
 | ||
|         }
 | ||
|         private void receive_dis_data1( 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 = "数据发送成功,开始播种";
 | ||
|                     meditLogs.Text = meditLogs.Text + "数据发送成功" + "\r\n";
 | ||
|                 }
 | ||
|                 else if (aa.command_bz_ack == 4)
 | ||
|                 {
 | ||
|                     aa.command_bz_ack = 0;
 | ||
|                     lbstate.Text = "数据部分发送成功,开始播种";
 | ||
|                     meditLogs.Text = meditLogs.Text + "数据部分发送成功" + "\r\n";
 | ||
|                     MessageBox.Show("数据部分发送成功", "title", MessageBoxButtons.OK, MessageBoxIcon.Error);
 | ||
|                 }
 | ||
|                 else if (aa.command_bz_ack == 5) lbstate.Text = "数据发送失败,开始播种";
 | ||
|                 else if (aa.command_bz_ack == 6)
 | ||
|                 {
 | ||
|                     aa.command_bz_ack = 0;
 | ||
|                     lbstate.Text = "播种完毕";
 | ||
|                     meditLogs.Text = meditLogs.Text + "播种完毕" + "\r\n";
 | ||
|                     if (test_count != count_bz)
 | ||
|                         MessageBox.Show("播种丢包", "title", MessageBoxButtons.OK, MessageBoxIcon.Error);
 | ||
|                 }
 | ||
|                 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);
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         // update driver
 | ||
|         //升级标签程序
 | ||
|         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("控制器" + "升级成功");
 | ||
|                     }
 | ||
| 
 | ||
|                 }
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|       
 | ||
| 
 | ||
| 
 | ||
|     }
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
| /*
 | ||
|     class model
 | ||
|     {
 | ||
|         public struct uart_dis_data
 | ||
|         {
 | ||
|             public byte order;         //货单号
 | ||
|             public byte dis_type;     //显示类型
 | ||
|             public byte state;       //1 2  3  4   5
 | ||
|             public string port;       //端口
 | ||
|             public int ele_id;        //电子标签id
 | ||
|             public byte little_ele_id;  //货物地址
 | ||
|             public int send_count;     //发送数量
 | ||
|             public int receive_count;  //收到的数量
 | ||
|             public byte little_ele_idH1;  //货物地址
 | ||
|             public byte little_ele_idH2;  //货物地址
 | ||
|             public bool bcdflag;
 | ||
|         }
 | ||
|     
 | ||
| 
 | ||
|         public struct config_led_bell
 | ||
|         {
 | ||
|             public byte order;          //单号
 | ||
|             public int ele_id;        //电子标签id
 | ||
|             public byte num;          //配置编号
 | ||
| 
 | ||
|             public byte red_on;         //红灯点亮的时间
 | ||
|             public byte red_off;     //红灯关闭的时间
 | ||
|             public byte red_cycle;       //红灯执行的周期数  0  红灯操作无效  255 红灯周期无穷大
 | ||
|             public byte green_on;        //绿灯点亮的时间
 | ||
|             public byte green_off;    //绿灯关闭的时间
 | ||
|             public byte green_cycle;    //绿灯执行的周期数  0  绿灯操作无效  255 绿灯周期无穷大
 | ||
|             public byte blue_on;         //兰灯点亮的时间
 | ||
|             public byte blue_off;     //兰灯关闭的时间
 | ||
|             public byte blue_cycle;       //兰灯执行的周期数  0  兰灯操作无效  255 兰灯周期无穷大
 | ||
| 
 | ||
|             public byte speak_on;        //蜂鸣器开的时间
 | ||
|             public byte speak_off;      //蜂鸣器关闭的时间
 | ||
|             public byte speak_cycle;      //蜂鸣器执行的周期数  0  蜂鸣器操作无效  255 蜂鸣器周期无穷大
 | ||
|             public byte state;  //装态保留 设为1
 | ||
|         }
 | ||
|         public struct modify_id
 | ||
|         {
 | ||
|             public byte order;        //货单号
 | ||
|             public int new_ele_id;        //修改后的电子标签id
 | ||
|             public int old_ele_id;     //修改前的电子标签id
 | ||
|             public byte state;         //装态保留 设为1
 | ||
|         }
 | ||
|         public struct config_channel_led
 | ||
|         {
 | ||
|             //           public byte order;        //货单号
 | ||
|             public int channel_id;        //修改后的电子标签id
 | ||
|             public byte config_word;     //修改前的电子标签id
 | ||
|             public byte state;         //装态保留 设为1
 | ||
|         }
 | ||
|         public struct close_channel_led
 | ||
|         {
 | ||
|             //           public byte order;        //货单号
 | ||
|             public int channel_id;        //修改后的电子标签id
 | ||
|             //           public int old_ele_id;     //修改前的电子标签id
 | ||
|             public byte state;         //装态保留 设为1
 | ||
|         }
 | ||
|         public struct open_channel_led
 | ||
|         {
 | ||
|             //           public byte order;        //货单号
 | ||
|             public int channel_id;        //修改后的电子标签id
 | ||
|             //           public int old_ele_id;     //修改前的电子标签id
 | ||
|             public byte state;         //装态保留 设为1
 | ||
|         }
 | ||
|         public struct dis_id
 | ||
|         {
 | ||
|             public byte order;        //修改后的电子标签id
 | ||
|             public int ele_id;        //电子标签id
 | ||
|             public byte state;
 | ||
|         }
 | ||
|         public struct clear_comment
 | ||
|         {
 | ||
|             public byte order;        //货单号
 | ||
|             public int ele_id;        //电子标签id
 | ||
|             public byte state;     //装态保留 设为1
 | ||
|         }
 | ||
|         //public struct channel_lab
 | ||
|         //{
 | ||
|         //    public byte order;         //货单号
 | ||
|         //    public byte dis_type;     //显示类型
 | ||
|         //    public byte state;       //1 2  3  4   5
 | ||
|         //    public string port;       //端口
 | ||
|         //    public int ele_id;        //电子标签id
 | ||
|         //    public byte little_ele_id;  //货物地址
 | ||
|         //    public int send_count;     //发送数量
 | ||
|         //    public int receive_count;  //收到的数量
 | ||
|         //}
 | ||
|         public struct key_config
 | ||
|         {
 | ||
|             public byte order;        //货单号
 | ||
|             public int ele_id;        //电子标签id            
 | ||
|             public byte fn_key;          //翻页键   1 开启   0  关闭 
 | ||
|             public byte confirm_key;     //完成健   1 开启   0  关闭
 | ||
|             public byte modify_key;      //修改建   1 开启   0  关闭
 | ||
|             public byte state;            //装态保留 设为1
 | ||
| 
 | ||
|         }
 | ||
|         public struct clear_order
 | ||
|         {
 | ||
|             public byte order;        //货单号
 | ||
|             //        public int ele_id;        //电子标签id
 | ||
|             public byte state;     //装态保留 设为1
 | ||
|         }
 | ||
| 
 | ||
|         
 | ||
|     }
 | ||
| 
 | ||
|     */
 | ||
| } |