FortrendPLUS500.cs 7.1 KB

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