| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539 | 
							- using Aitex.Core.RT.DataCenter;
 
- using Aitex.Core.RT.Device;
 
- using Aitex.Core.RT.Event;
 
- using Aitex.Core.RT.Log;
 
- using Aitex.Core.RT.OperationCenter;
 
- using Aitex.Core.RT.Routine;
 
- using Aitex.Core.RT.SCCore;
 
- using Aitex.Core.Util;
 
- using MECF.Framework.Common.Beckhoff.AxisProvider;
 
- using MECF.Framework.Common.Beckhoff.IOAxis;
 
- using MECF.Framework.Common.Beckhoff.Station;
 
- using MECF.Framework.Common.CommonData.PUF;
 
- using MECF.Framework.Common.TwinCat;
 
- using MECF.Framework.Common.Utilities;
 
- using CyberX8_Core;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Reflection;
 
- using System.Text;
 
- using System.Threading;
 
- using System.Threading.Tasks;
 
- using System.Timers;
 
- using CommunityToolkit.HighPerformance.Buffers;
 
- using System.Windows.Documents;
 
- using MECF.Framework.Common.Device.Galil;
 
- namespace CyberX8_RT.Devices.AXIS
 
- {
 
-     public abstract class JetAxisBase : BaseDevice, IDevice
 
-     {
 
-         #region 常量
 
-         private const string STATUS_WORD = "StatusWord";
 
-         private const string DIGITAL_INPUTS="DigitalInputs";
 
-         private const string CONTROL_WORD = "ControlWord";
 
-         private const string MODE_OF_OPERATION = "ModeOfOperation";
 
-         protected const string PROFILE_VELOCITY = "ProfileVelocity";
 
-         protected const string PROFILE_ACCEL = "ProfileAccel";
 
-         protected const string PROFILE_DECEL = "ProfileDecel";
 
-         private const string TARGET_POSITION = "TargetPosition";
 
-         private const string MOTOR_POSITION = "MotorPosition";
 
-         private const string ACTUAL_VELOCITY = "ActualVelocity";
 
-         private const string ACTUAL_TORQUE = "ActualTorque";
 
-         private const string POSITION_ERROR = "PositionError";
 
-         private const string MOTION_DATA = "MotionData";
 
-         private const string CURRENT_STATION = "CurrentStation";
 
-         protected const string CURRENT_STATION_LIST = "CurrentStationList";
 
-         private const string IS_SWITCH_ON = "IsSwitchOn";
 
-         private const string HOME_OFFSET = "HomeOffset";
 
-         private const string HOMING_METHOD = "HomingMethod";
 
-         protected const string HOMING_VELOCITY = "HomingVelocity";
 
-         protected const string HOMING_VELOCITY_SLOW = "HomingVelocitySlow";
 
-         protected const string HOMING_ACCEL = "HomingAccel";
 
-         private const string NEGATIVE_TORQUE_LIMIT="NegativeTorqueLimit";
 
-         private const string POSITIVE_TORQUE_LIMIT = "PositiveTorqueLimit";
 
-         private const string MANUF_STATUS="ManufStatus";
 
-         private const string SOFTWARE_LIMIT_MINUS= "SoftwareLimitMinus";
 
-         private const string SOFTWARE_LIMIT_PLUS = "SoftwareLimitPlus";
 
-         private const string STOP_CODE = "StopCode";
 
-         #endregion
 
-         #region 内部变量
 
-         /// <summary>
 
-         /// 比例因子
 
-         /// </summary>
 
-         private double _scaleFactor = 0;
 
-         /// <summary>
 
-         /// jog限制
 
-         /// </summary>
 
-         private double _jogLimit = 0;
 
-         /// <summary>
 
-         /// 当前位置数值(用于判定是否正在运动)
 
-         /// </summary>
 
-         private int _currentLocation = 0;
 
-         /// <summary>
 
-         /// 是否运动
 
-         /// </summary>
 
-         private bool _isRun = false;
 
-         /// <summary>
 
-         /// 当前位置
 
-         /// </summary>
 
-         private string _currentStation = "";
 
-         /// <summary>
 
-         /// 当前位置集合(多个位置共用一个数值)
 
-         /// </summary>
 
-         private List<string> _currentStationList = new List<string>();
 
-         /// <summary>
 
-         /// 当前位置锁
 
-         /// </summary>
 
-         private object _locationLocker = new object();
 
-         /// <summary>
 
-         /// 工位位置对象
 
-         /// </summary>
 
-         private BeckhoffStationAxis _stationAxis;
 
-         /// <summary>
 
-         /// 运动时间
 
-         /// </summary>
 
-         private DateTime _runTime = DateTime.Now;
 
-         /// <summary>
 
-         /// 尺寸
 
-         /// </summary>
 
-         private int _waferSize = 0;
 
-         /// <summary>
 
-         /// inter lock
 
-         /// </summary>
 
-         private IAxisInterLock _interLock;
 
-         /// <summary>
 
-         /// 是否存在Rev Sensor Limit
 
-         /// </summary>
 
-         private bool _isRevSensorLimit = false;
 
-         /// <summary>
 
-         /// 是否存在Forward Limit
 
-         /// </summary>
 
-         private bool _isForwardSensorLimit = false;
 
-         /// <summary>
 
-         /// Home Switched是否触发
 
-         /// </summary>
 
-         private bool _isHomeSwitchedTrigger = false;
 
-         /// <summary>
 
-         /// 变量是否初始化字典
 
-         /// </summary>
 
-         private Dictionary<string, bool> _variableInitializeDic = new Dictionary<string, bool>();
 
-         #endregion
 
-         #region protected 字段
 
-         /// <summary>
 
-         /// 轴参数对象
 
-         /// </summary>
 
-         protected GalilAxisConfig _galilAxisConfig = null;
 
-         /// <summary>
 
-         /// 状态
 
-         /// </summary>
 
-         protected RState _status;
 
-         /// <summary>
 
-         /// 当前操作
 
-         /// </summary>
 
-         protected MotionOperation _currentOperation = MotionOperation.None;
 
-         /// <summary>
 
-         /// 模式
 
-         /// </summary>
 
-         protected byte _modeOfOperation;
 
-         /// <summary>
 
-         /// 状态字
 
-         /// </summary>
 
-         protected ushort _statusWord;
 
-         /// <summary>
 
-         /// 控制字
 
-         /// </summary>
 
-         protected ushort _controlWord;
 
-         /// <summary>
 
-         /// 运动数据对象
 
-         /// </summary>
 
-         protected CommandMotionData _commandMotionData = new CommandMotionData();
 
-         /// <summary>
 
-         /// Home状态
 
-         /// </summary>
 
-         protected bool _isHomed;
 
-         /// <summary>
 
-         /// SwitchOn状态
 
-         /// </summary>
 
-         protected bool _isSwitchOn;
 
-         /// <summary>
 
-         /// 是否错误
 
-         /// </summary>
 
-         protected bool _isError;
 
-         /// <summary>
 
-         /// 是否到达目标位置
 
-         /// </summary>
 
-         protected bool _inTargetPosition = false;
 
-         /// <summary>
 
-         /// 初始化的速度
 
-         /// </summary>
 
-         protected int _initialVelocity = 0;
 
-         /// <summary>
 
-         /// 初始化的加速度
 
-         /// </summary>
 
-         protected int _initialAcceleration = 0;
 
-         /// <summary>
 
-         /// 初始化的减速度
 
-         /// </summary>
 
-         protected int _initialDeceleration = 0;
 
-         /// <summary>
 
-         /// 运动速度
 
-         /// </summary>
 
-         protected int _profileVelocity = 0;
 
-         /// <summary>
 
-         /// 运动加速度
 
-         /// </summary>
 
-         protected int _profileAcceleration = 0;
 
-         /// <summary>
 
-         /// 运动减速度
 
-         /// </summary>
 
-         protected int _profileDeceleration = 0;
 
-         /// <summary>
 
-         /// 负向Torque限制
 
-         /// </summary>
 
-         protected int _profileNegativeTorqueLimit = 0;
 
-         /// <summary>
 
-         /// 正向Torque限制
 
-         /// </summary>
 
-         protected int _profilePositiveTorqueLimit = 0;
 
-         /// <summary>
 
-         /// Homing 速度
 
-         /// </summary>
 
-         protected int _profileHomingVelocity = 0;
 
-         /// <summary>
 
-         /// Homing 速度Slow
 
-         /// </summary>
 
-         protected int _profileHomingVelocitySlow = 0;
 
-         /// <summary>
 
-         /// Homing加速度
 
-         /// </summary>
 
-         protected int _profileHomingAccel = 0;
 
-         /// <summary>
 
-         /// <summary>
 
-         /// 目标位置
 
-         /// </summary>
 
-         protected double _targetPosition = 0.0;
 
-         /// <summary>
 
-         /// home超时时长
 
-         /// </summary>
 
-         protected int _homeTimeout = 5000;
 
-         /// <summary>
 
-         /// coe输出变量集合
 
-         /// </summary>
 
-         protected List<string> _coeOutputs = new List<string>();
 
-         /// <summary>
 
-         /// 速度比例
 
-         /// </summary>
 
-         protected int _speedRatio = 1;
 
-         /// <summary>
 
-         /// 加速度的比例
 
-         /// </summary>
 
-         protected int _accelerationRatio = 1;
 
-         /// <summary>
 
-         /// torque比例
 
-         /// </summary>
 
-         protected int _torqueRatio = 1000;
 
-         /// <summary>
 
-         /// Motion Position比例
 
-         /// </summary>
 
-         protected double _motionPositionRation = 1;
 
-         #endregion
 
-         #region 属性
 
-         /// <summary>
 
-         /// 状态
 
-         /// </summary>
 
-         public RState Status { get { return _status; } }
 
-         /// <summary>
 
-         /// Home状态
 
-         /// </summary>
 
-         public bool IsHomed { get { return _isHomed; } set { _isHomed = value; } }
 
-         /// <summary>
 
-         /// SwitchOn状态
 
-         /// </summary>
 
-         public bool IsSwitchOn { get { return _isSwitchOn; } }
 
-         /// <summary>
 
-         /// 模式
 
-         /// </summary>
 
-         public byte ModeOfOperation { get { return _modeOfOperation; } }
 
-         /// <summary>
 
-         /// 控制字
 
-         /// </summary>
 
-         public ushort ControlWord { get { return _controlWord; } }
 
-         /// <summary>
 
-         /// 是否运动中
 
-         /// </summary>
 
-         public bool IsRun { get { return _isRun; } }
 
-         /// <summary>
 
-         /// 当前位置
 
-         /// </summary>
 
-         public string CurrentStation { get { return _currentStation; } }
 
-         /// <summary>
 
-         /// 是否到达目标位置
 
-         /// </summary>
 
-         public bool InTargetPosition { get { return _inTargetPosition; } }
 
-         /// <summary>
 
-         /// 运动数据对象
 
-         /// </summary>
 
-         public CommandMotionData MotionData { get { return _commandMotionData; } }
 
-         /// <summary>
 
-         /// 负向Torque限制数值
 
-         /// </summary>
 
-         public int NegativeTorqueLimit { get { return _profileNegativeTorqueLimit; } }
 
-         /// <summary>
 
-         /// 正向Torque限制数值
 
-         /// </summary>
 
-         public int PositiveTorqueLimit { get { return _profilePositiveTorqueLimit; } }
 
-         /// <summary>
 
-         /// 是否错误
 
-         /// </summary>
 
-         public bool IsError { get { return _isError; } }
 
-         /// <summary>
 
-         /// 目标位置
 
-         /// </summary>
 
-         public double TargetPosition { get { return _targetPosition; } }
 
-         /// <summary>
 
-         /// 加速度
 
-         /// </summary>
 
-         public double ProfileAcceleration { get { return _profileAcceleration; } }
 
-         /// <summary>
 
-         /// 减速度
 
-         /// </summary>
 
-         public double ProfileDeceleration { get { return _profileDeceleration; } }
 
-         /// <summary>
 
-         /// inter lock接口对象
 
-         /// </summary>
 
-         public IAxisInterLock InterLock { set { _interLock= value; } }
 
-         /// <summary>
 
-         /// 是否存在Sensor Limit
 
-         /// </summary>
 
-         public bool IsRevSensorLimit { set { _isRevSensorLimit = value; } }
 
-         /// <summary>
 
-         /// 是否存在正向Sensor Limit
 
-         /// </summary>
 
-         public bool IsForwardSensorLimit { set { _isForwardSensorLimit = value; } }
 
-         /// <summary>
 
-         /// Home Switch是否触发
 
-         /// </summary>
 
-         public bool IsHomeSwitchedTriggered { get { return _isHomeSwitchedTrigger; } set { _isHomeSwitchedTrigger = value; } }
 
-         /// <summary>
 
-         /// 所有io变量是否初始化
 
-         /// </summary>
 
-         public bool IOInitialized { get { return AllIoVariableInitialized(); } }
 
-         /// <summary>
 
-         /// WaferSize
 
-         /// </summary>
 
-         public int WaferSize { get { return _waferSize; }  set { _waferSize = value; } }
 
-         #endregion
 
-         /// <summary>
 
-         /// 构造函数
 
-         /// </summary>
 
-         /// <param name="moduleName"></param>
 
-         /// <param name="name"></param>
 
-         public JetAxisBase(string moduleName,string name) : base(moduleName, name,name,name)
 
-         {
 
-             InitializeParameter();
 
-             LoadStation();
 
-             InitializeRoutine();
 
-             SubscribeData();
 
-             InitializeOperation();
 
-         }
 
-         #region private方法
 
-         /// <summary>
 
-         /// 加载Station位置
 
-         /// </summary>
 
-         private void LoadStation()
 
-         {
 
-             _waferSize = SC.GetValue<int>("System.WaferSize");
 
-             _stationAxis = BeckhoffStationLocationManager.Instance.GetStationAxis(Module, Name, _waferSize);
 
-         }
 
-         /// <summary>
 
-         /// 订阅数据
 
-         /// </summary>
 
-         private void SubscribeData()
 
-         {
 
-             BeckhoffProviderAxis beckhoffProviderAxis = BeckhoffAxisProviderManager.Instance.GetAxisProvider($"{Module}.{Name}");
 
-             if (beckhoffProviderAxis != null)
 
-             {
 
-                 _scaleFactor = beckhoffProviderAxis.ScaleFactor;
 
-                 _jogLimit = beckhoffProviderAxis.JogLimit;
 
-                 _motionPositionRation = beckhoffProviderAxis.MotorPositionRate;
 
-             }
 
-             _galilAxisConfig = GalilControllerCfgManager.Instance.GetGalilAxisConfig(Module.ToString(),Name);
 
-             if (_galilAxisConfig != null)
 
-             {
 
-                 _profileVelocity =CalculateMultiplySpeedRatio(_galilAxisConfig.Speed);
 
-                 _initialVelocity = _profileVelocity;
 
-                 _profileAcceleration = CalculateDivideAccelerationRatio(_galilAxisConfig.Acceleration);
 
-                 _initialAcceleration = _profileAcceleration;
 
-                 _profileDeceleration = CalculateDivideAccelerationRatio(_galilAxisConfig.Deceleration);
 
-                 _initialDeceleration = _profileDeceleration;
 
-                 _profileNegativeTorqueLimit = _galilAxisConfig.NegativeTorqueLimit;
 
-                 _profilePositiveTorqueLimit = _galilAxisConfig.PositiveTorqueLimit;
 
-                 _commandMotionData.FileAcceleration = CalculateValueAfterScale(_galilAxisConfig.Acceleration);
 
-                 _commandMotionData.FileDeceleration = CalculateValueAfterScale(_galilAxisConfig.Deceleration);
 
-                 _commandMotionData.HomeOffset = CalculateValueAfterScale(_galilAxisConfig.HomingOffset);
 
-                 _commandMotionData.FileHomingAccel = CalculateValueAfterScale(_galilAxisConfig.HomingAcceleration);
 
-                 _commandMotionData.FileHomingVelocitySlow = CalculateValueAfterScale(_galilAxisConfig.HomingSpeed);
 
-                 _commandMotionData.FileHomingVelocity = CalculateValueAfterScale(_galilAxisConfig.HomingSpeed);
 
-                 _commandMotionData.FileProfileVelocity = CalculateValueAfterScale(_galilAxisConfig.Speed);
 
-                 _commandMotionData.FwdSoftLimit = CalculateValueAfterScale(_galilAxisConfig.ForwardSoftwareLimit)-_commandMotionData.HomeOffset;
 
-                 _commandMotionData.RevSoftLimit = CalculateValueAfterScale(_galilAxisConfig.ReverseSoftwareLimit)-_commandMotionData.HomeOffset;
 
-                 _commandMotionData.NegativeTorqueLimit = _galilAxisConfig.NegativeTorqueLimit;
 
-                 _commandMotionData.PositiveTorqueLimit = _galilAxisConfig.PositiveTorqueLimit;
 
-                 if (_galilAxisConfig.NegativeTorqueLimit != 0 || _galilAxisConfig.PositiveTorqueLimit != 0)
 
-                 {
 
-                     _commandMotionData.TorqueLimit = $"-{_galilAxisConfig.NegativeTorqueLimit}/+{_galilAxisConfig.PositiveTorqueLimit}";
 
-                 }
 
-                 if(_galilAxisConfig.HomingTimeOut!=0)
 
-                 {
 
-                     _homeTimeout = _galilAxisConfig.HomingTimeOut;
 
-                 }
 
-             }
 
-             DATA.Subscribe($"{Module}.{Name}.{MOTION_DATA}", () => _commandMotionData,SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{Name}.{MOTOR_POSITION}", () => _commandMotionData.MotorPosition,SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{Name}.ProfileVelocity", () => _commandMotionData.ProfileVelocity, SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{Name}.Acceleration",()=>_commandMotionData.FileAcceleration,SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{Name}.Deceleration",()=>_commandMotionData.FileDeceleration,SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{Name}.ActualTorque",()=>_commandMotionData.ActualTorque,SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{Name}.{CURRENT_STATION}", () => _currentStation,SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{Name}.{CURRENT_STATION_LIST}", () => _currentStationList, SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{Name}.{IS_SWITCH_ON}", () => IsSwitchOn, SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{Name}.IsHomed", () => IsHomed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{Name}.IsError",()=>IsError, SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{Name}.IsMoving", () => _isRun, SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{Name}.IsRun", () => _isRun, SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-         }
 
-         /// <summary>
 
-         /// 初始化操作
 
-         /// </summary>
 
-         private void InitializeOperation()
 
-         {
 
-             OP.Subscribe($"{Module}.{Name}.{MotionOperation.SwitchOn}", (cmd, args) => { SwitchOn(); return true; });
 
-             OP.Subscribe($"{Module}.{Name}.{MotionOperation.SwitchOff}", (cmd, args) => { SwitchOff(); return true; });
 
-             OP.Subscribe($"{Module}.{Name}.{MotionOperation.Home}", (cmd, args) => { Home(); return true; });
 
-             OP.Subscribe($"{Module}.{Name}.JogUp", JogUpPosition);
 
-             OP.Subscribe($"{Module}.{Name}.JogDown", JogDownPosition);
 
-             OP.Subscribe($"{Module}.{Name}.{MotionOperation.KeyDown}", KeyDownOperation);
 
-             OP.Subscribe($"{Module}.{Name}.{MotionOperation.Stop}",(cmd,args)=> { return StopPositionOperation(); });
 
-             OP.Subscribe($"{Module}.{Name}.{MotionOperation.Save}", SaveOperation);
 
-             OP.Subscribe($"{Module}.{Name}.GotoSavedPosition", (cmd, args) => { 
 
-                 return PositionStation(args[1].ToString()); });            
 
-         }
 
-         /// <summary>
 
-         /// 保存操作
 
-         /// </summary>
 
-         /// <param name="cmd"></param>
 
-         /// <param name="args"></param>
 
-         /// <returns></returns>
 
-         public bool SaveOperation(string cmd, object[] args)
 
-         {
 
-             if (args.Length >= 2)
 
-             {
 
-                 string key = args[0].ToString();
 
-                 double paramValue = double.Parse(args[1].ToString());
 
-                 BeckhoffStationLocationManager.Instance.SaveMotionPosition(key, paramValue);
 
-                 lock (_locationLocker)
 
-                 {
 
-                     List<string> lst = new List<string>();
 
-                     foreach (Station item in _stationAxis.Stations)
 
-                     {
 
-                         if (item.Name == key)
 
-                         {
 
-                             item.Position = paramValue.ToString();
 
-                             _currentStation = item.Name;
 
-                             if (!lst.Contains(item.Name))
 
-                             {
 
-                                 lst.Add(item.Name);
 
-                             }
 
-                         }
 
-                     }
 
-                     _currentStationList.Clear();
 
-                     if (lst.Count != 0)
 
-                     {
 
-                         _currentStationList.AddRange(lst);
 
-                     }
 
-                 }
 
-                 LOG.WriteLog(eEvent.INFO_AXIS, $"{Module}.{Name}", "save success");
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 计算所处当前工位
 
-         /// </summary>
 
-         private void CalculateCurrentStation(double motor)
 
-         {
 
-             lock (_locationLocker)
 
-             {
 
-                 List<string> tmp = _currentStationList.ToList();
 
-                 List<string> lst = new List<string>();
 
-                 foreach (Station station in _stationAxis.Stations)
 
-                 {
 
-                     if (double.TryParse(station.Position, out double value))
 
-                     {
 
-                         if (Math.Round(Math.Abs(motor - value),2) <= _stationAxis.ToleranceDefault)
 
-                         {
 
-                             _currentStation = station.Name;
 
-                             if (!lst.Contains(station.Name))
 
-                             {
 
-                                 lst.Add(station.Name);
 
-                             }
 
-                         }
 
-                     }
 
-                 }
 
-                 _currentStationList.Clear();
 
-                 if (lst.Count != 0)
 
-                 {
 
-                     string str = string.Join(",", tmp);
 
-                     _currentStationList.AddRange(lst);
 
-                     string strLst = string.Join(",", _currentStationList);
 
-                     if (str != strLst)
 
-                     {
 
-                         LOG.WriteLog(eEvent.INFO_AXIS, $"{Module}.{Name}", $"position {motor} current {strLst}");
 
-                     }
 
-                 }
 
-                 else
 
-                 {
 
-                     _currentStation = "";
 
-                 }
 
-                 if (tmp.Count != 0&&_currentStationList.Count==0)
 
-                 {
 
-                     LOG.WriteLog(eEvent.INFO_AXIS, $"{Module}.{Name}", $"position {motor} current is empty");
 
-                 }
 
-             }
 
-         }
 
-         /// <summary>
 
-         ///  文本框回车操作
 
-         /// </summary>
 
-         /// <param name="cmd"></param>
 
-         /// <param name="args"></param>
 
-         /// <returns></returns>
 
-         private bool KeyDownOperation(string cmd, object[] args)
 
-         {
 
-             if (args.Length < 2)
 
-             {
 
-                 return false;
 
-             }
 
-             if (double.TryParse(args[1].ToString(), out double value))
 
-             {
 
-                 AxisKeyDown(args[0].ToString(), value);
 
-             }
 
-             else
 
-             {
 
-                 EV.PostWarningLog($"{Module}.{Name}", eEvent.ERR_AXIS, $"{args[0]} value {args[1]}is not int value");
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 是否所有IO变量初始化完成
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private bool AllIoVariableInitialized()
 
-         {
 
-             foreach (string item in _variableInitializeDic.Keys)
 
-             {
 
-                 if (!_variableInitializeDic[item])
 
-                 {
 
-                     LOG.WriteLog(eEvent.ERR_DRYER, Module, $"{item} is not initialized");
 
-                     return false;
 
-                 }
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 更新运动数据
 
-         /// </summary>
 
-         /// <param name="variable"></param>
 
-         /// <param name="value"></param>
 
-         private void UpdateMotionData(string variable, object value)
 
-         {
 
-             if(!MotionData.IsDataInitialized)
 
-             {
 
-                 MotionData.IsDataInitialized = true;
 
-             }
 
-             PropertyInfo property = MotionData.GetType().GetProperty(variable);
 
-             if (property != null)
 
-             {
 
-                 if (JudgeIsScale(variable))
 
-                 {
 
-                     if (int.TryParse(value.ToString(), out int intValue))
 
-                     {
 
-                         if (JudgeSpeedRatio(variable))
 
-                         {
 
-                             property.SetValue(MotionData, CalculateValueAfterScale(CalculateDivideSpeedRatio(intValue)));
 
-                         }
 
-                         else if(JudgeAccelerationRation(variable))
 
-                         {
 
-                             property.SetValue(MotionData, CalculateValueAfterScale(CalculateMultiplyAccelerationRatio(intValue)));
 
-                         }
 
-                         else
 
-                         {
 
-                             if (variable == MOTOR_POSITION)
 
-                             {
 
-                                 intValue = (int)Math.Round(intValue * _motionPositionRation,0);
 
-                             }
 
-                             property.SetValue(MotionData, CalculateValueAfterScale(intValue));
 
-                         }
 
-                     }
 
-                     else
 
-                     {
 
-                         property.SetValue(MotionData, value);
 
-                     }                    
 
-                 }
 
-                 else if(variable==ACTUAL_TORQUE)
 
-                 {
 
-                     if (short.TryParse(value.ToString(), out short shortValue))
 
-                     {
 
-                         property.SetValue(MotionData, CalculateDivideTorqueRatio(shortValue));
 
-                     }
 
-                     else
 
-                     {
 
-                         property.SetValue(MotionData, value);
 
-                     }
 
-                 }
 
-                 else
 
-                 {
 
-                     property.SetValue(MotionData, value);
 
-                 }
 
-             }
 
-             if (variable == IS_SWITCH_ON)
 
-             {
 
-                 _isSwitchOn = MotionData.IsSwitchOn;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 判定是否需要比例计算
 
-         /// </summary>
 
-         /// <param name="variable"></param>
 
-         /// <returns></returns>
 
-         private bool JudgeIsScale(string variable)
 
-         {
 
-             switch (variable)
 
-             {
 
-                 case PROFILE_VELOCITY:
 
-                 case PROFILE_ACCEL:
 
-                 case PROFILE_DECEL:
 
-                 case MOTOR_POSITION:
 
-                 case POSITION_ERROR:
 
-                 case ACTUAL_VELOCITY:
 
-                 case TARGET_POSITION:
 
-                 case HOMING_ACCEL:
 
-                 case HOMING_VELOCITY:
 
-                 case HOMING_VELOCITY_SLOW:
 
-                 case HOME_OFFSET:
 
-                     return true;
 
-                 default:
 
-                     return false;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 判定是否需要速度调整比例
 
-         /// </summary>
 
-         /// <param name="variable"></param>
 
-         /// <returns></returns>
 
-         private bool JudgeSpeedRatio(string variable)
 
-         {
 
-             switch (variable)
 
-             {
 
-                 case PROFILE_VELOCITY:
 
-                 case ACTUAL_VELOCITY:
 
-                 case HOMING_VELOCITY:
 
-                 case HOMING_VELOCITY_SLOW:
 
-                 case HOME_OFFSET:
 
-                     return true;
 
-                 default:
 
-                     return false;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 是否是加速度调整比例
 
-         /// </summary>
 
-         /// <param name="variable"></param>
 
-         /// <returns></returns>
 
-         protected bool JudgeAccelerationRation(string variable)
 
-         {
 
-             switch(variable)
 
-             {
 
-                 case PROFILE_ACCEL:
 
-                 case PROFILE_DECEL:
 
-                 case HOMING_ACCEL:
 
-                     return true;
 
-                 default:
 
-                     return false;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// motor position发生变化
 
-         /// </summary>
 
-         /// <param name="location"></param>
 
-         private void MotionPositionChanged(int location)
 
-         {
 
-             if(Math.Round(Math.Abs(location - _currentLocation)/_scaleFactor, 2)>0)
 
-             //if (Math.Abs(location - _currentLocation)/_scaleFactor >= _stationAxis.ToleranceDefault)
 
-             {
 
-                 _currentLocation = location;
 
-                 _runTime = DateTime.Now;
 
-                 _isRun = true;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 更新Digital Inputs
 
-         /// </summary>
 
-         /// <param name="digitalInputs"></param>
 
-         private void UpdateDigitalInputs(uint digitalInputs)
 
-         {
 
-             if (_isRevSensorLimit)
 
-             {
 
-                 MotionData.RevLimited = !(((digitalInputs>>18) & 0x01) == 0x01);
 
-             }
 
-             if(_isForwardSensorLimit)
 
-             {
 
-                 MotionData.FwdLimited = !(((digitalInputs >> 17) & 0x01) == 0x01);
 
-             }
 
-             MotionData.HomedSwitched =((digitalInputs>>22)&0x01) == 0x01;
 
-             if(!_isHomeSwitchedTrigger&&MotionData.HomedSwitched)
 
-             {
 
-                 _isHomeSwitchedTrigger = true;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 更新ManufactureStatus
 
-         /// </summary>
 
-         /// <param name="manufactureStatus"></param>
 
-         private void UpdateManufactureStatus(uint manufactureStatus)
 
-         {
 
-             MotionData.HomedSwitched = ((manufactureStatus >> 26)&0x01) == 0x01;
 
-             if (!_isHomeSwitchedTrigger && MotionData.HomedSwitched)
 
-             {
 
-                 _isHomeSwitchedTrigger = true;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 更新Torque Limited状态
 
-         /// </summary>
 
-         private void UpdateTorqueLimited()
 
-         {
 
-             if(MotionData.NegativeTorqueLimit!=0||MotionData.PositiveTorqueLimit!=0)
 
-             {
 
-                 MotionData.TorqueLimited = (MotionData.ActualTorque >= -MotionData.NegativeTorqueLimit) && (MotionData.ActualTorque <= MotionData.PositiveTorqueLimit) ;
 
-             }
 
-             else
 
-             {
 
-                 MotionData.TorqueLimited = true;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 根据位置获取相应的Position数值
 
-         /// </summary>
 
-         /// <param name="station"></param>
 
-         /// <returns></returns>
 
-         public (bool success,double position) GetPositionByStation(string station)
 
-         {
 
-             foreach(Station item in _stationAxis.Stations)
 
-             {
 
-                 if(item.Name.EndsWith(station))
 
-                 {
 
-                     if(double.TryParse(item.Position,out double position))
 
-                     {
 
-                         return (true, position);
 
-                     }
 
-                     else
 
-                     {
 
-                         return (false, 0);
 
-                     }
 
-                 }
 
-             }
 
-             return (false, 0);
 
-         }
 
-         #endregion
 
-         #region protected 子类使用共用类,子类不再扩展
 
-         /// <summary>
 
-         /// 计算比例后的数值
 
-         /// </summary>
 
-         /// <param name="value"></param>
 
-         /// <returns></returns>
 
-         protected double CalculateValueAfterScale(int value)
 
-         {
 
-             if (_scaleFactor != 0)
 
-             {
 
-                 return Math.Round((double)value / _scaleFactor, 2);
 
-             }
 
-             else
 
-             {
 
-                 return (double)value;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 确认操作状态
 
-         /// </summary>
 
-         /// <param name="operation"></param>
 
-         protected void ConfirmOperationState(MotionOperation operation)
 
-         {
 
-             if (_currentOperation == operation)
 
-             {
 
-                 _status = RState.End;
 
-                 EndOperation();
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 结束操作
 
-         /// </summary>
 
-         protected void EndOperation()
 
-         {
 
-             LOG.WriteLog(eEvent.INFO_AXIS,$"{Module}.{Name}", $"{Module}.{Name} execute {_currentOperation} complete");
 
-             _currentOperation = MotionOperation.None;
 
-             _targetPosition = 0;
 
-         }
 
-         /// <summary>
 
-         /// 订阅变量数值发生变化
 
-         /// </summary>
 
-         protected void SubscribeValueAction()
 
-         {
 
-             GalilAxisSubscribeUpdateVariable(IS_SWITCH_ON);
 
-             GalilAxisSubscribeUpdateVariable(STOP_CODE);
 
-             GalilAxisSubscribeUpdateVariable( MOTOR_POSITION);
 
-             GalilAxisSubscribeUpdateVariable( POSITION_ERROR);
 
-             GalilAxisSubscribeUpdateVariable( ACTUAL_TORQUE);
 
-             GalilAxisSubscribeUpdateVariable( ACTUAL_VELOCITY);
 
-         }
 
-         /// <summary>
 
-         /// 订阅IO变量
 
-         /// </summary>
 
-         /// <param name="variable"></param>
 
-         private void GalilAxisSubscribeUpdateVariable(string variable)
 
-         {
 
-             _variableInitializeDic[variable] = false;
 
-             GalilAxisManager.Instance.SubscribeModuleVariable($"{Module}.{Name}", variable, UpdateVariableValue);
 
-         }
 
-         /// <summary>
 
-         /// 更新变量数值
 
-         /// </summary>
 
-         /// <param name="variable"></param>
 
-         /// <param name="value"></param>
 
-         protected void UpdateVariableValue(string variable, object value)
 
-         {
 
-             if (value == null)
 
-             {
 
-                 return;
 
-             }
 
-             if (_variableInitializeDic.ContainsKey(variable) && !_variableInitializeDic[variable])
 
-             {
 
-                 _variableInitializeDic[variable] = true;
 
-             }
 
-             if (variable == MOTOR_POSITION)
 
-             {
 
-                 if (int.TryParse(value.ToString(), out int location))
 
-                 {
 
-                     MotionPositionChanged(location);
 
-                     if (_galilAxisConfig.ForwardSoftwareLimit != 0)
 
-                     {
 
-                         MotionData.ForwardSoftwareLimited = location > _galilAxisConfig.ForwardSoftwareLimit-_galilAxisConfig.HomingOffset;
 
-                         if (!_isForwardSensorLimit && !_isRevSensorLimit)
 
-                         {
 
-                             MotionData.FwdLimited = MotionData.ForwardSoftwareLimited;
 
-                         }
 
-                     }
 
-                     if (_galilAxisConfig.ReverseSoftwareLimit != 0)
 
-                     {
 
-                         MotionData.ReverseSoftwareLimited = location < _galilAxisConfig.ReverseSoftwareLimit-_galilAxisConfig.HomingOffset;
 
-                         if (!_isRevSensorLimit && !_isForwardSensorLimit)
 
-                         {
 
-                             MotionData.RevLimited = MotionData.ReverseSoftwareLimited;
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             UpdateMotionData(variable, value);
 
-             if (variable == MOTOR_POSITION)
 
-             {
 
-                 CalculateCurrentStation(MotionData.MotorPosition);
 
-             }
 
-             if (variable == ACTUAL_TORQUE)
 
-             {
 
-                 UpdateTorqueLimited();
 
-             }
 
-             else if (variable == POSITIVE_TORQUE_LIMIT || variable == NEGATIVE_TORQUE_LIMIT)
 
-             {
 
-                 MotionData.TorqueLimit = $"-{MotionData.NegativeTorqueLimit}/+{MotionData.PositiveTorqueLimit}";
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 监控(用于判定是否停止运动)
 
-         /// </summary>
 
-         protected void JudgeRunMonitor()
 
-         {
 
-             if (_isRun && DateTime.Now.Subtract(_runTime).TotalMilliseconds >= 500)
 
-             {
 
-                 _isRun = false;
 
-             }
 
-         }
 
-         #endregion
 
-         #region public 公开方法
 
-         /// <summary>
 
-         /// 初始化
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public bool Initialize()
 
-         {
 
-             SubscribeValueAction();
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 当前位置是否离目标位置不远
 
-         /// </summary>
 
-         /// <param name="targetPosition"></param>
 
-         /// <returns></returns>
 
-         public bool JudgeCurrentPositionIsInTargetPosition(int targetPosition)
 
-         {
 
-             double scaledTargetPosition = targetPosition /_scaleFactor;
 
-             double currentMotionPosition = MotionData.MotorPosition;
 
-             double delta = Math.Round(Math.Abs(currentMotionPosition - scaledTargetPosition), 2);
 
-             bool result = delta <= _stationAxis.ToleranceDefault;
 
-             return result;
 
-         }
 
-         /// <summary>
 
-         /// 计算乘以比例后的数值
 
-         /// </summary>
 
-         /// <param name="value"></param>
 
-         /// <returns></returns>
 
-         public int CalculateValueMultiplyScale(double value)
 
-         {
 
-             if (_scaleFactor != 0)
 
-             {
 
-                 return (int)Math.Round(value * _scaleFactor, 0);
 
-             }
 
-             else
 
-             {
 
-                 return (int)Math.Round(value, 0);
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 计算乘上速度比例后的速度
 
-         /// </summary>
 
-         /// <param name="speed"></param>
 
-         /// <returns></returns>
 
-         public int CalculateMultiplySpeedRatio(int speed)
 
-         {
 
-             return speed * _speedRatio;
 
-         }
 
-         /// <summary>
 
-         /// 计算乘上加速度比例后的加速度
 
-         /// </summary>
 
-         /// <param name="acceleration"></param>
 
-         /// <returns></returns>
 
-         public int CalculateMultiplyAccelerationRatio(int acceleration)
 
-         {
 
-             return acceleration * _accelerationRatio;
 
-         }
 
-         /// <summary>
 
-         /// 计算除以速度比例后的速度
 
-         /// </summary>
 
-         /// <param name="speed"></param>
 
-         /// <returns></returns>
 
-         protected int CalculateDivideSpeedRatio(int speed)
 
-         {
 
-             return speed / _speedRatio;
 
-         }
 
-         /// <summary>
 
-         /// 计算除以加速度比例后的加速度
 
-         /// </summary>
 
-         /// <param name="acceleration"></param>
 
-         /// <returns></returns>
 
-         protected int CalculateDivideAccelerationRatio(int acceleration)
 
-         {
 
-             return acceleration / _accelerationRatio;
 
-         }
 
-         /// <summary>
 
-         /// 计算除以Torque比例后的Torque
 
-         /// </summary>
 
-         /// <param name="speed"></param>
 
-         /// <returns></returns>
 
-         protected double CalculateDivideTorqueRatio(int torque)
 
-         {
 
-             return Math.Round((double)torque / _torqueRatio, 2);            
 
-         }
 
-         /// <summary>
 
-         /// Jog Up
 
-         /// </summary>
 
-         /// <param name="cmd"></param>
 
-         /// <param name="args"></param>
 
-         /// <returns></returns>
 
-         public bool JogUpPosition(string cmd, object[] args)
 
-         {
 
-             double jog=(double)args[1];
 
-             double currentPosition=MotionData.MotorPosition;
 
-             if(_jogLimit!=0)
 
-             {
 
-                 if(jog>_jogLimit)
 
-                 {
 
-                     LOG.WriteLog(eEvent.ERR_AXIS, Module, $"Jog Value {jog} is over {_jogLimit}");
 
-                     return false;
 
-                 }
 
-             }
 
-             if (!_isSwitchOn)
 
-             {
 
-                 LOG.WriteLog(eEvent.ERR_AXIS, Module, $"Axis is switch off,cannot jog");
 
-                 return false;
 
-             }
 
-             return ProfilePositionOperation(Math.Round(currentPosition + jog,2));
 
-         }
 
-         /// <summary>
 
-         /// Jog Down
 
-         /// </summary>
 
-         /// <param name="cmd"></param>
 
-         /// <param name="args"></param>
 
-         /// <returns></returns>
 
-         public bool JogDownPosition(string cmd, object[] args)
 
-         {
 
-             double jog = (double)args[1];
 
-             double currentPosition = MotionData.MotorPosition;
 
-             if (_jogLimit != 0)
 
-             {
 
-                 if (jog > _jogLimit)
 
-                 {
 
-                     LOG.WriteLog(eEvent.ERR_AXIS, Module, $"Jog Value {jog} is over {_jogLimit}");
 
-                     return false;
 
-                 }
 
-             }
 
-             if(!_isSwitchOn)
 
-             {
 
-                 LOG.WriteLog(eEvent.ERR_AXIS, Module, $"Axis is switch off,cannot jog");
 
-                 return false;
 
-             }
 
-             return ProfilePositionOperation(Math.Round(currentPosition - jog,2));
 
-         }
 
-         /// <summary>
 
-         /// Profile position操作
 
-         /// </summary>
 
-         /// <param name="cmd"></param>
 
-         /// <param name="args"></param>
 
-         /// <returns></returns>
 
-         public bool ProfilePositionOperation(double position)
 
-         {
 
-             _targetPosition = position;
 
-             int targetPosition = CalculateValueMultiplyScale(_targetPosition);
 
-             if (_galilAxisConfig.ForwardSoftwareLimit != 0 && targetPosition > _galilAxisConfig.ForwardSoftwareLimit - _galilAxisConfig.HomingOffset)
 
-             {
 
-                 LOG.WriteLog(eEvent.ERR_AXIS, Module, $"target position {_targetPosition} is over forward limit");
 
-                 return false;
 
-             }
 
-             if (_galilAxisConfig.ReverseSoftwareLimit != 0 && targetPosition < _galilAxisConfig.ReverseSoftwareLimit - _galilAxisConfig.HomingOffset)
 
-             {
 
-                 LOG.WriteLog(eEvent.ERR_AXIS, Module, $"target position {_targetPosition} is less reverse limit");
 
-                 return false;
 
-             }
 
-             bool result= ProfilePosition(targetPosition, _profileVelocity, _profileAcceleration, _profileDeceleration);
 
-             if (result)
 
-             {
 
-                 MotionData.TargetPosition = _targetPosition;
 
-             }
 
-             return result;
 
-         }
 
-         /// <summary>
 
-         /// 移动至指定位置
 
-         /// </summary>
 
-         /// <param name="targetStation"></param>
 
-         /// <returns></returns>
 
-         public bool PositionStation(string targetStation,bool isHome=false,int velocity=0,int acceleration=0,int deceleration=0, bool judgeTorqueLimit = true)
 
-         {
 
-             if (!CheckPositionIsInStation(MotionData.MotorPosition,targetStation))
 
-             {
 
-                 if(_interLock!=null&&!isHome&&!_interLock.CheckGotoPosition(targetStation))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 var result=GetPositionByStation(targetStation);
 
-                 if(result.success)
 
-                 {
 
-                     _targetPosition = result.position;
 
-                     int targetPosition = (int)Math.Round(result.position*_scaleFactor, 0);
 
-                     bool positionResult = false;
 
-                     if (velocity != 0)
 
-                     {
 
-                         positionResult= ProfilePosition(targetPosition, velocity, acceleration, deceleration, judgeTorqueLimit);
 
-                     }
 
-                     else
 
-                     {
 
-                         positionResult= ProfilePosition(targetPosition, _profileVelocity, _profileAcceleration, _profileDeceleration, judgeTorqueLimit);
 
-                     }
 
-                     if (positionResult)
 
-                     {
 
-                         MotionData.TargetPosition = _targetPosition;
 
-                     }
 
-                     return positionResult;
 
-                 }
 
-                 LOG.WriteLog(eEvent.ERR_AXIS, Module, $"{targetStation} not in list,cannot goto fixed position");
 
-                 return false;
 
-             }
 
-             else
 
-             {
 
-                 _status = RState.End;
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 上电
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public bool WriteSwitchOn()
 
-         {
 
-             return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "SH", null);
 
-         }
 
-         /// <summary>
 
-         /// 下电
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public bool WriteSwitchOff()
 
-         {
 
-             return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "MO", null);
 
-         }
 
-         /// <summary>
 
-         /// 写入相对位置
 
-         /// </summary>
 
-         /// <param name="referencePosition"></param>
 
-         /// <returns></returns>
 
-         public bool WriteReferencePosition(int referencePosition)
 
-         {
 
-             return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "PR", referencePosition);
 
-         }
 
-         /// <summary>
 
-         /// 写入绝对位置
 
-         /// </summary>
 
-         /// <param name="referencePosition"></param>
 
-         /// <returns></returns>
 
-         public bool WriteAbsolutePosition(int absolutePosition)
 
-         {
 
-             return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "PA", absolutePosition);
 
-         }
 
-         /// <summary>
 
-         /// 写入速度
 
-         /// </summary>
 
-         /// <param name="referencePosition"></param>
 
-         /// <returns></returns>
 
-         public bool WriteSpeed(int speed)
 
-         {
 
-             return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "SP", speed);
 
-         }
 
-         /// <summary>
 
-         /// 写入加速度
 
-         /// </summary>
 
-         /// <param name="referencePosition"></param>
 
-         /// <returns></returns>
 
-         public bool WriteAcceleration(int acceleration)
 
-         {
 
-             return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "AC", acceleration);
 
-         }
 
-         /// <summary>
 
-         /// 写入减速度
 
-         /// </summary>
 
-         /// <param name="referencePosition"></param>
 
-         /// <returns></returns>
 
-         public bool WriteDeceleration(int deceleration)
 
-         {
 
-             return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "DC", deceleration);
 
-         }
 
-         /// <summary>
 
-         /// 停止
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public bool WriteStop()
 
-         {
 
-             return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "ST", null);
 
-         }
 
-         /// <summary>
 
-         /// 开始运动
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public bool WriteStartMotion()
 
-         {
 
-             return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "BG", null);
 
-         }
 
-         /// <summary>
 
-         /// Home 电机
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public bool WriteHomeAxisCommand()
 
-         {
 
-             return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "HM", null);
 
-         }
 
-         /// <summary>
 
-         /// Home 电机
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public bool WriteCNCommand(string cn)
 
-         {
 
-             return GalilControllerCfgManager.Instance.SetSystemCommand(Module, Name, "CN", cn);
 
-         }
 
-         /// <summary>
 
-         /// 手动置零
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public bool WriteDP(int dp)
 
-         {
 
-             bool result= GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "DP", dp);
 
-             if (result)
 
-             {
 
-                 return GalilControllerCfgManager.Instance.SetAxisCommand(Module, Name, "DE", dp);
 
-             }
 
-             return false;
 
-         }
 
-         /// <summary>
 
-         /// 写入控制字
 
-         /// </summary>
 
-         /// <param name="controlWord"></param>
 
-         public bool WriteControlWord(ushort controlWord)
 
-         {
 
-             return BeckhoffAxisManager.Instance.WriteVariableValue($"{Module}.{Name}.{CONTROL_WORD}", controlWord);
 
-         }
 
-         /// <summary>
 
-         /// 写入ModeOfOperation
 
-         /// </summary>
 
-         /// <param name="modeOfOperation"></param>
 
-         /// <returns></returns>
 
-         public bool WriteModeOfMode(AxisModeOfOperation modeOfOperation)
 
-         {
 
-             return BeckhoffAxisManager.Instance.WriteVariableValue($"{Module}.{Name}.{MODE_OF_OPERATION}", (byte)modeOfOperation);
 
-         }
 
-         /// <summary>
 
-         /// 写变量数值
 
-         /// </summary>
 
-         /// <param name="variableName"></param>
 
-         /// <param name="value"></param>
 
-         /// <returns></returns>
 
-         public bool WriteVariable(string variableName,object value) 
 
-         {
 
-             return BeckhoffAxisManager.Instance.WriteVariableValue($"{Module}.{Name}.{variableName}", value);
 
-         }
 
-         /// <summary>
 
-         /// 检验GotoPosition条件
 
-         /// </summary>
 
-         /// <param name="station"></param>
 
-         public bool CheckGotoPosition(string station)
 
-         {
 
-             return _interLock.CheckGotoPosition(station);
 
-         }
 
-         /// <summary>
 
-         /// 检验当位Position是否在位置上
 
-         /// </summary>
 
-         /// <param name="position"></param>
 
-         /// <param name="stationName"></param>
 
-         /// <returns></returns>
 
-         public bool CheckPositionIsInStation(double position,string stationName)
 
-         {
 
-             foreach (Station station in _stationAxis.Stations)
 
-             {
 
-                 string[] strAry = station.Name.Split('.');
 
-                 if(strAry.Length == 0)
 
-                 {
 
-                     continue;
 
-                 }
 
-                 if (strAry[strAry.Length-1].ToLower()==(stationName.ToLower()))
 
-                 {
 
-                     if (double.TryParse(station.Position, out double value))
 
-                     {
 
-                         if (Math.Round(Math.Abs(position - value), 2) <= _stationAxis.ToleranceDefault)
 
-                         {
 
-                             return true;
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             return false;
 
-         }
 
-         /// <summary>
 
-         /// 检验位置(忽略WaferSize)
 
-         /// </summary>
 
-         /// <param name="position"></param>
 
-         /// <param name="stationName"></param>
 
-         /// <returns></returns>
 
-         public bool CheckPositionInStationIgnoreWaferSize(double position,string stationName)
 
-         {
 
-             foreach (Station station in _stationAxis.Stations)
 
-             {
 
-                 if (station.Name.ToLower().Contains(stationName.ToLower()))
 
-                 {
 
-                     if (double.TryParse(station.Position, out double value))
 
-                     {
 
-                         if (Math.Round(Math.Abs(position - value), 2) <= _stationAxis.ToleranceDefault)
 
-                         {
 
-                             return true;
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             return false;
 
-         }
 
-         /// <summary>
 
-         /// 检验位置是否为空
 
-         /// </summary>
 
-         /// <param name="position"></param>
 
-         /// <returns></returns>
 
-         public bool CheckPositionIsEmpty(double position)
 
-         {
 
-             foreach (Station station in _stationAxis.Stations)
 
-             {
 
-                 if (double.TryParse(station.Position, out double value))
 
-                 {
 
-                     if (Math.Round(Math.Abs(position - value), 2) <= _stationAxis.ToleranceDefault)
 
-                     {
 
-                         return false;
 
-                     }
 
-                 }
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 判定与目标位置相对关系
 
-         /// </summary>
 
-         /// <param name="station"></param>
 
-         /// <param name="compareType">Left--位于目标位置左侧,Right--位于目标位置右侧</param>
 
-         /// <returns></returns>
 
-         public bool JudgeCompareTargetStation(string station,string compareType)
 
-         {
 
-             double position = 0;
 
-             var result = GetPositionByStation(station);
 
-             if(result.success)
 
-             {
 
-                 position = result.position;
 
-             }
 
-             else
 
-             {
 
-                 return false;
 
-             }
 
-             var buffer16Position=GetPositionByStation(station);
 
-             switch(compareType)
 
-             {
 
-                 case "Left":
 
-                     return IsInStationLeftDirection(position);
 
-                 case "Right":
 
-                     if (buffer16Position.success)
 
-                     {
 
-                         position=buffer16Position.position;
 
-                     }
 
-                     return IsInStationRightPosition(position);
 
-                 default:
 
-                     return false;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 是否位于位置左侧
 
-         /// </summary>
 
-         /// <param name="stationPosition"></param>
 
-         /// <returns></returns>
 
-         private bool IsInStationLeftDirection(double stationPosition)
 
-         {
 
-             double currentPosition = MotionData.MotorPosition;
 
-             double targetPosition = _targetPosition;
 
-             if(_currentOperation==MotionOperation.Position)
 
-             {
 
-                 return currentPosition <= stationPosition && targetPosition <= stationPosition;
 
-             }
 
-             else
 
-             {
 
-                 return currentPosition <= stationPosition;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 是否位于位置右侧
 
-         /// </summary>
 
-         /// <param name="stationPosition"></param>
 
-         /// <returns></returns>
 
-         private bool IsInStationRightPosition(double stationPosition)
 
-         {
 
-             double currentPosition = MotionData.MotorPosition;
 
-             double targetPosition = _targetPosition;
 
-             if (_currentOperation == MotionOperation.Position)
 
-             {
 
-                 return currentPosition > stationPosition && targetPosition > stationPosition;
 
-             }
 
-             else
 
-             {
 
-                 return currentPosition > stationPosition ;
 
-             }
 
-         }
 
-         #endregion
 
-         #region virtual共用方法,子类可实现更多方法
 
-         /// <summary>
 
-         /// Home共用方法
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public virtual bool Home()
 
-         {
 
-             if (!_isSwitchOn)
 
-             {
 
-                 EV.PostAlarmLog($"{Module}.{Name}", eEvent.ERR_PUF, $"{Module}.{Name} switch off,cannot home");
 
-                 return false;
 
-             }
 
-             if (_status == RState.Running)
 
-             {
 
-                 EV.PostAlarmLog($"{Module}.{Name}", eEvent.ERR_PUF, $"{Module}.{Name} current execute {_currentOperation},cannot home");
 
-                 return false;
 
-             }
 
-             _currentOperation = MotionOperation.Home;
 
-             _status = RState.Running;
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// Home(isLogError)共用方法
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public virtual bool Home(bool isLogError)
 
-         {
 
-             if (!_isSwitchOn)
 
-             {
 
-                 EV.PostAlarmLog($"{Module}.{Name}", eEvent.ERR_PUF, $"{Module}.{Name} switch off,cannot home");
 
-                 return false;
 
-             }
 
-             if (_status == RState.Running)
 
-             {
 
-                 EV.PostAlarmLog($"{Module}.{Name}", eEvent.ERR_PUF, $"{Module}.{Name} current execute {_currentOperation},cannot home");
 
-                 return false;
 
-             }
 
-             _currentOperation = MotionOperation.Home;
 
-             _status = RState.Running;
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 更改速度百分比
 
-         /// </summary>
 
-         /// <param name="percent"></param>
 
-         /// <returns></returns>
 
-         public bool ChangePercentSpeedAceleration(int percent)
 
-         {
 
-             double percentSpeed = _initialVelocity * ((double)percent / 100);
 
-             double percentAceleration = _initialAcceleration * ((double)percent / 100);
 
-             double percentDeceleration = _initialDeceleration * ((double)percent / 100);
 
-             int changedSpeed = (int)(Math.Round(percentSpeed, 0));
 
-             int changedAcceleration = (int)(Math.Round(percentAceleration, 0));
 
-             int changedDeceleration = (int)(Math.Round(percentDeceleration, 0));
 
-             bool result= ChangeSpeedAcceleration(changedSpeed,changedAcceleration,changedDeceleration);
 
-             if(result)
 
-             {
 
-                 _profileVelocity = changedSpeed;
 
-                 _profileAcceleration = changedAcceleration;
 
-                 _profileDeceleration = changedDeceleration;
 
-             }
 
-             return result;
 
-         }
 
-         #endregion
 
-         #region public abstract 子类实现方法
 
-         /// <summary>
 
-         /// 停止操作
 
-         /// </summary>
 
-         /// <param name="cmd"></param>
 
-         /// <param name="args"></param>
 
-         /// <returns></returns>
 
-         public abstract bool StopPositionOperation();
 
-         /// <summary>
 
-         /// change speed
 
-         /// </summary>
 
-         /// <param name="speed"></param>
 
-         /// <returns></returns>
 
-         public abstract bool ChangeSpeed(int speed);
 
-         /// <summary>
 
-         /// 改变速度加速度
 
-         /// </summary>
 
-         /// <param name="speed"></param>
 
-         /// <returns></returns>
 
-         public abstract bool ChangeSpeedAcceleration(int speed, int acceleration, int deceleration);
 
-         /// <summary>
 
-         /// Switch On
 
-         /// </summary>
 
-         public abstract bool SwitchOn();
 
-         /// <summary>
 
-         /// Switch Off
 
-         /// </summary>
 
-         public abstract bool SwitchOff();
 
-         /// <summary>
 
-         /// 停止
 
-         /// </summary>
 
-         public abstract void Stop();
 
-         /// <summary>
 
-         /// Enable Operation
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public abstract bool EnableOperation();
 
-         /// <summary>
 
-         /// 定时器执行
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public abstract bool OnTimer();
 
-         /// <summary>
 
-         /// Profile operation
 
-         /// </summary>
 
-         /// <param name="targetPoint"></param>
 
-         /// <param name="profileVelocity"></param>
 
-         /// <param name="profileAcceleration"></param>
 
-         /// <param name="profileDeceleration"></param>
 
-         public abstract bool ProfilePosition(int targetPoint, int profileVelocity, int profileAcceleration, int profileDeceleration, bool judgeTorqueLimit = true);
 
-         #endregion
 
-         #region protected abstract 子类实现方法
 
-         /// <summary>
 
-         /// 初始化Routine
 
-         /// </summary>
 
-         protected abstract void InitializeRoutine();
 
-         /// <summary>
 
-         /// 初始化参数
 
-         /// </summary>
 
-         protected abstract void InitializeParameter();
 
-         /// <summary>
 
-         /// 更新状态字
 
-         /// </summary>
 
-         /// <param name="statusWord"></param>
 
-         public abstract void UpdateStatusWord(ushort statusWord);
 
-         /// <summary>
 
-         /// 回车输入
 
-         /// </summary>
 
-         /// <param name="arg"></param>
 
-         /// <param name="value"></param>
 
-         protected abstract void AxisKeyDown(string arg, double value);
 
-         #endregion
 
-         /// <summary>
 
-         /// 监控
 
-         /// </summary>
 
-         public void Monitor()
 
-         {
 
-         }
 
-         public void Reset()
 
-         {
 
-         }
 
-         
 
-         /// 停止
 
-         /// </summary>
 
-         public void Terminate()
 
-         {
 
-         }
 
-     }
 
- }
 
 
  |