BCRExtension.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. //public static string GetBCRCode(this List<IBCR81> bs, string code)
  49. //{
  50. // code = "BCR" + code;
  51. // var bcr = bs.FirstOrDefault(p => p. == code) ?? throw new KnownException($"未找到扫码器{code}", LogLevelEnum.High);
  52. // return bcr.GetBCRCode();
  53. //}
  54. }
  55. }