Converter.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Runtime.InteropServices;
  6. using Aitex.Sorter.Common;
  7. using Aitex.Core.RT.SCCore;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. namespace Aitex.Core.Util
  11. {
  12. public static class Converter
  13. {
  14. ///// <summary>
  15. ///// Unit converter from physical to logical in linear formula
  16. ///// </summary>
  17. ///// <returns></returns>
  18. public static double Phy2Logic(double physicalValue, double logicalMin, double logicalMax, double physicalMin, double physicalMax)
  19. {
  20. var ret = (logicalMax - logicalMin) * (physicalValue - physicalMin) / (physicalMax - physicalMin) + logicalMin;
  21. //if (ret < logicalMin) ret = logicalMin;
  22. //if (ret > logicalMax) ret = logicalMax;
  23. if (double.IsNaN(ret)) throw new DivideByZeroException("Phy2Logic除0操作");
  24. return ret;
  25. }
  26. ///// <summary>
  27. ///// Unit converter from logical to physical in linear formula
  28. ///// </summary>
  29. ///// <returns></returns>
  30. public static double Logic2Phy(double logicalValue, double logicalMin, double logicalMax, double physicalMin, double physicalMax)
  31. {
  32. var ret = (physicalMax - physicalMin) * (logicalValue - logicalMin) / (logicalMax - logicalMin) + physicalMin;
  33. if (ret < physicalMin) ret = physicalMin;
  34. if (ret > physicalMax) ret = physicalMax;
  35. if (double.IsNaN(ret))
  36. throw new DivideByZeroException("Logic2Phy除0操作");
  37. return ret;
  38. }
  39. /// <summary>
  40. /// 只按占用的字节转换,不检查范围
  41. /// </summary>
  42. /// <param name="high"></param>
  43. /// <param name="low"></param>
  44. /// <returns></returns>
  45. public static float TwoUInt16ToFloat(UInt16 high, UInt16 low)
  46. {
  47. Int32 sum = (high << 16) + (low & 0xFFFF);
  48. byte[] bs = BitConverter.GetBytes(sum);
  49. return BitConverter.ToSingle(bs, 0);
  50. }
  51. public static int TwoInt16ToInt32(Int16 high, Int16 low)
  52. {
  53. UInt32 tmp = (ushort)low + (UInt32)(((ushort)high) << 16);
  54. return tmp > Int32.MaxValue ? (int)((~tmp + 1) * -1) : (int)tmp;////unsigned to signed
  55. }
  56. public static float TwoInt16ToFloat(Int16 high, Int16 low)
  57. {
  58. Int32 sum = (high << 16) + (low & 0xFFFF);
  59. byte[] bs = BitConverter.GetBytes(sum);
  60. return BitConverter.ToSingle(bs, 0);
  61. }
  62. public static Tuple<Pan, int[]> GetPanAndSlotFromPlace(Hand hand)
  63. {
  64. Pan pan = Pan.None;
  65. var handSlots = new int[] { (int)hand, ((int)hand) + 2 };
  66. var sourceSlots = new List<int>();
  67. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, handSlots[0]))
  68. {
  69. pan = Pan.Left;
  70. sourceSlots.Add(handSlots[0]);
  71. }
  72. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, handSlots[1]))
  73. {
  74. pan = Pan.Right;
  75. sourceSlots.Add(handSlots[1]);
  76. }
  77. if (sourceSlots.Count > 1) pan = Pan.Both;
  78. return new Tuple<Pan, int[]>(pan, sourceSlots.ToArray());
  79. }
  80. public static Tuple<Pan, int[]> GetPanAndSlotFromPick(Hand hand, int[] targetSlot)
  81. {
  82. int handSlot = (int)hand;
  83. if (!SC.IsDoubleFork) return new Tuple<Pan, int[]>(Pan.Left, new int[] { handSlot });
  84. if (targetSlot.Length > 1) return new Tuple<Pan, int[]>(Pan.Both, new int[] { handSlot, handSlot + 2 });
  85. if(targetSlot.Length == 1)
  86. {
  87. if(targetSlot[0] % 2 >0)
  88. return new Tuple<Pan, int[]>(Pan.Right, new int[] { handSlot + 2 });
  89. else
  90. return new Tuple<Pan, int[]>(Pan.Left, new int[] { handSlot });
  91. }
  92. return new Tuple<Pan, int[]>(Pan.None, null);
  93. }
  94. public static int[] MapBladeToSlots(Hand hand)
  95. {
  96. var slot = (int)hand;
  97. if (SC.IsDoubleFork)
  98. {
  99. return new int[] { slot, slot + 2 };
  100. }
  101. return new int[] { slot };
  102. }
  103. public static Hand MapSlotToHand(int slot)
  104. {
  105. return (Hand)(slot > 1 ? slot - 2 : slot);
  106. }
  107. public static int[] MapBladeAndPanToSlot(Hand hand, Pan pan)
  108. {
  109. var handSlot = (int)hand;
  110. if (pan == Pan.Left) return new int[] { handSlot };
  111. if (pan == Pan.Right) return new int[] { handSlot + 2 };
  112. if (pan == Pan.Both) return new int[] { handSlot, handSlot + 2 };
  113. return null;
  114. }
  115. public static int[] MapBladeAndPanToSlot(int blade, Pan pan)
  116. {
  117. return MapBladeAndPanToSlot((Hand)blade, pan);
  118. }
  119. public static int[] MapPanToPmSlot(Pan pan)
  120. {
  121. var result = new List<int>();
  122. if (pan == Pan.Left || pan == Pan.Both) result.Add(0);
  123. if (pan == Pan.Right || pan == Pan.Both) result.Add(1);
  124. if (pan == Pan.None) return null;
  125. return result.ToArray();
  126. }
  127. public static int[] MapPanToLLSlot(Pan pan, int[] sourceSlot)
  128. {
  129. var result = new List<int>();
  130. Array.Sort(sourceSlot);
  131. if (pan == Pan.Left || pan == Pan.Both) result.Add(sourceSlot[0]);
  132. if (pan == Pan.Right || pan == Pan.Both) result.Add(sourceSlot[1]);
  133. if (pan == Pan.None) return null;
  134. return result.ToArray();
  135. }
  136. private static Dictionary<Hand, Tuple<string, string, string>> _handToFork = new Dictionary<Hand, Tuple<string, string, string>>()
  137. {
  138. {Hand.Blade1,new Tuple<string, string, string>("A", "l", "r") },
  139. {Hand.Blade2,new Tuple<string, string, string>("B", "L", "R") },
  140. };
  141. public static string MapBladeAndPanToFork(Hand hand, Pan pan)
  142. {
  143. var forks = _handToFork[hand];
  144. if (pan == Pan.Both) return forks.Item1;
  145. if (pan == Pan.Right) return forks.Item2;
  146. return forks.Item3;
  147. }
  148. public static string MapBladeAndPanToFork(int hand, Pan pan)
  149. {
  150. var forks = _handToFork[(Hand)hand];
  151. if (pan == Pan.Both) return forks.Item1;
  152. if (pan == Pan.Right) return forks.Item2;
  153. return forks.Item3;
  154. }
  155. }
  156. }