CommandBox.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using ProjectManagementSystem.Device.Core;
  2. using ProjectManagementSystem.Device.Extenions;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace ProjectManagementSystem.Device.Command
  9. {
  10. public class CommandBox : IDeviceCommand
  11. {
  12. protected byte[] buffer = new byte[14] { 0x10, 0x40, 0x30, 0x30, 0x30, 0x50, 0x30, 0x30, 0, 0, 0, 0, 0, 0x03 };
  13. public byte Function { get; set; }
  14. public int Address { get; set; }
  15. public int Spare { get; set; }
  16. public int Route { get; set; }
  17. public int Mark { get; set; }
  18. public byte MarkFunction { get; set; }
  19. public byte AgvId { get; set; }
  20. public virtual byte[] Serialization()
  21. {
  22. int route = 0x3030 + Route;
  23. buffer[1] = Function;
  24. buffer[3] = (byte)(Address + 0x30);
  25. //if (Spare > 0)
  26. //{
  27. // buffer[4] = (byte)((Spare + 80) / 256 + 0x30);
  28. // buffer[5] = (byte)((Spare + 80) % 256);
  29. //}
  30. if (Spare > 0)
  31. {
  32. int tempSpare = 0x3050 + Spare;
  33. buffer[4] = (byte)(tempSpare / 256);
  34. buffer[5] = (byte)(tempSpare % 256);
  35. }
  36. buffer[6] = (byte)((route >> 8) & 0xFF);
  37. buffer[7] = (byte)(route & 0xFF);
  38. buffer[8] = (byte)((Mark & 0xFF00) >> 8);
  39. buffer[9] = (byte)(Mark & 0x00FF);
  40. buffer[10] = MarkFunction;
  41. buffer[11] = AgvId;
  42. buffer[12] = buffer.XOR_Check(12);
  43. return buffer;
  44. }
  45. }
  46. }