HiwinRobotConnection.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Aitex.Core.RT.Log;
  2. using MECF.Framework.Common.Communications;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.HiWin
  9. {
  10. public class HiwinRobotMessage : AsciiMessage
  11. {
  12. public string Data { get; set; }
  13. public string ErrorText { get; set; }
  14. }
  15. public class HiwinRobotConnection : TCPPortConnectionBase
  16. {
  17. private bool _isAckMode = false;//should read from config file
  18. public HiwinRobotConnection(string adress,string endof) : base(adress,endof,true)
  19. {
  20. }
  21. public override bool SendMessage(byte[] message)
  22. {
  23. return base.SendMessage(message);
  24. }
  25. protected override void ActiveHandlerProceedMessage(MessageBase msg)
  26. {
  27. lock (_lockerActiveHandler)
  28. {
  29. if (_activeHandler != null)
  30. {
  31. if(msg.IsFormatError|| (_activeHandler.HandleMessage(msg, out bool transactionComplete) && transactionComplete))
  32. {
  33. _activeHandler = null;
  34. }
  35. }
  36. }
  37. }
  38. protected override MessageBase ParseResponse(string rawText)
  39. {
  40. HiwinRobotMessage msg = new HiwinRobotMessage();
  41. msg.RawMessage = rawText;
  42. if (rawText.Length <= 0)
  43. {
  44. LOG.Error($"empty response");
  45. msg.IsFormatError = true;
  46. return msg;
  47. }
  48. rawText = rawText.Replace("\r", "").Replace("\n", "").Replace(">","");
  49. if (rawText.Contains("?"))
  50. {
  51. msg.IsError = true;
  52. msg.IsComplete = true;
  53. }
  54. msg.Data = rawText;
  55. msg.IsResponse = true;
  56. msg.IsAck = true;
  57. msg.IsComplete = true;
  58. return msg;
  59. }
  60. }
  61. }