FortrendPLUS500.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. using Aitex.Core.RT.SCCore;
  2. using MECF.Framework.Common.Communications;
  3. using MECF.Framework.Common.Equipment;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.IO.Ports;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace Venus_RT.Devices.SMIF
  12. {
  13. /// <summary>
  14. /// Fortrend PLUS 500
  15. /// Loader/Unloader
  16. /// 执行标准 E84
  17. /// </summary>
  18. public class FortrendPLUS500
  19. {
  20. private readonly Dictionary<FunctionType, StreamType> SFPair = new Dictionary<FunctionType, StreamType>()
  21. {
  22. //s1
  23. { FunctionType.Abort,StreamType.SMIFState},
  24. { FunctionType.Online,StreamType.SMIFState},
  25. { FunctionType.OnlineData,StreamType.SMIFState},
  26. { FunctionType.Map,StreamType.SMIFState},
  27. { FunctionType.MapData,StreamType.SMIFState},
  28. { FunctionType.Status,StreamType.SMIFState},
  29. { FunctionType.StatusData,StreamType.SMIFState},
  30. //s2
  31. { FunctionType.SetReport,StreamType.SMIFControl},
  32. { FunctionType.SetReportACK,StreamType.SMIFControl},
  33. { FunctionType.ResetORInit,StreamType.SMIFControl},
  34. { FunctionType.ResetORInitACK,StreamType.SMIFControl},
  35. { FunctionType.RemoteCommand,StreamType.SMIFControl},
  36. { FunctionType.RemoteCommandData,StreamType.SMIFControl},
  37. { FunctionType.CheckProto,StreamType.SMIFControl},
  38. { FunctionType.CheckProtoData,StreamType.SMIFControl},
  39. //s3
  40. { FunctionType.AccessMode,StreamType.LP},
  41. { FunctionType.AccessModeACK,StreamType.LP},
  42. //s4
  43. {FunctionType.ReadTag,StreamType.TAG},
  44. {FunctionType.ReadTagData,StreamType.TAG},
  45. {FunctionType.WriteTag,StreamType.TAG},
  46. {FunctionType.WriteTagData,StreamType.TAG},
  47. //s5
  48. {FunctionType.AlarmData,StreamType.ALARM },
  49. {FunctionType.AlarmACK,StreamType.ALARM },
  50. {FunctionType.SetAlarm,StreamType.ALARM },
  51. {FunctionType.SetAlarmACK,StreamType.ALARM },
  52. //s6
  53. {FunctionType.DataSend,StreamType.DVDATA},
  54. {FunctionType.DataSendACK,StreamType.DVDATA},
  55. //s9
  56. {FunctionType.UnrecognizedDeviceID,StreamType.COMMANDERROR},
  57. {FunctionType.UnrecognizedStream,StreamType.COMMANDERROR},
  58. {FunctionType.UnrecognizedFunction,StreamType.COMMANDERROR},
  59. {FunctionType.IllegalData,StreamType.COMMANDERROR},
  60. };
  61. public enum FunctionType
  62. {
  63. Abort = 0,
  64. Online = 1,
  65. OnlineData = 2,
  66. Map = 3,
  67. MapData = 4,
  68. Status = 5,
  69. StatusData = 6,
  70. SetReport = 15,
  71. SetReportACK = 16,
  72. ResetORInit = 19,
  73. ResetORInitACK = 20,
  74. RemoteCommand = 21,
  75. RemoteCommandData = 22,
  76. CheckProto = 25,
  77. CheckProtoData = 26,
  78. AccessMode = 27,
  79. AccessModeACK = 27,
  80. ReadTag = 101,
  81. ReadTagData = 102,
  82. WriteTag = 103,
  83. WriteTagData = 104,
  84. AlarmData = 1,
  85. AlarmACK = 2,
  86. SetAlarm = 3,
  87. SetAlarmACK = 4,
  88. DataSend = 3,
  89. DataSendACK = 4,
  90. UnrecognizedDeviceID = 1,
  91. UnrecognizedStream = 3,
  92. UnrecognizedFunction = 5,
  93. IllegalData = 7,
  94. }
  95. public enum StreamType
  96. {
  97. SMIFState = 1,
  98. SMIFControl = 2,
  99. LP = 3,
  100. TAG = 4,
  101. ALARM = 5,
  102. DVDATA = 6,
  103. COMMANDERROR = 9,
  104. RFIDCOMMAND= 18,
  105. SMARTTAG8400COMMAND = 100,
  106. }
  107. private AsyncSerialPort _serialport;
  108. private string _portname;
  109. //connect status
  110. public bool IsConnected;
  111. //online status
  112. public bool IsOnline;
  113. //Load
  114. public bool IsLoaded;
  115. //Lock
  116. public bool IsLocked;
  117. //Error
  118. public bool IsError;
  119. /// <summary>
  120. /// 构造函数
  121. /// </summary>
  122. /// <param name="DEVICEBelong">从属的设备 如VCE1 LP1</param>
  123. public FortrendPLUS500(ModuleName DEVICEBelong)
  124. {
  125. _portname = SC.GetStringValue($"{DEVICEBelong}.SMIF.PortNumber");
  126. _serialport = new AsyncSerialPort(_portname, 9600, 8,Parity.None,StopBits.One);
  127. _serialport.Open();
  128. _serialport.OnDataChanged += OnSMIFDataChanged;
  129. }
  130. //检查传入SxFy是否定义在字典中
  131. private bool CheckStreamFunctionPair(string sfstring)
  132. {
  133. string[] sfcodes = sfstring.Split('S','F');
  134. if (sfcodes.Length == 2
  135. && Enum.TryParse(Convert.ToInt32(sfcodes[0]).ToString(), out StreamType snum)
  136. && Enum.IsDefined(typeof(StreamType),snum)
  137. && Enum.TryParse(Convert.ToInt32(sfcodes[1]).ToString(), out FunctionType fnum)
  138. && Enum.IsDefined(typeof(FunctionType), fnum)
  139. && SFPair.TryGetValue(fnum,out StreamType _snum)
  140. && _snum == snum)
  141. {
  142. return true;
  143. }
  144. return false;
  145. }
  146. private void OnSMIFDataChanged(string oneLineMessage)
  147. {
  148. }
  149. public void Load()
  150. {
  151. }
  152. public void Unload()
  153. {
  154. }
  155. public void Lock()
  156. {
  157. }
  158. public void Unlock()
  159. {
  160. }
  161. public void ReadMap()
  162. {
  163. }
  164. /// <summary>
  165. /// 中断SMIF正在执行的操作
  166. /// </summary>
  167. public void Abort()
  168. {
  169. }
  170. }
  171. }