CommandIO.cs 827 B

123456789101112131415161718192021222324252627282930
  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 CommandIO : IDeviceCommand
  11. {
  12. public byte TargetID { get; set; }
  13. public ushort Output { get; set; }
  14. protected byte[] buffer = new byte[14] { 0x10, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x03 };
  15. public byte[] Serialization()
  16. {
  17. var OutputBytes = BitConverter.GetBytes(Output);
  18. buffer[2] = TargetID;
  19. buffer[3] = OutputBytes[1];
  20. buffer[4] = OutputBytes[0];
  21. buffer[12] = buffer.XOR_Check(12);//异或
  22. return buffer;
  23. }
  24. }
  25. }