123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Runtime.InteropServices;
- using Aitex.Sorter.Common;
- using Aitex.Core.RT.SCCore;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- namespace Aitex.Core.Util
- {
- public static class Converter
- {
- ///// <summary>
- ///// Unit converter from physical to logical in linear formula
- ///// </summary>
- ///// <returns></returns>
- public static double Phy2Logic(double physicalValue, double logicalMin, double logicalMax, double physicalMin, double physicalMax)
- {
- var ret = (logicalMax - logicalMin) * (physicalValue - physicalMin) / (physicalMax - physicalMin) + logicalMin;
- //if (ret < logicalMin) ret = logicalMin;
- //if (ret > logicalMax) ret = logicalMax;
- if (double.IsNaN(ret)) throw new DivideByZeroException("Phy2Logic除0操作");
- return ret;
- }
- ///// <summary>
- ///// Unit converter from logical to physical in linear formula
- ///// </summary>
- ///// <returns></returns>
- public static double Logic2Phy(double logicalValue, double logicalMin, double logicalMax, double physicalMin, double physicalMax)
- {
- var ret = (physicalMax - physicalMin) * (logicalValue - logicalMin) / (logicalMax - logicalMin) + physicalMin;
- if (ret < physicalMin) ret = physicalMin;
- if (ret > physicalMax) ret = physicalMax;
- if (double.IsNaN(ret))
- throw new DivideByZeroException("Logic2Phy除0操作");
- return ret;
- }
- /// <summary>
- /// 只按占用的字节转换,不检查范围
- /// </summary>
- /// <param name="high"></param>
- /// <param name="low"></param>
- /// <returns></returns>
- public static float TwoUInt16ToFloat(UInt16 high, UInt16 low)
- {
- Int32 sum = (high << 16) + (low & 0xFFFF);
- byte[] bs = BitConverter.GetBytes(sum);
- return BitConverter.ToSingle(bs, 0);
- }
- public static int TwoInt16ToInt32(Int16 high, Int16 low)
- {
- UInt32 tmp = (ushort)low + (UInt32)(((ushort)high) << 16);
- return tmp > Int32.MaxValue ? (int)((~tmp + 1) * -1) : (int)tmp;////unsigned to signed
- }
-
- public static float TwoInt16ToFloat(Int16 high, Int16 low)
- {
- Int32 sum = (high << 16) + (low & 0xFFFF);
- byte[] bs = BitConverter.GetBytes(sum);
- return BitConverter.ToSingle(bs, 0);
- }
- public static Tuple<Pan, int[]> GetPanAndSlotFromPlace(Hand hand)
- {
- Pan pan = Pan.None;
- var handSlots = new int[] { (int)hand, ((int)hand) + 2 };
- var sourceSlots = new List<int>();
- if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, handSlots[0]))
- {
- pan = Pan.Left;
- sourceSlots.Add(handSlots[0]);
- }
- if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, handSlots[1]))
- {
- pan = Pan.Right;
- sourceSlots.Add(handSlots[1]);
- }
- if (sourceSlots.Count > 1) pan = Pan.Both;
- return new Tuple<Pan, int[]>(pan, sourceSlots.ToArray());
- }
- public static Tuple<Pan, int[]> GetPanAndSlotFromPick(Hand hand, int[] targetSlot)
- {
- int handSlot = (int)hand;
- if (!SC.IsDoubleFork) return new Tuple<Pan, int[]>(Pan.Left, new int[] { handSlot });
- if (targetSlot.Length > 1) return new Tuple<Pan, int[]>(Pan.Both, new int[] { handSlot, handSlot + 2 });
- if(targetSlot.Length == 1)
- {
- if(targetSlot[0] % 2 >0)
- return new Tuple<Pan, int[]>(Pan.Right, new int[] { handSlot + 2 });
- else
- return new Tuple<Pan, int[]>(Pan.Left, new int[] { handSlot });
- }
- return new Tuple<Pan, int[]>(Pan.None, null);
- }
- public static int[] MapBladeToSlots(Hand hand)
- {
- var slot = (int)hand;
- if (SC.IsDoubleFork)
- {
- return new int[] { slot, slot + 2 };
- }
- return new int[] { slot };
- }
- public static Hand MapSlotToHand(int slot)
- {
- return (Hand)(slot > 1 ? slot - 2 : slot);
- }
- public static int[] MapBladeAndPanToSlot(Hand hand, Pan pan)
- {
- var handSlot = (int)hand;
- if (pan == Pan.Left) return new int[] { handSlot };
- if (pan == Pan.Right) return new int[] { handSlot + 2 };
- if (pan == Pan.Both) return new int[] { handSlot, handSlot + 2 };
- return null;
- }
- public static int[] MapBladeAndPanToSlot(int blade, Pan pan)
- {
- return MapBladeAndPanToSlot((Hand)blade, pan);
- }
- public static int[] MapPanToPmSlot(Pan pan)
- {
- var result = new List<int>();
- if (pan == Pan.Left || pan == Pan.Both) result.Add(0);
- if (pan == Pan.Right || pan == Pan.Both) result.Add(1);
- if (pan == Pan.None) return null;
- return result.ToArray();
- }
- public static int[] MapPanToLLSlot(Pan pan, int[] sourceSlot)
- {
- var result = new List<int>();
- Array.Sort(sourceSlot);
- if (pan == Pan.Left || pan == Pan.Both) result.Add(sourceSlot[0]);
- if (pan == Pan.Right || pan == Pan.Both) result.Add(sourceSlot[1]);
- if (pan == Pan.None) return null;
- return result.ToArray();
- }
- private static Dictionary<Hand, Tuple<string, string, string>> _handToFork = new Dictionary<Hand, Tuple<string, string, string>>()
- {
- {Hand.Blade1,new Tuple<string, string, string>("A", "l", "r") },
- {Hand.Blade2,new Tuple<string, string, string>("B", "L", "R") },
- };
- public static string MapBladeAndPanToFork(Hand hand, Pan pan)
- {
- var forks = _handToFork[hand];
- if (pan == Pan.Both) return forks.Item1;
- if (pan == Pan.Right) return forks.Item2;
- return forks.Item3;
- }
- public static string MapBladeAndPanToFork(int hand, Pan pan)
- {
- var forks = _handToFork[(Hand)hand];
- if (pan == Pan.Both) return forks.Item1;
- if (pan == Pan.Right) return forks.Item2;
- return forks.Item3;
- }
- }
- }
|