BCRExtension.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using PlcSiemens.Core.Extension;
  2. using ServiceCenter.Logs;
  3. using WCS.Core;
  4. using WCS.WorkEngineering.Protocol.BCR;
  5. namespace WCS.WorkEngineering.Extensions
  6. {
  7. /// <summary>
  8. /// BCR扩展
  9. /// </summary>
  10. public class BCR : Device<IBCR81>
  11. {
  12. /// <summary>
  13. /// BCR扩展
  14. /// </summary>
  15. /// <param name="device"></param>
  16. /// <param name="world"></param>
  17. public BCR(Device device, World world) : base(device, world)
  18. {
  19. }
  20. /// <summary>
  21. /// 获取BCR码
  22. /// </summary>
  23. /// <returns></returns>
  24. public string GetBCRCode()
  25. {
  26. var barcode = Data.Content.Trim().Split('\0')[0];
  27. if (barcode.IsNullOrWhiteSpace()) throw new KnownException($"{Entity.Code}--扫码失败,内容为空", LogLevelEnum.High);
  28. return barcode;
  29. }
  30. }
  31. /// <summary>
  32. /// BCR扩展
  33. /// </summary>
  34. public static class BCRExtension
  35. {
  36. /// <summary>
  37. /// 获取BCR码
  38. /// </summary>
  39. /// <param name="bs"></param>
  40. /// <param name="code">BCR对应站点设备号</param>
  41. /// <returns></returns>
  42. public static string GetBCRCode(this List<BCR> bs, string code)
  43. {
  44. code = "BCR" + code;
  45. var bcr = bs.FirstOrDefault(p => p.Entity.Code == code) ?? throw new KnownException($"未找到扫码器{code}", LogLevelEnum.High);
  46. return bcr.GetBCRCode();
  47. }
  48. }
  49. }