123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Runtime.InteropServices;
- namespace Aitex.Core.Util
- {
- public static class Converter
- {
- /// <summary>
- /// Converts chamber Ids into Chinese string.
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- //public static string ToCstring(ChamberSet value)
- //{
- // switch (value)
- // {
- // case ChamberSet.ReactorA:
- // return "A腔";
- // case ChamberSet.ReactorB:
- // return "B腔";
- // case ChamberSet.ReactorC:
- // return "C腔";
- // case ChamberSet.ReactorD:
- // return "D腔";
- // case ChamberSet.Buffer1:
- // return "缓冲腔1";
- // case ChamberSet.Cooldown:
- // return "冷却腔";
- // case ChamberSet.Loadlock:
- // return "装卸腔";
- // case ChamberSet.Loadlock:
- // return "传送腔";
- // case ChamberSet.System:
- // return "系统";
- // default:
- // return "未知腔";
- // }
- //}
- ///// <summary>
- ///// Convert susceptor status
- ///// </summary>
- ///// <param name="status"></param>
- ///// <returns></returns>
- //public static string SusceptorStatus(SusceptorStatus status)
- //{
- // switch (status)
- // {
- // case Platform.SusceptorStatus.Empty: return "空盘";
- // case Platform.SusceptorStatus.Failed: return "运行出错";
- // case Platform.SusceptorStatus.InProcessing: return "正在运行";
- // case Platform.SusceptorStatus.Preprocessing: return "运行准备";
- // case Platform.SusceptorStatus.Processed: return "运行完毕";
- // case Platform.SusceptorStatus.Troubled: return "运行出错";
- // case Platform.SusceptorStatus.Unprocessed: return "未处理";
- // default:
- // return "未知";
- // }
- //}
- //public static string ToRoutineString(ChamberStateEnum routine)
- //{
- // switch (routine)
- // {
- // case ChamberStateEnum.Pump:
- // return "抽真空";
- // case ChamberStateEnum.Vent:
- // return "充气";
- // case ChamberStateEnum.CyclePurge:
- // return "循环吹扫";
- // case ChamberStateEnum.LeakCheck:
- // return "泄漏检查";
- // case ChamberStateEnum.Idle:
- // return "空闲";
- // case ChamberStateEnum.Error:
- // return "出错";
- // case ChamberStateEnum.Aborted:
- // return "空闲";
- // case ChamberStateEnum.Servoing:
- // return "伺服压力";
- // case ChamberStateEnum.Transferring:
- // return "传盘中";
- // }
- // return "未知";
- //}
- ///// <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>
- ///// Convert a structure to byte array
- ///// </summary>
- ///// <typeparam name="T">structure type</typeparam>
- ///// <param name="object1">structure object</param>
- ///// <returns></returns>
- //public static byte[] Structure2Bytes<T>(T object1)
- //{
- // int size = Marshal.SizeOf(typeof(T));
- // byte[] byteArr = new byte[size];
- // IntPtr ptr = Marshal.AllocHGlobal(size);
- // Marshal.StructureToPtr(object1, ptr, true);
- // Marshal.Copy(ptr, byteArr, 0, size);
- // Marshal.FreeHGlobal(ptr);
- // return byteArr;
- //}
- ///// <summary>
- ///// Convert a byte array to a structure
- ///// </summary>
- ///// <typeparam name="T">Structure type</typeparam>
- ///// <param name="byteArr">byte array</param>
- ///// <param name="offset">byte array start index</param>
- ///// <param name="length">effective byte length</param>
- ///// <returns></returns>
- //public static T Bytes2Structure<T>(byte[] byteArr, int offset, int length)
- //{
- // T object1;
- // IntPtr ptr = Marshal.AllocHGlobal(length);
- // Marshal.Copy(byteArr, offset, ptr, length);
- // object1 = (T)Marshal.PtrToStructure(ptr, typeof(T));
- // Marshal.FreeHGlobal(ptr);
- // return object1;
- //}
- ///// <summary>
- ///// 转换不成功返回-1
- ///// </summary>
- ///// <param name="indata"></param>
- ///// <returns></returns>
- //public static double DoubleConverter(string indata)
- //{
- // double ret = -1;
- // double.TryParse(indata, out ret);
- // return ret;
-
- //}
- /// <summary>
- /// Convert DeviceNet mac number to status string
- /// 0 = No error
- /// 1 = Station deactivated
- /// 2 = Station not exists
- /// 18 = Station ready
- /// 31 = only for EtherCAT gateways: WC-State of cyclic EtherCAT frame is 1
- /// 40 = Heartbeat Message not received
- /// 41 = Shutdown Message received
- /// 42 = Electronic Key Fault: Vendor Id
- /// 43 = Electronic Key Fault: Device Type
- /// 44 = Electronic Key Fault: Product Code
- /// 45 = Electronic Key Fault: Revision
- /// 46 = Fault while writing Start-Up Attributs
- /// 47 = wrong Produced IO-Data Size
- /// 48 = wrong Consumed IO-Data Size
- /// 49 = Idle Mode (for Slave Devices): no valid IO-Data is exchanged via DeviceNet
- /// </summary>
- /// <param name="macStatusInt"></param>
- /// <returns></returns>
- public static string MacStatus(int macStatusInt)
- {
- string ret = "未知错误代码" + macStatusInt.ToString();
- switch (macStatusInt)
- {
- case 0: ret = "No error"; break;
- case 1: ret = "Station deactivated"; break;
- case 2: ret = "Station not exists"; break;
- case 18: ret = "Station ready"; break;
- case 31: ret = "only for EtherCAT gateways: WC-State of cyclic EtherCAT frame is 1"; break;
- case 40: ret = "Heartbeat Message not received"; break;
- case 41: ret = "Shutdown Message received"; break;
- case 42: ret = "Electronic Key Fault: Vendor Id"; break;
- case 43: ret = "Electronic Key Fault: Device Type"; break;
- case 44: ret = "Electronic Key Fault: Product Code"; break;
- case 45: ret = "Electronic Key Fault: Revision"; break;
- case 46: ret = "Fault while writing Start-Up Attributs"; break;
- case 47: ret = "wrong Produced IO-Data Size"; break;
- case 48: ret = "wrong Consumed IO-Data Size"; break;
- case 49: ret = "Idle Mode (for Slave Devices): no valid IO-Data is exchanged via DeviceNet"; break;
- }
- return ret;
- }
-
- //public static string GetShowCommandString(string command)
- //{
- // switch ((command+"").ToLower())
- // {
- // case "tmllgatevalve": return "装卸腔闸板阀开关";
- // case "tmreactoragate": return "反应腔A闸板阀开关";
- // case "tmreactorbgate": return "反应腔B闸板阀开关";
- // case "tmreactorcgate": return "反应腔C闸板阀开关";
- // case "tmreactordgate": return "反应腔D闸板阀开关";
- // }
- // return "";
- //}
- public static string MFCDisplay(double value)
- {
- if (value >= 10000)
- return value.ToString("F0");
- else if (value >= 10)
- return value.ToString("0.0");
- else
- return value.ToString("0.00");
- }
- }
- }
|