CognexConnection.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.Util;
  3. using MECF.Framework.Common.Communications;
  4. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Text.RegularExpressions;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.OcrReaders.Cognex
  13. {
  14. public class CognexOCRMessage : AsciiMessage
  15. {
  16. public string Data { get; set; }
  17. }
  18. public class CognexOCRConnection : TCPPortConnectionBase
  19. {
  20. private CognexWaferIDReader _reader;
  21. public CognexOCRConnection(string addr,CognexWaferIDReader reader) : base(addr,"")
  22. {
  23. _reader = reader;
  24. }
  25. protected override MessageBase ParseResponse(string rawText)
  26. {
  27. CognexOCRMessage msg = new CognexOCRMessage();
  28. if (rawText.Contains("User:"))
  29. {
  30. SendMessage("admin\r\n");
  31. msg.IsResponse = false;
  32. msg.IsAck = false;
  33. msg.IsComplete = false;
  34. return msg;
  35. }
  36. if (rawText.Contains("Welcome to In-Sight"))
  37. {
  38. msg.IsResponse = false;
  39. msg.IsAck = false;
  40. msg.IsComplete = false;
  41. return msg;
  42. }
  43. if (rawText.Contains("Password:"))
  44. {
  45. SendMessage("\r\n");
  46. //SendMessage("admin\r\n");
  47. msg.IsResponse = false;
  48. msg.IsAck = false;
  49. msg.IsComplete = false;
  50. return msg;
  51. }
  52. if (rawText.Contains("User Logged In"))
  53. {
  54. _reader.IsLogined = true;
  55. //SendMessage("admin\r\n");
  56. msg.IsResponse = false;
  57. msg.IsAck = false;
  58. msg.IsComplete = false;
  59. return msg;
  60. }
  61. if (rawText.Contains("Invalid Password"))
  62. {
  63. _reader.IsLogined = false;
  64. //_reader.OnError(rawText);
  65. SendMessage("admin\r\n");
  66. msg.IsResponse = false;
  67. msg.IsAck = false;
  68. msg.IsComplete = false;
  69. return msg;
  70. }
  71. msg.IsNak = false;
  72. msg.IsResponse = false;
  73. msg.IsAck = false;
  74. msg.IsComplete = false;
  75. string tempdata = Regex.Split(rawText, "\r\n").FirstOrDefault().Replace("\r","").Replace("\n","");
  76. msg.RawMessage = rawText;
  77. msg.Data = rawText;
  78. if (tempdata.Contains("Welcome"))
  79. {
  80. msg.IsAck = true;
  81. }
  82. if (tempdata == "1")
  83. {
  84. msg.IsAck = true;
  85. }
  86. else if(tempdata == "-2")
  87. {
  88. msg.IsNak = true;
  89. }
  90. else
  91. {
  92. msg.IsResponse = true;
  93. }
  94. msg.Data = rawText;
  95. return msg;
  96. }
  97. }
  98. }