| | |
| | | #endregion |
| | | |
| | | AOI1Config ConfigAOI1 => Config as AOI1Config; |
| | | TcpClientWrapBase BarcodeScanner = null; |
| | | |
| | | |
| | | |
| | | public override void Open() |
| | | { |
| | | base.Open(); |
| | | BarcodeScanner = DeviceCollection.FirstOrDefault(u => u is TcpClientWrapBase) as TcpClientWrapBase; |
| | | |
| | | } |
| | | |
| | | [ProcessMethod("", "PositionCheck_P1", "工位1检测", InvokeType.TestInvoke)] |
| | | public ResponseMessage PositionCheck_P1(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | |
| | | var positionSet = M141Config.WorkPositionCollection.Where(u => u.IsEnabled).FirstOrDefault(u => u.TriggerValue == "1#"); |
| | | if (positionSet == null) |
| | | { |
| | |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | if (config is IImageCheckOperationConfig opConfig) |
| | | { |
| | | var results = opConfig.Products.Select(u => |
| | | if (invokeDevice is TcpClientWrapBase BarcodeScanner) |
| | | { |
| | | DetectResult result = new DetectResult(); |
| | | result.PID = u.PID; |
| | | result.Specs = GetSpecListFromConfigSelection(opConfig.SpecCollection); |
| | | return result; |
| | | }).ToList(); |
| | | var results = opConfig.Products.Select(u => |
| | | { |
| | | DetectResult result = new DetectResult(); |
| | | result.PID = u.PID; |
| | | result.Specs = GetSpecListFromConfigSelection(opConfig.SpecCollection); |
| | | return result; |
| | | }).ToList(); |
| | | |
| | | msg.DataObj = results; |
| | | msg.DataObj = results; |
| | | |
| | | string barcode = BarcodeScannerCommunicate(); |
| | | string barcode = BarcodeScannerCommunicate(BarcodeScanner); |
| | | |
| | | List<double> ret = new List<double>(); |
| | | if ("NOREAD".Equals(barcode.ToUpper())) |
| | | { |
| | | ret.Add(999); |
| | | List<double> ret = new List<double>(); |
| | | if ("NOREAD".Equals(barcode.ToUpper())) |
| | | { |
| | | ret.Add(999); |
| | | } |
| | | else |
| | | { |
| | | ret.Add(1); |
| | | } |
| | | |
| | | FillSpecResults(results[0].PID, results[0].Specs, ret, opConfig.Products[0].SEQUENCE); |
| | | |
| | | |
| | | opConfig.Products[0].SN = barcode; |
| | | opConfig.Products[0].Details.ForEach(u => u.SN = barcode); |
| | | |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"产品{opConfig.Products[0].PID}条码获取为{barcode}"); |
| | | } |
| | | else |
| | | { |
| | | ret.Add(1); |
| | | } |
| | | |
| | | FillSpecResults(results[0].PID, results[0].Specs, ret, opConfig.Products[0].SEQUENCE); |
| | | |
| | | |
| | | opConfig.Products[0].SN = barcode; |
| | | opConfig.Products[0].Details.ForEach(u => u.SN = barcode); |
| | | |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"产品{opConfig.Products[0].PID}条码获取为{barcode}"); |
| | | |
| | | } |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | [ProcessMethod("ImageCheck", "ReadBarcode2", "读栏具码", InvokeType.TestInvoke)] |
| | | public ResponseMessage ReadBarcode2(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice) |
| | | { |
| | | ResponseMessage msg = new ResponseMessage(); |
| | | |
| | | private string BarcodeScannerCommunicate() |
| | | if (invokeDevice is TcpClientWrapBase BarcodeScanner2) |
| | | { |
| | | string barcode = BarcodeScannerCommunicate(BarcodeScanner2); |
| | | if (string.IsNullOrEmpty(barcode) || "noread".Equals(barcode.ToLower())) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"栏具码获取失败"); |
| | | Plc1.WriteSingleAddress(1524, 2, out _); |
| | | Plc1.WriteSingleAddress(1514, 1, out _); |
| | | } |
| | | else |
| | | { |
| | | Plc1.WriteSingleAddress(1524, 1, out _); |
| | | Plc1.WriteSingleAddress(1514, 1, out _); |
| | | ConfigAOI1.basketcode = barcode; |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"获取到栏具码为{barcode}"); |
| | | } |
| | | } |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | |
| | | |
| | | private string BarcodeScannerCommunicate(TcpClientWrapBase client) |
| | | { |
| | | string barcode = ""; |
| | | |
| | | for (int i = 0; i < 3; i++) |
| | | { |
| | | if (BarcodeScanner.WriteAndRead("start", out string error, out barcode, true)) |
| | | if (client.WriteAndRead("start", out string error, out barcode, true)) |
| | | { |
| | | barcode = barcode.Trim(' ', '\r', '\n'); |
| | | if (CheckBarcodeValid(barcode)) |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"{BarcodeScanner.Name}扫码完成,反馈{barcode}"); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"{client.Name}扫码完成,反馈{barcode}"); |
| | | return barcode; |
| | | } |
| | | else |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"{BarcodeScanner.Name}第{i + 1}扫码完成,反馈{barcode},不是合法条码"); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"{client.Name}第{i + 1}扫码完成,反馈{barcode},不是合法条码"); |
| | | Thread.Sleep(200); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"{BarcodeScanner.Name}扫码失败,{error}"); |
| | | LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"{client.Name}扫码失败,{error}"); |
| | | break; |
| | | } |
| | | } |