BCRExtension.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using PlcSiemens.Core.Extension;
  2. using WCS.Core;
  3. using WCS.Entity.Protocol.BCR;
  4. using WCS.WorkEngineering.Worlds.Logs;
  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('\r');
  27. if (barcode.IsNullOrWhiteSpace()) throw new KnownException($"{Entity.Code}--扫码失败,内容为空", LogLevelEnum.High);
  28. return barcode;
  29. }
  30. }
  31. /// <summary>
  32. /// BCR扩展
  33. /// </summary>
  34. public class BCRList : List<BCR>
  35. {
  36. /// <summary>
  37. /// 获取BCR码
  38. /// </summary>
  39. /// <param name="Code">BCR对应站点设备号</param>
  40. /// <returns></returns>
  41. public string GetBCRCode(string code)
  42. {
  43. code = "BCR" + code;
  44. var bcr = this.FirstOrDefault(p => p.Entity.Code == code) ?? throw new KnownException($"未找到扫码器{code}", LogLevelEnum.High);
  45. return bcr.GetBCRCode();
  46. }
  47. }
  48. }