CommunicationVcu.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Pms.Models;
  2. using ProjectManagementSystem.Common.Extenions;
  3. using ProjectManagementSystem.Common.WebApi;
  4. using ProjectManagementSystem.Device.Core;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace ProjectManagementSystem.Common.Core
  11. {
  12. public class CommunicationVcu : CommunicationBase, ICommunication
  13. {
  14. private static CommunicationVcu m_instance;
  15. private string addressName = "VCU";
  16. public static CommunicationVcu Instance
  17. {
  18. get
  19. {
  20. if (m_instance == null)
  21. {
  22. m_instance = new CommunicationVcu();
  23. }
  24. return m_instance;
  25. }
  26. }
  27. private CommunicationVcu()
  28. {
  29. }
  30. public void SendCommand(byte[] data, string address)
  31. {
  32. if (address == addressName)
  33. {
  34. int agvId = BitConverter.ToUInt16(data, 1);
  35. PmsApi.SendTransparentData(agvId, data);
  36. }
  37. }
  38. public void Received(byte[] data)
  39. {
  40. try
  41. {
  42. LogMsg($"{addressName}: Recv: {data.ToHexString()}");
  43. DataReceived?.Invoke(addressName, data);
  44. }
  45. catch (Exception ex)
  46. {
  47. LogMsg("接收VCU数据异常", ex);
  48. }
  49. }
  50. }
  51. }