| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  | using System; | 
					
						
							|  |  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  |  | using System.Linq; | 
					
						
							|  |  |  |  | using System.Text; | 
					
						
							|  |  |  |  | using System.Threading; | 
					
						
							|  |  |  |  | using System.Data; | 
					
						
							|  |  |  |  | using System.Windows.Forms; | 
					
						
							|  |  |  |  | using Model; | 
					
						
							|  |  |  |  | using DeiNiu.wms.Data; | 
					
						
							|  |  |  |  | using DeiNiu.wms.Data.Model; | 
					
						
							|  |  |  |  | using DeiNiu.Utils; | 
					
						
							|  |  |  |  | //using DeiNiu.wms.Logical; | 
					
						
							|  |  |  |  | using DeiNiu.wms.win.ServiceReferenceStockOutPickRequest; | 
					
						
							|  |  |  |  | using DeiNiu.wms.win; | 
					
						
							|  |  |  |  | using System.Speech.Synthesis; | 
					
						
							|  |  |  |  | namespace Deiniu.win.elelab | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     internal class lightSeeds | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         internal static Thread pick_work; | 
					
						
							|  |  |  |  |         internal static Thread pick_work_support; | 
					
						
							|  |  |  |  |         //internal static Timer check_time;  | 
					
						
							|  |  |  |  |         //internal static uart_dis_data[] ele_return_data = new uart_dis_data[10000]; | 
					
						
							|  |  |  |  |         //internal static int ele_return_receive_address = 0; | 
					
						
							|  |  |  |  |         //internal static int ele_return_manage_address = 0; | 
					
						
							|  |  |  |  |         //internal static int ele_return_max = 10000; | 
					
						
							|  |  |  |  |         public delegate void lightFinish(int eleId); | 
					
						
							|  |  |  |  |         public static event lightFinish lightOffEvent; | 
					
						
							|  |  |  |  |         internal static bool begain_pick = false; | 
					
						
							|  |  |  |  |         //  internal static bool Threads_state; | 
					
						
							|  |  |  |  |         // internal static bool out_start_state; | 
					
						
							|  |  |  |  |         internal static byte[,] ele_lab = new byte[3000, 100];//ele_id address type 0 拣选 1 播种 2 装车 | 
					
						
							|  |  |  |  |         internal static uart_dis_data[] ele_lab_data = new uart_dis_data[10000];//ele_id address type 0 拣选 1 播种 2 装车 | 
					
						
							|  |  |  |  |         internal static int receive_add = 0; | 
					
						
							|  |  |  |  |         internal static int manage_add = 0; | 
					
						
							|  |  |  |  |         internal static int add_max = 10000; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         internal static int[] pick_part_task = new int[100];//分区名称 分区结果 0 没有任务 正在处理任务 | 
					
						
							|  |  |  |  |         internal static int[] seed_part_task = new int[100];//分区名称 分区结果 0 没有任务 正在处理任务 | 
					
						
							|  |  |  |  |         internal static int[] tran_part_task = new int[100];//分区名称 分区结果 0 没有任务 正在处理任务 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |    //     internal static int port_max = 100; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         internal static bool pick_task = true; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         internal static List<int> activeComports = new List<int>() ;//激活的com口 | 
					
						
							|  |  |  |  |         static Dictionary<int, int> partColors = new Dictionary<int, int>(); | 
					
						
							|  |  |  |  |         static Dictionary<int, string> partKeys = new Dictionary<int, string>(); //亮灯的完成器的statuskey | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         private static byte get_byte(string data) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             int length = data.Length; | 
					
						
							|  |  |  |  |             List<string> str = new List<string>(); | 
					
						
							|  |  |  |  |             for (int i = 0; i < length; i++) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 string result = data.Substring(i, 1); | 
					
						
							|  |  |  |  |                 char aaaq = Convert.ToChar(result); | 
					
						
							|  |  |  |  |                 if ((aaaq >= 0x30) && (aaaq <= 0x39)) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     str.Add(data.Substring(i, 1)); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             if (str.Count == 1) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 return Convert.ToByte(str[0]); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             else if (str.Count == 2) | 
					
						
							|  |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                 int len = Convert.ToInt16(str[0]); | 
					
						
							|  |  |  |  |                 int len1 = Convert.ToInt16(str[1]); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                 len = len * 10 + len1; | 
					
						
							|  |  |  |  |                 return Convert.ToByte(len); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             else if (str.Count == 3) | 
					
						
							|  |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                 int len = Convert.ToInt16(str[0]); | 
					
						
							|  |  |  |  |                 int len1 = Convert.ToInt16(str[1]); | 
					
						
							|  |  |  |  |                 int len2 = Convert.ToInt16(str[2]); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |                 len = len * 100 + len1 * 10 + len2; | 
					
						
							|  |  |  |  |                 return Convert.ToByte(len); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             return 0; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         private bool send_data(DataTable[] ds, byte byt) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             for (int j = 0; j < ds.Length; j++) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 //string part = ; | 
					
						
							|  |  |  |  |                 byte part_byte = get_byte(ds[j].Rows[0]["part"].ToString()); | 
					
						
							|  |  |  |  |                 string port = ds[j].Rows[0]["port"].ToString(); | 
					
						
							|  |  |  |  |                 byte port_byte = get_byte(port); | 
					
						
							|  |  |  |  |                 byte led_color = get_byte(ds[j].Rows[0]["color"].ToString()); | 
					
						
							|  |  |  |  |                 elelab.lightSeeds.make_data(ds[j], led_color, part_byte, port_byte, null, null, null, byt); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             return true; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         private static void init_sys_port(enumLabelPickType pickType) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |            // activeComports.Clear(); | 
					
						
							|  |  |  |  |             clear_order order = new clear_order(); | 
					
						
							|  |  |  |  |             int port; | 
					
						
							|  |  |  |  |             for (int i = 0; i < coms.com_count; i++)//init com0-10 | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 int com = Convert.ToByte(i); | 
					
						
							|  |  |  |  |                 if (elelab.coms.initCom(com, true) == true) | 
					
						
							|  |  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                     port = Convert.ToInt16(i); | 
					
						
							|  |  |  |  |                     // order = Convert.ToInt16(dt.Rows[i]["ele_order"]); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                     order.order = Convert.ToByte(i); | 
					
						
							|  |  |  |  |                     order.state =Convert.ToByte((int)pickType); | 
					
						
							|  |  |  |  |                     if (coms.com_manage[port].clear_order(order)) | 
					
						
							|  |  |  |  |                     { | 
					
						
							|  |  |  |  |                         activeComports.Add( port); | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |               | 
					
						
							|  |  |  |  |             init_pick(); | 
					
						
							|  |  |  |  |             // clear_order(dt); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         internal static bool clear_order(DataTable dt) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             int port; | 
					
						
							|  |  |  |  |             clear_order order = new clear_order(); | 
					
						
							|  |  |  |  |             for (int i = 0; i < dt.Rows.Count; i++) | 
					
						
							|  |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                 port = Convert.ToInt16(dt.Rows[i]["port"]); | 
					
						
							|  |  |  |  |                 // order = Convert.ToInt16(dt.Rows[i]["ele_order"]); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                 order.order = Convert.ToByte(dt.Rows[i]["ele_order"]); | 
					
						
							|  |  |  |  |                 order.state = 1; | 
					
						
							|  |  |  |  |                 coms.com_manage[port].clear_order(order); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             return true; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         private static void init_pick() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             //为数据处理开辟线程 | 
					
						
							|  |  |  |  |             // Thread workTicketThread; | 
					
						
							|  |  |  |  |             //Thread workTicketThread; | 
					
						
							|  |  |  |  |             if (pick_work != null) | 
					
						
							|  |  |  |  |                 return; | 
					
						
							|  |  |  |  |             pick_work = new Thread(pick_sys); | 
					
						
							|  |  |  |  |             // Make this a background thread, so it will terminate when the main thread/process is de-activated | 
					
						
							|  |  |  |  |             pick_work.IsBackground = true; | 
					
						
							|  |  |  |  |             //pick_work.SetApartmentState(ApartmentState.STA); | 
					
						
							|  |  |  |  |             pick_work.SetApartmentState(ApartmentState.MTA); | 
					
						
							|  |  |  |  |             // Start the Work | 
					
						
							|  |  |  |  |             pick_work.Start(); | 
					
						
							|  |  |  |  |             //workerThreads[i] = workTicketThread; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         internal static void init_pick_support() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             //为数据处理开辟线程 | 
					
						
							|  |  |  |  |             // Thread workTicketThread; | 
					
						
							|  |  |  |  |             //Thread workTicketThread; | 
					
						
							|  |  |  |  |             pick_work_support = new Thread(pick_sys_support); | 
					
						
							|  |  |  |  |             // Make this a background thread, so it will terminate when the main thread/process is de-activated | 
					
						
							|  |  |  |  |             pick_work_support.IsBackground = true; | 
					
						
							|  |  |  |  |             //pick_work.SetApartmentState(ApartmentState.STA); | 
					
						
							|  |  |  |  |             pick_work_support.SetApartmentState(ApartmentState.MTA); | 
					
						
							|  |  |  |  |             // Start the Work | 
					
						
							|  |  |  |  |             pick_work_support.Start(); | 
					
						
							|  |  |  |  |             //workerThreads[i] = workTicketThread; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         internal static void wake_thread() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |           //  if (Convert.ToInt16(pick_work.ThreadState) == 68) | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |             { | 
					
						
							|  |  |  |  |                 try | 
					
						
							|  |  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                     if (pick_work!=null && Convert.ToInt16(pick_work.ThreadState) == 68) | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                     pick_work.Resume(); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 catch(Exception  er) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     LogHelper.WriteLog(typeof(light), er); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         internal static void wake_support_thread() | 
					
						
							|  |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |             if (Convert.ToInt16(pick_work_support.ThreadState) == 68) | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                 pick_work_support.Resume(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         private static void get_data(string data, out int dot_station, out int total_num) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             data = Convert.ToDouble(data).ToString(); | 
					
						
							|  |  |  |  |             string[] count = data.Split('.');//Out_count | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |             int full = Convert.ToInt16(count[0]); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |             int dot_num; | 
					
						
							|  |  |  |  |             dot_station = 0; | 
					
						
							|  |  |  |  |             total_num = full; | 
					
						
							|  |  |  |  |             if (count.Length > 1) | 
					
						
							|  |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                 dot_num = Convert.ToInt16(count[1]); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                 if (dot_num > 0) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     if (dot_num < 10) | 
					
						
							|  |  |  |  |                     { | 
					
						
							|  |  |  |  |                         total_num = full * 10 + dot_num; | 
					
						
							|  |  |  |  |                         dot_station = 1; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                     else if ((dot_num > 9) && (dot_num < 100)) | 
					
						
							|  |  |  |  |                     { | 
					
						
							|  |  |  |  |                         total_num = full * 100 + dot_num; | 
					
						
							|  |  |  |  |                         dot_station = 2; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                     else if ((dot_num > 99) && (dot_num < 1000)) | 
					
						
							|  |  |  |  |                     { | 
					
						
							|  |  |  |  |                         total_num = full * 1000 + dot_num; | 
					
						
							|  |  |  |  |                         dot_station = 3; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                     else if ((dot_num > 999) && (dot_num < 10000)) | 
					
						
							|  |  |  |  |                     { | 
					
						
							|  |  |  |  |                         total_num = full * 10000 + dot_num; | 
					
						
							|  |  |  |  |                         dot_station = 4; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                     else | 
					
						
							|  |  |  |  |                     { | 
					
						
							|  |  |  |  |                         dot_station = 0; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |          | 
					
						
							|  |  |  |  |         internal static bool make_data(DataTable ds, byte led_color, byte ele_order_id, byte port, | 
					
						
							|  |  |  |  |                      string[] ele_lab_id, string[] ele_address, string[] Out_count, byte type) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             //dt 列名 ele_lab_id  ele_address  Out_count | 
					
						
							|  |  |  |  |             //        电子标签id  控制的层列    数量 | 
					
						
							|  |  |  |  |             //led_color  灯的颜色 0 不亮 1 红灯 2 绿灯 3 蓝灯 4 红闪 5 绿闪 6 蓝闪 7红绿 8 红蓝 9 绿蓝 14红绿蓝 15 红绿蓝蜂鸣器 | 
					
						
							|  |  |  |  |             //ele_order_id  电子标签的订单号(电子标签使用)订单号范围 1-200  每个订单号有多条数据 控制器一次能处理多个订单号 | 
					
						
							|  |  |  |  |             //订单号唯一,一个订单号使用完毕,这个订单号才能被使用 | 
					
						
							|  |  |  |  |             //port 端口号  | 
					
						
							|  |  |  |  |             //DataTable ds = new DataTable(); | 
					
						
							|  |  |  |  |             List<string> statuKeys = new List<string>(); | 
					
						
							|  |  |  |  |             int elid; | 
					
						
							|  |  |  |  |             if (ds != null) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 if (ds.Rows.Count == 0) | 
					
						
							|  |  |  |  |                     return false; | 
					
						
							|  |  |  |  |                 uart_dis_data[] ele_data_comment = new uart_dis_data[ds.Rows.Count]; | 
					
						
							|  |  |  |  |                 for (int j = 0; j < ds.Rows.Count; j++) | 
					
						
							|  |  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                     elid = Convert.ToInt16(ds.Rows[j]["ele_lab_id"].ToString()); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |                     ele_data_comment[j].channel_id = 0;//暂不使用 默认为0 | 
					
						
							|  |  |  |  |                     ele_data_comment[j].dis_type = Convert.ToByte(ds.Rows[j]["color"].ToString()); ;// 灯的颜色 0 不亮 1 红灯 2 绿灯 3 蓝灯 4 红闪 5 绿闪 6 蓝闪  | 
					
						
							|  |  |  |  |                     ele_data_comment[j].ele_id = elid; | 
					
						
							|  |  |  |  |                     ele_data_comment[j].kucun_id = 0; | 
					
						
							|  |  |  |  |                     ele_data_comment[j].little_ele_id = Convert.ToByte(ds.Rows[j]["ele_address"].ToString()); | 
					
						
							|  |  |  |  |                     ele_data_comment[j].order = Convert.ToByte(ele_order_id); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                     ele_data_comment[j].port = "1"; | 
					
						
							|  |  |  |  |                     ele_data_comment[j].receive_count = 0; | 
					
						
							|  |  |  |  |                     int dot_station; | 
					
						
							|  |  |  |  |                     int total_num; | 
					
						
							|  |  |  |  |                     string[] count = ds.Rows[j]["send_count"].ToString().Split('.');//Out_count | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                     get_data(ds.Rows[j]["send_count"].ToString(), out dot_station, out total_num); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                     //total_num = Convert.ToInt16(count[0]); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                     ele_data_comment[j].send_count = total_num;//.ToString()); | 
					
						
							|  |  |  |  |                     ele_data_comment[j].dot = Convert.ToByte(0); | 
					
						
							|  |  |  |  |                     //ele_data_comment[j].dot = 0; | 
					
						
							|  |  |  |  |                     ele_data_comment[j].WarehousingID = 0; | 
					
						
							|  |  |  |  |                     ele_lab[ele_data_comment[j].ele_id, ele_data_comment[j].little_ele_id] = type; | 
					
						
							|  |  |  |  |                      | 
					
						
							|  |  |  |  |                     string key = Util.getLightKey(ele_data_comment[j].dis_type, elid, Convert.ToByte(ds.Rows[j]["ele_address"].ToString())); | 
					
						
							|  |  |  |  |                     statuKeys.Add(key); | 
					
						
							|  |  |  |  |                     | 
					
						
							| 
									
										
										
										
											2024-02-06 19:36:47 +08:00
										 |  |  |  |                     if (WmsConstants.PART_FINISH_LABLE_IDS!=null && WmsConstants.PART_FINISH_LABLE_IDS.Contains(Convert.ToInt16(ds.Rows[j]["ele_lab_id"].ToString()))) | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                     { | 
					
						
							|  |  |  |  |                         partKeys[elid] = key; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                 }// //向串口发送数据 | 
					
						
							|  |  |  |  |                 clear_order order = new clear_order(); | 
					
						
							|  |  |  |  |                 order.order = Convert.ToByte(ele_order_id); | 
					
						
							|  |  |  |  |                 order.state = 1; | 
					
						
							|  |  |  |  |                 if (coms.com_manage[port].clear_order(order) == false) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     LogHelper.WriteLog(typeof(light), string.Format(" port {0} clear fail",port)); | 
					
						
							|  |  |  |  |                     //MessageBox.Show("clear fail"); | 
					
						
							|  |  |  |  |                      return false; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 //elelab.ele_base.usart_send_state = false; //ele .usart_send_state = false; | 
					
						
							|  |  |  |  |                 while (coms.com_manage[port].send_state_finish == false) ; | 
					
						
							|  |  |  |  |                 coms.com_manage[port].send_state_finish = false; | 
					
						
							|  |  |  |  |                 coms.com_manage[port].usart_send_state = false; | 
					
						
							|  |  |  |  |                 coms.com_manage[port].usart_send_result = ""; | 
					
						
							|  |  |  |  |                 if (coms.com_manage[port].write_data(ele_data_comment) == false) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     LogHelper.WriteLog(typeof(light), string.Format(" port {0} send fail", port)); | 
					
						
							|  |  |  |  |                     //MessageBox.Show("send  fail") ; | 
					
						
							|  |  |  |  |                     coms.com_manage[port].send_state_finish = true; | 
					
						
							|  |  |  |  |                     coms.com_manage[port].usart_send_state = true; | 
					
						
							|  |  |  |  |                     coms.com_manage[port].usart_send_result = ""; | 
					
						
							|  |  |  |  |                      return false; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 string result; | 
					
						
							|  |  |  |  |                 bool isLightsSuccess = coms.com_manage[port].wait_ack(out result); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 foreach(string key in statuKeys){ | 
					
						
							|  |  |  |  |                     WmsConstants.WAVE_CURRENT_LIGHTS_STATUS[key] = isLightsSuccess; | 
					
						
							|  |  |  |  |                     WmsConstants.WAVE_CURRENT_PICK_STATUS[key] = false;  | 
					
						
							|  |  |  |  |                 }  | 
					
						
							|  |  |  |  |                 return isLightsSuccess; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             else | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 uart_dis_data[] ele_data_comment = new uart_dis_data[ele_lab_id.Length]; | 
					
						
							|  |  |  |  |                 for (int j = 0; j < ele_lab_id.Length; j++) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     ele_data_comment[j].channel_id = 0;//暂不使用 默认为0 | 
					
						
							|  |  |  |  |                     ele_data_comment[j].dis_type = led_color;// 灯的颜色 0 不亮 1 红灯 2 绿灯 3 蓝灯 4 红闪 5 绿闪 6 蓝闪  | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                     ele_data_comment[j].ele_id = Convert.ToInt16(ele_lab_id[j].ToString()); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                     ele_data_comment[j].kucun_id = 0; | 
					
						
							|  |  |  |  |                     ele_data_comment[j].little_ele_id = Convert.ToByte(ele_address[j].ToString()); | 
					
						
							|  |  |  |  |                     ele_data_comment[j].order = Convert.ToByte(ele_order_id); | 
					
						
							|  |  |  |  |                     ele_data_comment[j].port = "1"; | 
					
						
							|  |  |  |  |                     ele_data_comment[j].receive_count = 0; | 
					
						
							|  |  |  |  |                     string[] count = Out_count[j].ToString().Split('.'); | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                     ele_data_comment[j].send_count = Convert.ToInt16(count[0]);//.ToString()); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                     ele_data_comment[j].state = 1; | 
					
						
							|  |  |  |  |                     ele_data_comment[j].WarehousingID = 0; | 
					
						
							|  |  |  |  |                     ele_lab[ele_data_comment[j].ele_id, ele_data_comment[j].little_ele_id] = type; | 
					
						
							|  |  |  |  |                 }// //向串口发送数据 | 
					
						
							|  |  |  |  |                 clear_order order = new clear_order(); | 
					
						
							|  |  |  |  |                 order.order = Convert.ToByte(ele_order_id); | 
					
						
							|  |  |  |  |                 order.state = 1; | 
					
						
							|  |  |  |  |                 if (coms.com_manage[port].clear_order(order) == false) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     return false; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 if (coms.com_manage[port].write_data(ele_data_comment) == false) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     return false; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 return true; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |           void speak(string msg) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             SpeechSynthesizer voice = new SpeechSynthesizer();   //创建语音实例 | 
					
						
							|  |  |  |  |             voice.Rate = -1; //设置语速,[-10,10] | 
					
						
							|  |  |  |  |             voice.Volume = 100; //设置音量,[0,100] | 
					
						
							|  |  |  |  |             voice.SpeakAsync(msg);  //播放指定的字符串,这是异步朗读 | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |          internal static bool clsDisplay(byte port, byte ele_order_id) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             clear_order order = new clear_order(); | 
					
						
							|  |  |  |  |             order.order = Convert.ToByte(ele_order_id); | 
					
						
							|  |  |  |  |             order.state = 1; | 
					
						
							|  |  |  |  |             return coms.com_manage[port].clear_order(order); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         internal static bool restDevice(byte port) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             //clear_order order = new clear_order(); | 
					
						
							|  |  |  |  |             //order.order = Convert.ToByte(ele_order_id); | 
					
						
							|  |  |  |  |             //order.state = 1; | 
					
						
							|  |  |  |  |             coms.com_manage[port].write_reset_device(); | 
					
						
							|  |  |  |  |             return true; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     | 
					
						
							|  |  |  |  |         private static void read_single(int address) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             while (coms.com_manage[address].manage_address != coms.com_manage[address].receive_address) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 ele_lab_data[receive_add] = coms.com_manage[address].return_data[coms.com_manage[address].manage_address]; | 
					
						
							|  |  |  |  |                 receive_add++; | 
					
						
							|  |  |  |  |                 if (receive_add >= add_max) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     receive_add = 0; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 coms.com_manage[address].manage_address++; | 
					
						
							|  |  |  |  |                 if (coms.com_manage[address].manage_address >= coms.com_manage[address].return_max) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     coms.com_manage[address].manage_address = 0; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         private static void receiveData() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             for (int i = 0; i < coms.com_manage.Length; i++) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 if (coms.com_manage[i] != null) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     if (coms.com_manage[i].wait_data == true) | 
					
						
							|  |  |  |  |                     {//读取数据 | 
					
						
							|  |  |  |  |                         coms.com_manage[i].wait_data = false; | 
					
						
							|  |  |  |  |                         read_single(i); | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         private static string receiveDataDot(int count, int dot_station) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             string result = "0"; | 
					
						
							|  |  |  |  |             if (dot_station == 0) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 result = count.ToString(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             else if (dot_station == 1) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 result = (count / 10).ToString() + "." + (count % 10).ToString(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             else if (dot_station == 2) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 result = (count / 100).ToString() + "." + (count % 100).ToString(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             else if (dot_station == 3) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 result = (count / 1000).ToString() + "." + (count % 1000).ToString(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             return result; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       //  static WmsOutPickLable outPick = new WmsOutPickLable(); | 
					
						
							|  |  |  |  |        // static lWmsOutPickRequest lpickRequest = new lWmsOutPickRequest(); | 
					
						
							|  |  |  |  |        /// <summary> | 
					
						
							|  |  |  |  |        /// send back from elabel | 
					
						
							|  |  |  |  |        /// </summary> | 
					
						
							|  |  |  |  |         internal static void dataSent() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             List<string> statuKeys = new List<string>(); | 
					
						
							|  |  |  |  |           //  string sql, table; | 
					
						
							|  |  |  |  |             int ele_id; | 
					
						
							|  |  |  |  |             int little_ele_id; | 
					
						
							|  |  |  |  |             string receive_count; | 
					
						
							|  |  |  |  |             string color; | 
					
						
							|  |  |  |  |             string eOrder; | 
					
						
							|  |  |  |  |            // WmsOutPickLable outPick = new WmsOutPickLable(); | 
					
						
							|  |  |  |  |            | 
					
						
							|  |  |  |  |             enumLabelPickType pickType =enumLabelPickType.pick; //同一个控制器应该拣选类型唯一 | 
					
						
							|  |  |  |  |           //  int cnt = 0; | 
					
						
							|  |  |  |  |             Dictionary<string, bool> tmp = WmsConstants.WAVE_CURRENT_PICK_STATUS; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             LogHelper.debug(typeof(light),"-----------------------------new data---------------------------"); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             while (receive_add != manage_add) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |               //  cnt++; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |             receive_count = receiveDataDot(Convert.ToInt16(ele_lab_data[manage_add].receive_count), Convert.ToInt16(ele_lab_data[manage_add].dot)); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                 // ele_lab_data[receive_add] | 
					
						
							|  |  |  |  |                 //receive_count = "0"; | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |             ele_id = Convert.ToInt16(ele_lab_data[manage_add].ele_id.ToString()); //label id | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |             color = ele_lab_data[manage_add].dis_type.ToString();//color | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |             little_ele_id = Convert.ToInt16(ele_lab_data[manage_add] .little_ele_id.ToString()); //ele address | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |             eOrder = ele_lab_data[manage_add].order.ToString() ; | 
					
						
							|  |  |  |  |                 int state = elelab.lightSeeds.ele_lab[ele_id, little_ele_id]; | 
					
						
							|  |  |  |  |                 pickType = (enumLabelPickType)state; | 
					
						
							|  |  |  |  |                  | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                 int partion = Convert.ToInt16(eOrder); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |            | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                    string key = Util.getLightKey(Convert.ToInt16(color), ele_id, little_ele_id); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                    LogHelper.debug(typeof(light), string.Format("current key {0}, waveNo {1}", key, WmsConstants.WAVE_CURRENT_ORDER)); | 
					
						
							|  |  |  |  |                    //WmsConstants.WAVE_CURRENT_PICK_STATUS[key] = true; | 
					
						
							|  |  |  |  | //#if debug | 
					
						
							|  |  |  |  |                    //speak(key); | 
					
						
							|  |  |  |  | //#endif | 
					
						
							|  |  |  |  |                    LogHelper.debug(typeof(light), string.Format("receive_add {0}, manage_add {1}", receive_add, manage_add)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |               //   while (receive_add != manage_add) | 
					
						
							|  |  |  |  |           //  { | 
					
						
							|  |  |  |  |                 switch (pickType) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     case enumLabelPickType.pick: | 
					
						
							|  |  |  |  |                            | 
					
						
							|  |  |  |  |                         break; | 
					
						
							|  |  |  |  |                     case enumLabelPickType.seed:  | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                          | 
					
						
							|  |  |  |  |                         if (WmsConstants.SEEDS_CURRENT_PICK_STATUS.ContainsKey(key)) | 
					
						
							|  |  |  |  |                         { | 
					
						
							|  |  |  |  |                             if (WmsConstants.SEEDS_CURRENT_PICK_STATUS[key]) | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 manage_add++; | 
					
						
							|  |  |  |  |                                 if (manage_add >= add_max) | 
					
						
							|  |  |  |  |                                 { | 
					
						
							|  |  |  |  |                                     manage_add = 0; | 
					
						
							|  |  |  |  |                                 } | 
					
						
							|  |  |  |  |                                 continue; | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                         using (WmsOutPickRequestClient client = new WmsOutPickRequestClient("BasicHttpBinding_IWmsOutPickRequest", | 
					
						
							|  |  |  |  |                                                     string.Format("http://{0}/{1}", Park.svrUrl, "WmsOutPickRequestService.svc"))) | 
					
						
							|  |  |  |  |                         { | 
					
						
							|  |  |  |  |                             try | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                               //  WmsConstants.SEEDS_CURRENT_PICK_STATUS[key] = client.updateSeedingStatus(WmsConstants.CURRENT_SEEDS_NO, WmsConstants.CURRENT_SEEDS_GOODSID, WmsConstants.CURRENT_SEEDS_GOOD_BATCH, ele_id, little_ele_id, Convert.ToDecimal(receive_count));//本次拣选完毕 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                               //  client.Close(); | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                             catch (DeiNiuTimeOutException e) | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 Login lg = new Login(); | 
					
						
							|  |  |  |  |                                 lg.ShowDialog(); | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                             catch (Exception e) | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 LogHelper.WriteLog(typeof(light), e); | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                         } | 
					
						
							|  |  |  |  |                           | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                         break; | 
					
						
							|  |  |  |  |                     case enumLabelPickType.tran: | 
					
						
							|  |  |  |  |                         break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                     case enumLabelPickType.seedPick: // 播种分区摘果 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-06 19:36:47 +08:00
										 |  |  |  |                         if (WmsConstants.PART_FINISH_LABLE_IDS!=null && WmsConstants.PART_FINISH_LABLE_IDS.Contains(ele_id))//区域完成键 | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                         { | 
					
						
							|  |  |  |  |                             manage_add++; | 
					
						
							|  |  |  |  |                             if (manage_add >= add_max) | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 manage_add = 0; | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                             WmsConstants.WAVE_CURRENT_PICK_STATUS[key] = true; | 
					
						
							|  |  |  |  |                             if (partKeys[ele_id] != key) | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 return; | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                             /* | 
					
						
							|  |  |  |  |                             if ( (WmsConstants.partStatus.Keys.Contains(ele_id)) && WmsConstants.partStatus[ele_id]) //已点亮 | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 return; | 
					
						
							|  |  |  |  |                             }*/ | 
					
						
							|  |  |  |  |                             lightFinish handler = lightOffEvent; | 
					
						
							|  |  |  |  |                             if (handler != null) | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 // WmsConstants.partStatus[ele_id] = false; | 
					
						
							|  |  |  |  |                                 handler(ele_id); | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                             return; | 
					
						
							|  |  |  |  |                         } | 
					
						
							|  |  |  |  |                         if (WmsConstants.WAVE_CURRENT_PICK_STATUS.ContainsKey(key)) | 
					
						
							|  |  |  |  |                         { | 
					
						
							|  |  |  |  |                             LogHelper.debug(typeof(light), string.Format(" !!!!!!!!!..........{0} exist in pick cache ", key)); | 
					
						
							|  |  |  |  |                             //  | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                             if (WmsConstants.WAVE_CURRENT_PICK_STATUS[key]) | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 manage_add++; | 
					
						
							|  |  |  |  |                                 if (manage_add >= add_max) | 
					
						
							|  |  |  |  |                                 { | 
					
						
							|  |  |  |  |                                     manage_add = 0; | 
					
						
							|  |  |  |  |                                 } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                                 continue; | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                         } | 
					
						
							|  |  |  |  |                         using (WmsOutPickRequestClient client = new WmsOutPickRequestClient("BasicHttpBinding_IWmsOutPickRequest", | 
					
						
							|  |  |  |  |                                                    string.Format("http://{0}/{1}", Park.svrUrl, "WmsOutPickRequestService.svc"))) | 
					
						
							|  |  |  |  |                         { | 
					
						
							|  |  |  |  |                             LogHelper.debug(typeof(light), string.Format(" ..........{0} trying to update db ", key)); | 
					
						
							|  |  |  |  |                             try | 
					
						
							|  |  |  |  |                             { | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                               //  WmsConstants.WAVE_CURRENT_PICK_STATUS[key] = client.updateSeedsPickingStatus(getOrigColor(partion, Convert.ToInt16(color)), ele_id, little_ele_id, //Convert.ToDecimal(receive_count));//本次拣选完毕 | 
					
						
							|  |  |  |  |                                 WmsConstants.WAVE_CURRENT_PICK_STATUS[key] = client.updateSeedsPickingStatus( Convert.ToInt16(color), ele_id, little_ele_id, Convert.ToDecimal(receive_count),partion);//本次拣选完毕 | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                                 LogHelper.debug(typeof(light), string.Format(" ..........{0} update result {1}", key, WmsConstants.WAVE_CURRENT_PICK_STATUS[key])); | 
					
						
							|  |  |  |  |                                   | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                                 client.Close(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                             catch (DeiNiuTimeOutException e) | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 Login lg = new Login(); | 
					
						
							|  |  |  |  |                                 lg.ShowDialog(); | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                             catch (Exception e) | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 LogHelper.WriteLog(typeof(light), e); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                         } | 
					
						
							|  |  |  |  |                         break; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                  | 
					
						
							|  |  |  |  |                   | 
					
						
							|  |  |  |  |                  manage_add++; | 
					
						
							|  |  |  |  |                 if (manage_add >= add_max) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     manage_add = 0; | 
					
						
							|  |  |  |  |                 }  | 
					
						
							|  |  |  |  |                  | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             //统一处理。。。。 | 
					
						
							|  |  |  |  |             /* | 
					
						
							|  |  |  |  |             if (cnt == 0) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 return; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             switch (pickType) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 case enumLabelPickType.pick: | 
					
						
							|  |  |  |  |                   | 
					
						
							|  |  |  |  |                      bool isPickOver = outPick.getCurrentPickList(DeiNiu.Utils.enumLabelPickState.notPicked).Tables[0].Rows.Count ==0;//波次是否全部拣选完毕 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                        elelab.pick.pick_task = isPickOver; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                        if (isPickOver) | 
					
						
							|  |  |  |  |                        {   | 
					
						
							|  |  |  |  |                            //lWmsOutPickRequest lpickRequest = new lWmsOutPickRequest(); | 
					
						
							|  |  |  |  |                            lpickRequest.finishCurrentWave(false);   | 
					
						
							|  |  |  |  |                        } | 
					
						
							|  |  |  |  |                     break; | 
					
						
							|  |  |  |  |                 case enumLabelPickType.seed: | 
					
						
							|  |  |  |  |                     break; | 
					
						
							|  |  |  |  |                 case enumLabelPickType.tran: | 
					
						
							|  |  |  |  |                     break; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             */ | 
					
						
							|  |  |  |  |           | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         private static void manage_data() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             dataSent(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         private static bool read_state() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             for (int i = 0; i < coms.com_manage.Length; i++) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 if (coms.com_manage[i] != null) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     if (coms.com_manage[i].wait_data == true) | 
					
						
							|  |  |  |  |                     {//读取数据 | 
					
						
							|  |  |  |  |                         return true; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             return false; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         private static void pick_sys() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             //int count;Threads_state | 
					
						
							|  |  |  |  |             // Threads_state = true; | 
					
						
							|  |  |  |  |             //out_start_state = false; | 
					
						
							|  |  |  |  |             elelab.lightSeeds.init_pick_support(); | 
					
						
							|  |  |  |  |             while (true) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 // unart_manage.com_manage[17].return_data(); | 
					
						
							|  |  |  |  |                 pick_work_support.Suspend(); | 
					
						
							|  |  |  |  |                 //System.Threading.Thread.Sleep(15000); | 
					
						
							|  |  |  |  |                 receiveData(); | 
					
						
							|  |  |  |  |                 manage_data(); | 
					
						
							|  |  |  |  |                 wake_support_thread(); | 
					
						
							|  |  |  |  |                 pick_work.Suspend(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         internal static void pick_sys_support() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             //int count;Threads_state | 
					
						
							|  |  |  |  |             while (true) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 System.Threading.Thread.Sleep(2000); | 
					
						
							|  |  |  |  |                 if (read_state() == true) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     wake_thread(); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 pick_work_support.Suspend(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         internal static void test_multe() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             //while (wms_usartmanage.pick.send_state == true) ; | 
					
						
							|  |  |  |  |             //wms_usartmanage.pick.send_state = true; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             //// while (get_part_task() == true) ; | 
					
						
							|  |  |  |  |             //get_part_task(); | 
					
						
							|  |  |  |  |             ////while(led_lamble() == true); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             //wms_usartmanage.pick.send_state = false; | 
					
						
							|  |  |  |  |             return; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         //webserver 接口 | 
					
						
							|  |  |  |  |         //初始化端口 | 
					
						
							|  |  |  |  |         //复位端口 | 
					
						
							|  |  |  |  |         //清除订单 | 
					
						
							|  |  |  |  |         internal static void initPort(enumLabelPickType pickType) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             elelab.coms.initSys(); | 
					
						
							|  |  |  |  |             init_sys_port(pickType); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         | 
					
						
							|  |  |  |  |         public static bool resetDevice(int port) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if( elelab.coms.com_manage[port]!=null) | 
					
						
							|  |  |  |  |              return elelab.coms.com_manage[port].write_reset_device(); | 
					
						
							|  |  |  |  |             return false; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static void displayLabels(int port) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if (elelab.coms.com_manage[port] != null) | 
					
						
							|  |  |  |  |                 elelab.coms.com_manage[port].displayLabel(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static void clearLabels(int port) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if (elelab.coms.com_manage[port] != null) | 
					
						
							|  |  |  |  |                 elelab.coms.com_manage[port].clearLabel(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         internal static string lightsUp(DataTable dt,enumLabelPickType pickType)////----- | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |           // init_port(pickType); | 
					
						
							|  |  |  |  |             if (activeComports.Count ==0 ) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |               //  return "没有活动端口"; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             if ( dt.Rows.Count == 0) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 return "没有亮灯数据"; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             //WmsConstants.WAVE_CURRENT_PICK_STATUS.Clear(); | 
					
						
							|  |  |  |  |             //WmsConstants.WAVE_CURRENT_LIGHTS_STATUS.Clear(); | 
					
						
							|  |  |  |  |             //WmsConstants.SEEDS_CURRENT_PICK_STATUS.Clear();  | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |           | 
					
						
							|  |  |  |  |             DataTable[] ds = split_ele_data(dt); | 
					
						
							|  |  |  |  |           //  DataTable[] ds = split_ele_data(sortedTable); | 
					
						
							|  |  |  |  |              | 
					
						
							|  |  |  |  |             int successCnt=0; | 
					
						
							|  |  |  |  |             int failureCnt=0; | 
					
						
							|  |  |  |  |             for (int j = 0; j < ds.Length; j++) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 //string part = ; | 
					
						
							|  |  |  |  |                 byte part_byte = get_byte(ds[j].Rows[0]["ele_order"].ToString()); | 
					
						
							|  |  |  |  |                 //part_byte = 1; | 
					
						
							|  |  |  |  |                 string port = ds[j].Rows[0]["port"].ToString(); | 
					
						
							|  |  |  |  |                 byte port_byte = get_byte(port); | 
					
						
							|  |  |  |  |                 byte led_color = get_byte(ds[j].Rows[0]["color"].ToString()); | 
					
						
							|  |  |  |  |                 byte pick_type = get_byte( ((int)pickType).ToString()); | 
					
						
							|  |  |  |  |                 if (elelab.lightSeeds.make_data(ds[j], led_color, part_byte, port_byte, null, null, null, pick_type)) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     successCnt++; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 else | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     failureCnt++; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             elelab.lightSeeds.pick_task = false; | 
					
						
							|  |  |  |  |             if (failureCnt > 0) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |               //  return string.Format("成功点亮标签{0}个,点亮失败{1}个", successCnt, failureCnt); | 
					
						
							|  |  |  |  |                 //return string.Format("成功点亮{0},失败{1}", successCnt, failureCnt); | 
					
						
							|  |  |  |  |                 if (successCnt > 0) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     return "部分标签未点亮"; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 else | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     return "标签点亮失败"; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             return "亮灯成功"; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         private static DataTable[] split_ele_data(DataTable dt) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             //  dt.DefaultView.Sort = "ele_order,color"; | 
					
						
							|  |  |  |  |             // 同一个亮灯波次里标签ID和标签前2位数字的组合只能有一个 | 
					
						
							|  |  |  |  |             //[{"labelId":1,"num1":14,"num3":1333,"color":4 },{"labelId":1,"num1":14,"num3":67,"color":1 }] | 
					
						
							|  |  |  |  |             //如上,同一个亮灯 order只能显示一个 | 
					
						
							|  |  |  |  |             //需要分别放在不同亮灯波次order里 | 
					
						
							|  |  |  |  |           | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |             int partId = Convert.ToInt16(dt.Rows[0]["ele_order"].ToString()); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |            /* | 
					
						
							|  |  |  |  |             foreach (DataRow dr in dt.Rows) | 
					
						
							|  |  |  |  |             {  | 
					
						
							|  |  |  |  |                 string waveNo = dr["dpsOrder"].ToString(); | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                 int color = getMapColor(partId, Convert.ToInt16(dr["color"].ToString())); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                 dr["color"] = color; | 
					
						
							|  |  |  |  |                 if (!WmsConstants.currentWavePart.Keys.Contains(partId)) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     WmsConstants.currentWavePart[partId] = new Dictionary<int, string>(); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 WmsConstants.currentWavePart[partId].Add(color, waveNo); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             */ | 
					
						
							|  |  |  |  |             if (WmsConstants.PART_FINISH_LABLE_IDS != null | 
					
						
							|  |  |  |  |                 && WmsConstants.PART_FINISH_LABLE_IDS.Contains(partId)) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 DataRow dr1 = dt.NewRow(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 dr1["color"] = dt.Rows[0]["color"]; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 if (partColors.ContainsKey(partId)) //完成器颜色红绿轮替 | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     if (partColors[partId] == 1) | 
					
						
							|  |  |  |  |                     { | 
					
						
							|  |  |  |  |                         partColors[partId] = 2; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                     else | 
					
						
							|  |  |  |  |                     { | 
					
						
							|  |  |  |  |                         partColors[partId] = 1; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 else | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     partColors[partId] = 1; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 //  if (WmsConstants.PART_ORDER_SIZE > 1) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     dr1["color"] = partColors[partId]; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 dr1["ele_lab_id"] = partId; | 
					
						
							|  |  |  |  |                 dr1["ele_address"] = dt.Rows[0]["ele_order"]; ; | 
					
						
							|  |  |  |  |                 dr1["port"] = dt.Rows[0]["port"]; | 
					
						
							|  |  |  |  |                 dr1["pick_count"] = dt.Rows[0]["ele_order"]; | 
					
						
							|  |  |  |  |                 dr1["send_count"] = 1; //待分拣数量 | 
					
						
							|  |  |  |  |                 dr1["ele_order"] = dt.Rows[0]["ele_order"]; | 
					
						
							|  |  |  |  |                 dr1["state"] = 0; | 
					
						
							|  |  |  |  |                 //  dr[7] = dt.Rows[i][7]; | 
					
						
							|  |  |  |  |                 dt.Rows.Add(dr1); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             if (dt.Rows.Count ==2) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 DataTable[] ds1 = new DataTable[1]; | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                // dt.Rows[0]["color"] = getMapColor(partId, Convert.ToInt16(dt.Rows[0]["color"].ToString())); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                 ds1[0] = dt; | 
					
						
							|  |  |  |  |                 return ds1; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             int count = 1; | 
					
						
							|  |  |  |  |             //ele_order | 
					
						
							|  |  |  |  |             string port ,portLast, eOrder , eOrderLast = ""; | 
					
						
							|  |  |  |  |             for (int i = 1; i < dt.Rows.Count; i++) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                   port = dt.Rows[i]["port"].ToString(); | 
					
						
							|  |  |  |  |                   portLast = dt.Rows[i - 1]["port"].ToString(); | 
					
						
							|  |  |  |  |                   eOrder = dt.Rows[i]["ele_order"].ToString(); | 
					
						
							|  |  |  |  |                   eOrderLast = dt.Rows[i - 1]["ele_order"].ToString(); | 
					
						
							|  |  |  |  |                 if (port != portLast ||eOrder !=eOrderLast) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     count++; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             }//ele_order | 
					
						
							|  |  |  |  |             DataTable[] ds = new DataTable[count]; | 
					
						
							|  |  |  |  |             for (int i = 0; i < count; i++) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 ds[i] = dt.Clone(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             int address = 0; | 
					
						
							|  |  |  |  |             for (int i = 0; i < dt.Rows.Count; i++) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 if (i == 0) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     address = 0; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 else if ((dt.Rows[i]["port"].ToString() != dt.Rows[i - 1]["port"].ToString()) || | 
					
						
							|  |  |  |  |                     (dt.Rows[i]["ele_order"].ToString() != dt.Rows[i - 1]["ele_order"].ToString())) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     address++; | 
					
						
							|  |  |  |  |                     //ds[address].Rows.Add(dr); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 //else | 
					
						
							|  |  |  |  |                 //{ | 
					
						
							|  |  |  |  |                 //    ds[address].Rows.Add(dr); | 
					
						
							|  |  |  |  |                 //} | 
					
						
							|  |  |  |  |                 DataRow dr = ds[address].NewRow(); | 
					
						
							|  |  |  |  |                 dr[0] = dt.Rows[i][0]; | 
					
						
							|  |  |  |  |                 dr[1] = dt.Rows[i][1]; | 
					
						
							|  |  |  |  |                 dr[2] = dt.Rows[i][2]; | 
					
						
							|  |  |  |  |                 dr[3] = dt.Rows[i][3]; | 
					
						
							|  |  |  |  |                 dr[4] = dt.Rows[i][4]; | 
					
						
							|  |  |  |  |                 dr[5] = dt.Rows[i][5]; | 
					
						
							|  |  |  |  |                 dr[6] = dt.Rows[i][6]; | 
					
						
							|  |  |  |  |                 //  dr[7] = dt.Rows[i][7]; | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |               //  dr["color"] = getMapColor(partId, Convert.ToInt16(dr["color"].ToString())); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |                 ds[address].Rows.Add(dr); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             return ds; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         /// <summary> | 
					
						
							|  |  |  |  |         /// 记录当前点亮的波次信息 | 
					
						
							|  |  |  |  |         /// 注册周转箱时使用 | 
					
						
							|  |  |  |  |         /// </summary> | 
					
						
							|  |  |  |  |         //void setCurrentPartionWaveColor(DataTable dt) | 
					
						
							|  |  |  |  |         //{ | 
					
						
							|  |  |  |  |         //    WmsConstants.currentWavePart = new Dictionary<int, Dictionary<int, string>>(); | 
					
						
							|  |  |  |  |         //    foreach(DataRow dr in dt.Rows) | 
					
						
							|  |  |  |  |         //    { | 
					
						
							|  |  |  |  |              | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |         //        int partion= Convert.ToInt16( dr["ele_order"].ToString()); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |         //        string waveNo =  dr["dpsOrder"].ToString()  ;    | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |         //        int color=  getMapColor(partion, Convert.ToInt16(dr["color"].ToString())); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |         //        dr["color"] = color; | 
					
						
							|  |  |  |  |         //        if (!WmsConstants.currentWavePart.Keys.Contains(partion)) | 
					
						
							|  |  |  |  |         //        { | 
					
						
							|  |  |  |  |         //            WmsConstants.currentWavePart[partion] = new Dictionary<int, string>(); | 
					
						
							|  |  |  |  |         //        } | 
					
						
							|  |  |  |  |         //        WmsConstants.currentWavePart[partion].Add(color, waveNo); | 
					
						
							|  |  |  |  |             | 
					
						
							|  |  |  |  |         //    } | 
					
						
							|  |  |  |  |         //} | 
					
						
							|  |  |  |  |        | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } |