BCRExtension.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using PlcSiemens.Core.Extension;
  2. using ServiceCenter.Logs;
  3. using WCS.Core;
  4. using WCS.Entity.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.RemoveEscapeCharacters();
  27. if (barcode.IsNullOrWhiteSpace()) throw new KnownException($"{Entity.Code}--扫码失败,内容为空", LogLevelEnum.High);
  28. return barcode;
  29. }
  30. }
  31. /// <summary>
  32. /// BCR83
  33. /// </summary>
  34. public class BCR83 : Device<IBCR83>
  35. {
  36. /// <summary>
  37. /// BCR扩展
  38. /// </summary>
  39. /// <param name="device"></param>
  40. /// <param name="world"></param>
  41. public BCR83(Device device, World world) : base(device, world)
  42. {
  43. }
  44. /// <summary>
  45. /// 获取BCR码
  46. /// </summary>
  47. /// <returns></returns>
  48. public string GetBCRCode()
  49. {
  50. var barcode = Data.BcrCode.RemoveEscapeCharacters();
  51. if (barcode.IsNullOrWhiteSpace()) throw new KnownException($"{Entity.Code}--扫码失败,内容为空", LogLevelEnum.High);
  52. return barcode;
  53. }
  54. }
  55. /// <summary>
  56. /// BCR扩展
  57. /// </summary>
  58. public static class BCRExtension
  59. {
  60. /// <summary>
  61. /// 获取BCR码
  62. /// </summary>
  63. /// <param name="bs"></param>
  64. /// <param name="code">BCR对应站点设备号</param>
  65. /// <returns></returns>
  66. public static string GetBCRCode(this List<BCR> bc, string code)
  67. {
  68. code = "BCR" + code;
  69. var bcr = bc.FirstOrDefault(p => p.Entity.Code == code) ?? throw new KnownException($"未找到扫码器{code}", LogLevelEnum.High);
  70. return bcr.GetBCRCode();
  71. }
  72. ///// <summary>
  73. ///// 获取BCR83码集合
  74. ///// </summary>
  75. ///// <param name="bc"></param>
  76. ///// <returns></returns>
  77. //public static string GetBCRCodeList(this BCR83 bc)
  78. //{
  79. //}
  80. }
  81. }