| 
									
										
										
										
											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 lightPart | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         public delegate void printPack(int eleId); | 
					
						
							|  |  |  |  |         public static printPack printLabPack ; | 
					
						
							|  |  |  |  |         public delegate void lightFinish(int eleId); | 
					
						
							|  |  |  |  |         public static event lightFinish lightOffEvent; | 
					
						
							|  |  |  |  |         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; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         internal static bool begain_pick = false; | 
					
						
							|  |  |  |  |         //  internal static bool Threads_state; | 
					
						
							|  |  |  |  |         // internal static bool out_start_state; | 
					
						
							|  |  |  |  |         internal static byte[,] ele_lab = new byte[6000, 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()); | 
					
						
							|  |  |  |  |                 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; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         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 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; | 
					
						
							|  |  |  |  |                 DataView dv = ds.DefaultView; | 
					
						
							|  |  |  |  |                 dv.RowFilter = "state =0"; | 
					
						
							|  |  |  |  |                 uart_dis_data[] ele_data_comment = new uart_dis_data[dv.Count]; | 
					
						
							|  |  |  |  |                 int j = 0; | 
					
						
							|  |  |  |  |                 for (int i = 0; i < ds.Rows.Count; i++) | 
					
						
							|  |  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                     elid = Convert.ToInt16(ds.Rows[i]["ele_lab_id"].ToString()); | 
					
						
							|  |  |  |  |                     if (Convert.ToInt16(ds.Rows[i]["state"].ToString()) == 1) | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                     { //picked | 
					
						
							|  |  |  |  |                         continue; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                     ele_data_comment[j].channel_id = 0;//暂不使用 默认为0 | 
					
						
							|  |  |  |  |                     ele_data_comment[j].dis_type = Convert.ToByte(ds.Rows[i]["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[i]["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[i]["send_count"].ToString().Split('.');//Out_count | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                     get_data(ds.Rows[i]["send_count"].ToString(), out dot_station, out total_num); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-06 19:36:47 +08:00
										 |  |  |  |                     if (WmsConstants.PART_FINISH_LABLE_IDS != null && WmsConstants.PART_FINISH_LABLE_IDS.Contains(elid)) | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                     { | 
					
						
							|  |  |  |  |                         total_num = j; | 
					
						
							|  |  |  |  |                     } | 
					
						
							| 
									
										
										
										
											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[i]["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(elid)) | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                     { | 
					
						
							|  |  |  |  |                         partKeys[elid] = key; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                     j++; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 }// //向串口发送数据 | 
					
						
							|  |  |  |  |                 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; | 
					
						
							|  |  |  |  |             // 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 | 
					
						
							|  |  |  |  |                 //  color = ele_lab_data[manage_add].order.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
										 |  |  |  |                 int state = ele_lab[ele_id, little_ele_id]; | 
					
						
							|  |  |  |  |                 pickType = (enumLabelPickType)state; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							|  |  |  |  |                 //  { | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                 int trycnt=0; | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                 switch (pickType) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     case enumLabelPickType.pick: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                         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; | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                         } | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  |  |                         } | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |                         try | 
					
						
							|  |  |  |  |                         { | 
					
						
							| 
									
										
										
										
											2024-02-06 19:36:47 +08:00
										 |  |  |  |                             if(currentJobNo == "库存检查") | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 return; | 
					
						
							|  |  |  |  |                             } | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |                             updatePickStatus(key, color, ele_id, little_ele_id, receive_count); | 
					
						
							|  |  |  |  |                         } | 
					
						
							|  |  |  |  |                         catch (DeiNiuTimeOutException e) | 
					
						
							|  |  |  |  |                         { | 
					
						
							|  |  |  |  |                             Login lg = new Login(); | 
					
						
							|  |  |  |  |                             lg.ShowDialog(); | 
					
						
							|  |  |  |  |                         } | 
					
						
							|  |  |  |  |                         catch (Exception e) | 
					
						
							|  |  |  |  |                         { | 
					
						
							|  |  |  |  |                             LogHelper.WriteLog(typeof(light), e); | 
					
						
							|  |  |  |  |                             WmsConstants.WAVE_CURRENT_PICK_STATUS[key] = false; | 
					
						
							|  |  |  |  |                             trycnt++; | 
					
						
							|  |  |  |  |                             LogHelper.debug(typeof(light), string.Format(" trying cnt {0}  ", trycnt)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                             if (trycnt < 3) | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 try | 
					
						
							|  |  |  |  |                                 { | 
					
						
							|  |  |  |  |                                     updatePickStatus(key, color, ele_id, little_ele_id, receive_count); | 
					
						
							|  |  |  |  |                                 } | 
					
						
							|  |  |  |  |                                 catch (Exception err) | 
					
						
							|  |  |  |  |                                 { | 
					
						
							|  |  |  |  |                                     LogHelper.WriteLog(typeof(light), err); | 
					
						
							|  |  |  |  |                                 } | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                             // throw e; | 
					
						
							|  |  |  |  |                         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                         using (WmsOutPickRequestClient client = new WmsOutPickRequestClient()) | 
					
						
							|  |  |  |  |                         { | 
					
						
							|  |  |  |  |                             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.updatePickingStatus(Convert.ToInt16(color), ele_id, little_ele_id, Convert.ToDecimal(receive_count));//本次拣选完毕 | 
					
						
							| 
									
										
										
										
											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])); | 
					
						
							|  |  |  |  |                                 /* | 
					
						
							|  |  |  |  |                                 bool isPickOver = client.getCurrentPickList((int)DeiNiu.Utils.enumPickState.未拣).Rows.Count == 0;//波次是否全部拣选完毕 | 
					
						
							|  |  |  |  |                               //  LogHelper.debug(typeof(pick), string.Format(" ..........{0} update result {1}", key, WmsConstants.WAVE_CURRENT_PICK_STATUS[key])); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                                 pick_task = isPickOver; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                                 if (isPickOver) | 
					
						
							|  |  |  |  |                                 { | 
					
						
							|  |  |  |  |                                     //lWmsOutPickRequest lpickRequest = new lWmsOutPickRequest(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                                     client.finishCurrentWave(WmsConstants.WAVE_CURRENT_ORDER ,false); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                                 } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                                 client.Close(); | 
					
						
							|  |  |  |  |                                  * */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                             catch (DeiNiuTimeOutException e) | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 Login lg = new Login(); | 
					
						
							|  |  |  |  |                                 lg.ShowDialog(); | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                             catch (Exception e) | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 LogHelper.WriteLog(typeof(light), e); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                         } | 
					
						
							|  |  |  |  |                         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()) | 
					
						
							|  |  |  |  |                         { | 
					
						
							|  |  |  |  |                            /* try | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                               | 
					
						
							|  |  |  |  |                                  | 
					
						
							|  |  |  |  |                                 bool isPickOrderFinished  = 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(); | 
					
						
							|  |  |  |  |                               WmsConstants.SEEDS_CURRENT_PICK_STATUS[key] = isPickOrderFinished; | 
					
						
							|  |  |  |  |                              | 
					
						
							|  |  |  |  |                                  | 
					
						
							|  |  |  |  |                              if (isPickOrderFinished) | 
					
						
							|  |  |  |  |                               { | 
					
						
							|  |  |  |  |                                   if (printLabPack != null) | 
					
						
							|  |  |  |  |                                   { | 
					
						
							|  |  |  |  |                                       printLabPack(ele_id); | 
					
						
							|  |  |  |  |                                   } | 
					
						
							|  |  |  |  |                               } | 
					
						
							|  |  |  |  |                                | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                             catch (DeiNiuTimeOutException e) | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 Login lg = new Login(); | 
					
						
							|  |  |  |  |                                 lg.ShowDialog(); | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                             catch (Exception e) | 
					
						
							|  |  |  |  |                             { | 
					
						
							|  |  |  |  |                                 LogHelper.WriteLog(typeof(light), e); | 
					
						
							|  |  |  |  |                             } | 
					
						
							|  |  |  |  |                               * */ | 
					
						
							|  |  |  |  |                         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                         break; | 
					
						
							|  |  |  |  |                     case enumLabelPickType.tran: | 
					
						
							|  |  |  |  |                         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; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |         public static string currentJobNo = ""; | 
					
						
							| 
									
										
										
										
											2024-02-06 19:36:47 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         public static int userId = 0; | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |         private static void updatePickStatus(string key, string color, int ele_id, int little_ele_id, string receive_count) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             using (WmsOutPickRequestClient client = new WmsOutPickRequestClient("BasicHttpBinding_IWmsOutPickRequest", | 
					
						
							|  |  |  |  |                                                      string.Format("http://{0}/{1}", Park.svrUrl, "WmsOutPickRequestService.svc"))) | 
					
						
							|  |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2024-02-06 19:36:47 +08:00
										 |  |  |  |                 LogHelper.debug(typeof(lightPart), string.Format(" ..........{0} trying to update db, userId is  ", key,userId)); | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-06 19:36:47 +08:00
										 |  |  |  |                 WmsConstants.WAVE_CURRENT_PICK_STATUS[key] = client.updatePortPickingStatus(userId,Convert.ToInt16(color), ele_id, little_ele_id, Convert.ToDecimal(receive_count));//本次拣选完毕 | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                 LogHelper.debug(typeof(light), string.Format(" ..........{0} update result {1}", key, WmsConstants.WAVE_CURRENT_PICK_STATUS[key])); | 
					
						
							|  |  |  |  |                 bool isPickOver =false; | 
					
						
							|  |  |  |  |                 foreach (bool isOky in WmsConstants.WAVE_CURRENT_PICK_STATUS.Values) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     isPickOver = isOky; | 
					
						
							|  |  |  |  |                 }  | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                  isPickOver = isPickOver && client.getDpsPickList(currentJobNo,(int)DeiNiu.Utils.enumPickState.未拣).Rows.Count == 0;//波次是否全部拣选完毕 | 
					
						
							|  |  |  |  |                 //  //LogHelper.debug(typeof(pick), string.Format(" ..........{0} update result {1}", key, WmsConstants.WAVE_CURRENT_PICK_STATUS[key])); | 
					
						
							|  |  |  |  |                   | 
					
						
							|  |  |  |  |                  pick_task = isPickOver; | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                 if (isPickOver) | 
					
						
							|  |  |  |  |                 {  | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                   int i=  client.clearJobLightTask(currentJobNo ); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                     LogHelper.debug(typeof(lightPart), string.Format(" to clear job {0} ,cleared tasks cnt  {1}", currentJobNo,i)); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 client.Close(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         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; | 
					
						
							|  |  |  |  |             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); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         internal static string resetDevice(string port) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             int port_num; | 
					
						
							|  |  |  |  |             try | 
					
						
							|  |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                 port_num = Convert.ToInt16(port); | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |             } | 
					
						
							|  |  |  |  |             catch | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 port_num = 1; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             elelab.coms.com_manage[port_num].write_reset_device(); | 
					
						
							|  |  |  |  |             return "<result>执行成功</result>"; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         internal static string lightsUp(DataTable dt, enumLabelPickType pickType)////----- | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             // init_port(pickType); | 
					
						
							|  |  |  |  |             if (activeComports.Count == 0 || dt.Rows.Count == 0) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 return ""; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             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 (make_data(ds[j], led_color, part_byte, port_byte, null, null, null, pick_type)) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     successCnt++; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 else | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     failureCnt++; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             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"; | 
					
						
							|  |  |  |  |             if (dt.Rows.Count == 1) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 DataTable[] ds1 = new DataTable[1]; | 
					
						
							| 
									
										
										
										
											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
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |                 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); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 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 | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     string port1 = dt.Rows[i]["port"].ToString(); | 
					
						
							|  |  |  |  |                     string port2 = dt.Rows[i - 1]["port"].ToString(); | 
					
						
							|  |  |  |  |                     string order1 = dt.Rows[i]["ele_order"].ToString(); | 
					
						
							|  |  |  |  |                     string order2 = dt.Rows[i - 1]["ele_order"].ToString(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                     if ((port1 != port2) || (order1 != order2)) | 
					
						
							|  |  |  |  |                     { | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                         int partId = Convert.ToInt16(order2); | 
					
						
							| 
									
										
										
										
											2024-02-06 19:36:47 +08:00
										 |  |  |  |                         if (WmsConstants.PART_FINISH_LABLE_IDS != null && WmsConstants.PART_FINISH_LABLE_IDS.Contains(partId)) | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                         { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                             DataRow dr1 = ds[address].NewRow(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                             dr1["color"] = dt.Rows[i - 1]["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"] = partId; | 
					
						
							|  |  |  |  |                             dr1["port"] = dt.Rows[i - 1]["port"]; | 
					
						
							|  |  |  |  |                             dr1["pick_count"] = dt.Rows[i - 1]["ele_order"]; | 
					
						
							|  |  |  |  |                             dr1["send_count"] = dt.Rows[i - 1]["ele_order"]; | 
					
						
							|  |  |  |  |                             dr1["ele_order"] = dt.Rows[i - 1]["ele_order"]; | 
					
						
							|  |  |  |  |                             dr1["state"] = 0; | 
					
						
							|  |  |  |  |                             //  dr[7] = dt.Rows[i][7]; | 
					
						
							|  |  |  |  |                             ds[address].Rows.Add(dr1); | 
					
						
							|  |  |  |  |                         } | 
					
						
							|  |  |  |  |                         address++; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 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]; | 
					
						
							|  |  |  |  |                 ds[address].Rows.Add(dr); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 if (i + 1 == dt.Rows.Count) //点亮完成器 | 
					
						
							|  |  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |                     int partId = Convert.ToInt16(dt.Rows[i]["ele_order"].ToString()); | 
					
						
							| 
									
										
										
										
											2024-02-06 19:36:47 +08:00
										 |  |  |  |                     if (WmsConstants.PART_FINISH_LABLE_IDS != null && WmsConstants.PART_FINISH_LABLE_IDS.Contains(partId)) | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |                     { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                         DataRow dr1 = ds[address].NewRow(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                         dr1["color"] = dt.Rows[i]["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"] = partId; | 
					
						
							|  |  |  |  |                         dr1["port"] = dt.Rows[i]["port"]; | 
					
						
							|  |  |  |  |                         dr1["pick_count"] = dt.Rows[i]["ele_order"]; | 
					
						
							|  |  |  |  |                         dr1["send_count"] = dt.Rows[i]["ele_order"]; | 
					
						
							|  |  |  |  |                         dr1["ele_order"] = dt.Rows[i]["ele_order"]; | 
					
						
							|  |  |  |  |                         dr1["state"] = 0; | 
					
						
							|  |  |  |  |                         ds[address].Rows.Add(dr1); | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                     address++; | 
					
						
							|  |  |  |  |                     //ds[address].Rows.Add(dr); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             return ds; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-21 19:18:23 +08:00
										 |  |  |  |         public static bool lightLabels2(List<DeiNiu.wms.win.ELabel> lables, int portNo, int orderId, enumLabelPickType pickType)////----- | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             // init_port(pickType); | 
					
						
							|  |  |  |  |             // WmsConstants.WAVE_CURRENT_LIGHTS_PORT_STATUS.Clear(); | 
					
						
							|  |  |  |  |             byte orderPort = get_byte(portNo.ToString()); | 
					
						
							|  |  |  |  |             if (activeComports.Count == 0 || lables.Count == 0) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 return false; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             int deskId = lables[0].deskId; | 
					
						
							|  |  |  |  |            | 
					
						
							|  |  |  |  |             List<string> statuKeys = new List<string>(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             uart_dis_data[] ele_data_comment = new uart_dis_data[lables.Count]; | 
					
						
							|  |  |  |  |             for (int j = 0; j < lables.Count; j++) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 DeiNiu.wms.win.ELabel lb = lables[j];  | 
					
						
							|  |  |  |  |                  | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 ele_data_comment[j].dis_type = get_byte((lb.color).ToString());  //Convert.ToByte(textBox4.Text); 电子标签灯的颜色 1 红色 2 绿色 3 蓝色 | 
					
						
							|  |  |  |  |                 ele_data_comment[j].ele_id = lb.labelId; ;     //电子标签id | 
					
						
							|  |  |  |  |                 ele_data_comment[j].order = Convert.ToByte(orderId);// get_byte(orderId.ToString());//Convert.ToByte(textBox2.Text);  单号 | 
					
						
							|  |  |  |  |                 ele_data_comment[j].receive_count = 0;  //为0 | 
					
						
							|  |  |  |  |                 ele_data_comment[j].little_ele_id = Convert.ToByte(lb.address);// 货位号 | 
					
						
							|  |  |  |  |                 ele_data_comment[j].send_count = lb.count; | 
					
						
							|  |  |  |  |                 ele_data_comment[j].state = 1;  //都为1 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 ele_lab[ele_data_comment[j].ele_id, ele_data_comment[j].little_ele_id] = get_byte(((int)pickType).ToString()); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |                 statuKeys.Add(Util.getLightKey(lb.color, lb.labelId, lb.address)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             }// //向串口发送数据 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             if (!clearOrder(orderPort, orderId)) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 return false; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             coms.com_manage[orderPort].write_data(ele_data_comment); | 
					
						
							|  |  |  |  |             string result; | 
					
						
							|  |  |  |  |             bool isLightsSuccess = coms.com_manage[orderPort].wait_ack(out result); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             foreach (string key in statuKeys) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 WmsConstants.WAVE_CURRENT_LIGHTS_STATUS[key] = isLightsSuccess; | 
					
						
							|  |  |  |  |                 WmsConstants.WAVE_CURRENT_PICK_STATUS[key] = false; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             return true; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         public static bool clearOrder(int port, int orderId) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             clear_order order = new clear_order(); | 
					
						
							|  |  |  |  |             order.order = get_byte(orderId.ToString()); //orderPort;// get_byte(portNo.ToString());//Convert.ToByte(ele_order_id); | 
					
						
							|  |  |  |  |             order.state = 1; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             if (coms.com_manage[port].clear_order(order) == false) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 return false; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             return true; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static bool reset_device(int port) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if (coms.com_manage[port] != null) | 
					
						
							|  |  |  |  |                 return coms.com_manage[port].write_reset_device(); | 
					
						
							|  |  |  |  |             return false; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-05-23 16:13:17 +08:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | } |