| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774 | 
							- 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.Util;
 
- using MECF.Framework.Common.Device.LinMot;
 
- using PunkHPX8_Core;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Threading;
 
- using System.Threading.Tasks;
 
- using Aitex.Core.RT.Routine;
 
- using MECF.Framework.Common.ToolLayout;
 
- using System.Diagnostics;
 
- using Aitex.Core.RT.SCCore;
 
- namespace PunkHPX8_RT.Devices.LinMot
 
- {
 
-     public class LinMotAxis : BaseDevice, IDevice
 
-     {
 
-         #region 常量
 
-         /// <summary>
 
-         /// 控制字
 
-         /// </summary>
 
-         private const string STATUS_WORD = "StatusWord";
 
-         private const string HOME = "Home";
 
-         private const string SWITCH_ON = "SwitchOn";
 
-         private const string DIRECTION = "Direction";
 
-         private const string POSITION = "Position";
 
-         private const string SCAN_COUNT = "ScanCount";
 
-         /// <summary>
 
-         /// 下一指令判定条件与_startPosition的距离
 
-         /// </summary>
 
-         private const double _nextInterval = 2;
 
-         #endregion
 
-         #region 内部变量
 
-         /// <summary>
 
-         /// Home状态
 
-         /// </summary>
 
-         private bool _isHomed;
 
-         /// <summary>
 
-         /// SwitchOn状态
 
-         /// </summary>
 
-         private bool _isSwitchOn;
 
-         /// <summary>
 
-         /// Disabled状态
 
-         /// </summary>
 
-         private bool _isDisabled;
 
-         /// <summary>
 
-         /// 错误状态
 
-         /// </summary>
 
-         private bool _isError;
 
-         /// <summary>
 
-         /// 致命错误状态
 
-         /// </summary>
 
-         private bool _isFatalError;
 
-         /// <summary>
 
-         /// 运动状态
 
-         /// </summary>
 
-         private bool _isMotorOn;
 
-         /// <summary>
 
-         /// 是否到达目标
 
-         /// </summary>
 
-         private bool _inTagertPosition = false;
 
-         /// <summary>
 
-         /// 操作当前状态
 
-         /// </summary>
 
-         private RState _status;
 
-         /// <summary>
 
-         /// 当前操作指令 
 
-         /// </summary>
 
-         private LinMotOperation _currentOperation = LinMotOperation.None;
 
-         /// <summary>
 
-         /// 状态字
 
-         /// </summary>
 
-         private short _statusWord;
 
-         /// <summary>
 
-         /// LinMotId
 
-         /// </summary>
 
-         private byte _linmotId;
 
-         /// <summary>
 
-         /// 错误代码
 
-         /// </summary>
 
-         private short _errorCode;
 
-         /// <summary>
 
-         /// Reset Routine
 
-         /// </summary>
 
-         private LinMotResetRoutine _resetRoutine;
 
-         /// <summary>
 
-         /// Stop Motor Routine
 
-         /// </summary>
 
-         private LinMotStopMotorRoutine _stopMotorRoutine;
 
-         /// <summary>
 
-         /// Start Curve
 
-         /// </summary>
 
-         private LinMotStartContinueCurveRoutine _startContinueCurveRoutine;
 
-         /// <summary>
 
-         /// Start VAI
 
-         /// </summary>
 
-         private LinMotStartVAIPositionRoutine _startVAIPositionRoutine;
 
-         /// <summary>
 
-         /// Curve速度
 
-         /// </summary>
 
-         private int _curverSpeed = 100;
 
-         /// <summary>
 
-         /// Curver指定的Id
 
-         /// </summary>
 
-         private byte _curveId = 1;
 
-         /// <summary>
 
-         /// 指令发送时间(用于空闲时发送读取状态指令)
 
-         /// </summary>
 
-         private DateTime _sendTime = DateTime.Now;
 
-         /// <summary>
 
-         /// 运动时间(用于判定运动指令发送LinMot并没有执行上报超时)
 
-         /// </summary>
 
-         private DateTime _motorTime = DateTime.Now;
 
-         /// <summary>
 
-         /// 设备参数对象
 
-         /// </summary>
 
-         private LinMotDevice _linMotDeviceParam;
 
-         /// <summary>
 
-         /// 开始时的方向
 
-         /// </summary>
 
-         private string _startDirection = "";
 
-         /// <summary>
 
-         /// 当前GAI GO To Position方向 
 
-         /// </summary>
 
-         private string _direction = "";
 
-         /// <summary>
 
-         /// 当前位置
 
-         /// </summary>
 
-         private double _currentPosition =0;
 
-         /// <summary>
 
-         /// 当前位置(类型为整形)
 
-         /// </summary>
 
-         private int _currentIntPosition = 0;
 
-         /// 用于prewet页面UI的位置数据
 
-         /// </summary>
 
-         private double _currentPrewetUIPostion = 0;
 
-         /// <summary>
 
-         /// <summary>
 
-         /// 判定方向位置
 
-         /// </summary>
 
-         private double _judgePosition = 0;
 
-         /// <summary>
 
-         /// GAI运动前的位置
 
-         /// </summary>
 
-         private double _startPosition = 0;
 
-         /// <summary>
 
-         /// 状态字时间
 
-         /// </summary>
 
-         private DateTime _statusWordDateTime=DateTime.Now;
 
-         /// <summary>
 
-         /// linmot stop watch
 
-         /// </summary>
 
-         private Stopwatch _linmotStopWatch = new Stopwatch();
 
-         /// <summary>
 
-         /// 状态字上升沿信号 
 
-         /// </summary>
 
-         private R_TRIG _statusTrigger = new R_TRIG();
 
-         #endregion
 
-         #region 属性
 
-         /// <summary>
 
-         /// 操作当前状态
 
-         /// </summary>
 
-         public RState Status { get { return _status; } }
 
-         /// <summary>
 
-         /// Home
 
-         /// </summary>
 
-         public bool IsHomed { get { return IsConnectd && _isHomed; } }
 
-         /// <summary>
 
-         /// SwitchOn状态
 
-         /// </summary>
 
-         public bool IsSwitchOn { get { return IsConnectd && _isSwitchOn; } }
 
-         /// <summary>
 
-         /// 错误
 
-         /// </summary>
 
-         public bool IsError { get { return _isError; } }
 
-         /// <summary>
 
-         /// Disabled状态
 
-         /// </summary>
 
-         public bool IsDisabled { get { return IsConnectd&&_isDisabled; } }
 
-         /// <summary>
 
-         /// 运动状态
 
-         /// </summary>
 
-         public bool IsMotorOn 
 
-         { 
 
-             get 
 
-             {
 
-                 if(_isMotorOn)
 
-                 {
 
-                     return true;
 
-                 }
 
-                 else
 
-                 {
 
-                     if (_linmotStopWatch.ElapsedMilliseconds <= 2000)
 
-                     {
 
-                         return true;
 
-                     }
 
-                     else
 
-                     {
 
-                         return false;
 
-                     }
 
-                 }
 
-             } 
 
-         }
 
-         /// <summary>
 
-         /// 是否已经到达目标
 
-         /// </summary>
 
-         public bool InTargetPosition { get { return _inTagertPosition; } }
 
-         /// <summary>
 
-         /// 当前位置
 
-         /// </summary>
 
-         public double CurrentPosition { get { return _currentPosition; } }
 
-         /// <summary>
 
-         /// 方向 
 
-         /// </summary>
 
-         public string Direction { get { return _direction; } }
 
-         /// <summary>
 
-         /// 连接状态
 
-         /// </summary>
 
-         public bool IsConnectd { get { return LinMotDeviceConfigManager.Instance.GetDeviceConnect(Module.ToString()); } }
 
-         /// <summary>
 
-         /// 扫描次数
 
-         /// </summary>
 
-         public int ScanCount { get { return _startVAIPositionRoutine.CurrentScan; } }
 
-         /// <summary>
 
-         /// 当前位置
 
-         /// </summary>
 
-         public int CurrentIntPosition { get { return _currentIntPosition; } }
 
-         /// <summary>
 
-         /// 最后是否SwitchOff
 
-         /// </summary>
 
-         public bool LastSwitchOff { get; set; } = false;
 
-         /// <summary>
 
-         /// curve速度
 
-         /// </summary>
 
-         public int CurveSpeed
 
-         {
 
-             get { return _curverSpeed; }
 
-         }
 
-         /// <summary>
 
-         /// 错误代码
 
-         /// </summary>
 
-         public short ErrorCode
 
-         {
 
-             get { return _errorCode; }
 
-         }
 
-         #endregion
 
-         /// <summary>
 
-         /// 构造函数
 
-         /// </summary>
 
-         /// <param name="moduleName"></param>
 
-         /// <param name="name"></param>
 
-         public LinMotAxis(string moduleName) : base(moduleName, moduleName, moduleName, moduleName)
 
-         {
 
-             InitialData();
 
-             InitializeOperation();
 
-             InitializeRoute();
 
-             _linmotStopWatch.Restart();
 
-         }
 
-         /// <summary>
 
-         /// 初始化Routine
 
-         /// </summary>
 
-         private void InitializeRoute()
 
-         {
 
-             _resetRoutine = new LinMotResetRoutine(Module,this);
 
-             _stopMotorRoutine=new LinMotStopMotorRoutine(Module,this);
 
-             _startContinueCurveRoutine=new LinMotStartContinueCurveRoutine(Module,this);
 
-             _startVAIPositionRoutine=new LinMotStartVAIPositionRoutine(Module,this);
 
-         }
 
-         /// <summary>
 
-         /// 初始化OP
 
-         /// </summary>
 
-         private void InitializeOperation()
 
-         {
 
-             OP.Subscribe($"{Module}.Reset",(cmd,args)=> { return ResetOperation(cmd, LastSwitchOff); });
 
-             OP.Subscribe($"{Module}.StartCurve", StartCurveOperation);
 
-             OP.Subscribe($"{Module}.StartPosition", StartPosition);
 
-             OP.Subscribe($"{Module}.Stop", StopOperation);
 
-             OP.Subscribe($"{Module}.Abort", AbortOperation);
 
-             OP.Subscribe($"{Module}.UpdateSpeedData",UpdateSpeedDataOperation);
 
-             LinMotDeviceConfigManager.Instance.InitialDevice(Module.ToString());
 
-             LinMotDeviceConfigManager.Instance.SubscribeModuleVariable(Module, UpdateStatusWord);
 
-         }
 
-         /// <summary>
 
-         /// 初始化数据
 
-         /// </summary>
 
-         private void InitialData()
 
-         {
 
-             _linMotDeviceParam = LinMotDeviceConfigManager.Instance.GetLinMotDevice(Module);
 
-             if (_linMotDeviceParam == null)
 
-             {
 
-                 LOG.WriteLog(eEvent.ERR_LINMOT, Module.ToString(), "Get Address Id Error"); ;
 
-                 return;
 
-             }
 
-             if (byte.TryParse(_linMotDeviceParam.Address, out var tmpLinmotId))
 
-             {
 
-                 _linmotId = tmpLinmotId;
 
-             }
 
-             DATA.Subscribe($"{Module}.{STATUS_WORD}", () => IsConnectd?_statusWord:0,SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{HOME}", () => IsHomed,SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{SWITCH_ON}", () => IsSwitchOn, SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{DIRECTION}", () => _direction,SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{POSITION}", () => _currentPosition, SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.{SCAN_COUNT}",()=>ScanCount,SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.Speed", () => _curverSpeed, SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.IsConnectd", () => IsConnectd, SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.CurrentPrewetUIPostion", () => _currentPrewetUIPostion, SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-             DATA.Subscribe($"{Module}.LinmotDeviceData", () => _linMotDeviceParam.LinMotDeviceData, SubscriptionAttribute.FLAG.IgnoreSaveDB);
 
-         }
 
-         /// <summary>
 
-         /// 更新状态字
 
-         /// </summary>
 
-         /// <param name="cmd"></param>
 
-         /// <param name="args"></param>
 
-         /// <returns></returns>
 
-         private void UpdateStatusWord(short statusWord,short errorCode,int position)
 
-         {
 
-             _statusWordDateTime=DateTime.Now;
 
-             _statusTrigger.CLK = _statusWord != statusWord;
 
-             if (_statusTrigger.Q)
 
-             {
 
-                 LOG.WriteLog(eEvent.INFO_LINMOT, Module, $"statusword is {statusWord}");
 
-             }
 
-             _statusWord = statusWord;
 
-             UpdateStatusWord(statusWord);
 
-             short tmpErrorCode = errorCode;
 
-             NotifyError(tmpErrorCode);
 
-             //ContinueGAIGotoPosition();
 
-             double tmpPosition = (double)position / 10000;
 
-             if (Math.Abs(tmpPosition - _currentPosition) >= 0.1)
 
-             {
 
-                 _currentPosition = tmpPosition;
 
-                 bool enableLog = SC.GetValue<bool>("Log.EnableLinmotLog");
 
-                 if (enableLog)
 
-                 {
 
-                     LOG.WriteLog(eEvent.INFO_LINMOT, Module, $"motor status {_isMotorOn} position {_currentPosition}");
 
-                 }
 
-             }
 
-             _currentIntPosition = position;
 
-             if (_linMotDeviceParam.LinMotDeviceData != null && _linMotDeviceParam.LinMotDeviceData.TopPosition - _linMotDeviceParam.LinMotDeviceData.BottomPosition != 0)
 
-             {
 
-                 double proportion = _linMotDeviceParam.LinMotDeviceData.TopPosition - _linMotDeviceParam.LinMotDeviceData.BottomPosition;
 
-                 _currentPrewetUIPostion = 150 - 90 * Math.Abs(position / proportion); //150是prewet页面底部位置,90是页面顶部和底部距离之差
 
-             }
 
-             JudgeDirection();
 
-         }
 
-         /// <summary>
 
-         /// 更新StatusWord
 
-         /// </summary>
 
-         /// <param name="statusWord"></param>
 
-         private void UpdateStatusWord(short statusWord)
 
-         {
 
-             bool isHomed = (statusWord & 0b0100000000000) >> 11 == 1;//11位为Home
 
-             if (isHomed != _isHomed)
 
-             {
 
-                 _isHomed = isHomed;
 
-             }
 
-             _isDisabled = (statusWord & 0b0100) >> 2 == 0;
 
-             _isSwitchOn = (statusWord & 0x01) == 1;
 
-             _isError = ((statusWord & 0b01000) >> 3 == 1) || ((statusWord & 0b01000000000000) >> 12 == 1);
 
-             _isFatalError = ((statusWord & 0b01000000000000) >> 12 == 1);
 
-             bool isMotorOn = ((statusWord & 0b010000000000000) >> 13 == 1);//13是否正在运动
 
-             if (isMotorOn != _isMotorOn)
 
-             {
 
-                 _isMotorOn = isMotorOn;
 
-                 if (!_isMotorOn)
 
-                 {
 
-                     _linmotStopWatch.Restart();
 
-                 }
 
-             }
 
-             _inTagertPosition = (statusWord & 0b010000000000) >> 10 == 1;//10位是否到达目标
 
-         }
 
-         /// <summary>
 
-         /// 通知错误
 
-         /// </summary>
 
-         /// <param name="tmpErrorCode"></param>
 
-         private void NotifyError(short tmpErrorCode)
 
-         {
 
-             if (tmpErrorCode != _errorCode)
 
-             {
 
-                 if (tmpErrorCode != 0)
 
-                 {
 
-                     string errorMsg = LinMotErrorCodeManager.Instance.GetErrorCodeText(tmpErrorCode);
 
-                     string str = string.IsNullOrEmpty(errorMsg) ? tmpErrorCode.ToString() : errorMsg;
 
-                     if (!_isFatalError)
 
-                     {
 
-                         LOG.WriteLog(eEvent.ERR_LINMOT, Module, $"{str},please reset error");
 
-                     }
 
-                     else
 
-                     {
 
-                         LOG.WriteLog(eEvent.ERR_LINMOT, Module, $"{str},meets fatal error,please reboot {Module}");
 
-                     }
 
-                     _currentOperation = LinMotOperation.None;
 
-                     _status = RState.Failed;
 
-                 }
 
-                 _errorCode = tmpErrorCode;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 判定方向 
 
-         /// </summary>
 
-         private void JudgeDirection()
 
-         {
 
-             if(_linMotDeviceParam!=null&&_linMotDeviceParam.LinMotDeviceData!=null&&_currentOperation==LinMotOperation.StartVAIGoToPosition)
 
-             {
 
-                 double interval = _currentPosition - _judgePosition;
 
-                 if(Math.Abs(interval)>=1)
 
-                 {
 
-                     string tmpDirection = "";
 
-                     if(interval>0)
 
-                     {
 
-                         tmpDirection = "down";
 
-                     }
 
-                     else
 
-                     {
 
-                         tmpDirection = "up";
 
-                     }
 
-                     if(tmpDirection!=_direction)
 
-                     {
 
-                         //_sendNextGAIPosition = false;
 
-                         _direction = tmpDirection;
 
-                     }
 
-                     _judgePosition = _currentPosition;
 
-                 }
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// Reset
 
-         /// </summary>
 
-         /// <param name="cmd"></param>
 
-         /// <param name="args"></param>
 
-         /// <returns></returns>
 
-         public bool ResetOperation(string cmd, bool lastNeedSwitchoff)
 
-         {
 
-             if(_status==RState.Running)
 
-             {
 
-                 LOG.WriteLog(eEvent.ERR_LINMOT,Module.ToString(), $"{Module} current execute {_currentOperation},cannot Reset");
 
-                 return false;
 
-             }
 
-             if(!LinMotDeviceConfigManager.Instance.GetDeviceConnect(Module))
 
-             {
 
-                 LOG.WriteLog(eEvent.ERR_LINMOT, Module.ToString(), $"device is not connected");
 
-                 return false;
 
-             }
 
-             _currentOperation = LinMotOperation.Reset;
 
-             _status= _resetRoutine.Start(lastNeedSwitchoff);
 
-             _direction = "";
 
-             return _status==RState.Running;
 
-         }
 
-         /// <summary>
 
-         /// 开始Curve
 
-         /// </summary>
 
-         /// <param name="cmd"></param>
 
-         /// <param name="args"></param>
 
-         /// <returns></returns>
 
-         public bool StartCurveOperation(string cmd, object[] args)
 
-         {
 
-             if (_status == RState.Running)
 
-             {
 
-                 EV.PostAlarmLog(Module.ToString(), eEvent.INFO_LINMOT, $"{Module} current execute {_currentOperation},cannot curve");
 
-                 return false;
 
-             }
 
-             _motorTime = DateTime.Now;
 
-             object[] param= (object[])args[1];
 
-             int speed = (int)param[0];
 
-             return StartCurve(speed);
 
-         }
 
-         /// <summary>
 
-         /// 开始Curve
 
-         /// </summary>
 
-         /// <param name="speed"></param>
 
-         /// <returns></returns>
 
-         public bool StartCurve(int speed)
 
-         {
 
-             _currentOperation = LinMotOperation.StartCurve;
 
-             _curverSpeed = speed;
 
-             _status= _startContinueCurveRoutine.Start(_curverSpeed);
 
-             LOG.WriteLog(eEvent.INFO_LINMOT, Module, $"Start Curve With Speed {_curverSpeed}%");
 
-             return _status==RState.Running;
 
-         }
 
-         /// <summary>
 
-         /// 开始Curve速度
 
-         /// </summary>
 
-         /// <param name="speed"></param>
 
-         /// <returns></returns>
 
-         public bool ChangeCurveSpeed(int speed)
 
-         {
 
-             _curverSpeed= speed;
 
-             return WriteRamIntValue(0xCB, 0x14, speed * 100);
 
-         }
 
-         /// <summary>
 
-         /// 开始移动(GAI Goto Position)
 
-         /// </summary>
 
-         /// <param name="cmd"></param>
 
-         /// <param name="args"></param>
 
-         /// <returns></returns>
 
-         public bool StartPosition(string cmd, object[] args)
 
-         {
 
-             if (_linMotDeviceParam == null || _linMotDeviceParam.LinMotDeviceData == null)
 
-             {
 
-                 LOG.WriteLog(eEvent.ERR_LINMOT, Module.ToString(), $"{Module} config error");
 
-                 return false;
 
-             }
 
-             if (_status == RState.Running)
 
-             {
 
-                 LOG.WriteLog(eEvent.ERR_LINMOT,Module.ToString(), $"{Module} current execute {_currentOperation},cannot Start VAI Go To Position");
 
-                 return false;
 
-             }
 
-             _currentOperation = LinMotOperation.StartVAIGoToPosition;
 
-             if (_linMotDeviceParam.LinMotDeviceData.TopPosition < 0)
 
-             {
 
-                 _direction = "up";
 
-             }
 
-             else
 
-             {
 
-                 _direction = "down";
 
-             }
 
-             _startDirection = _direction;
 
-             _judgePosition = _currentPosition;
 
-             _startPosition = _currentPosition;
 
-             int totalScan = (int)args[0] ;
 
-             _status= _startVAIPositionRoutine.Start(totalScan, _linMotDeviceParam.LinMotDeviceData);
 
-             return _status==RState.Running;
 
-         }
 
-         /// <summary>
 
-         /// SwitchOff
 
-         /// </summary>
 
-         /// <param name="cmd"></param>
 
-         /// <param name="args"></param>
 
-         /// <returns></returns>
 
-         private bool AbortOperation(string cmd, object[] args)
 
-         {            
 
-             if(_currentOperation==LinMotOperation.StartVAIGoToPosition)
 
-             {
 
-                 _startVAIPositionRoutine.Abort();
 
-             }
 
-             _currentOperation = LinMotOperation.None;
 
-             _status = RState.End;
 
-             _direction = "";
 
-             LOG.WriteLog(eEvent.INFO_LINMOT, Module, "switch off");
 
-             return SendOperation(LinMotOperation.SwitchOff);
 
-         }
 
-         
 
-         /// <summary>
 
-         /// 更新linmot速度参数
 
-         /// </summary>
 
-         /// <param name="cmd"></param>
 
-         /// <param name="args"></param>
 
-         /// <returns></returns>
 
-         private bool UpdateSpeedDataOperation(string cmd, object[] args)
 
-         {
 
-             string name = args[0].ToString();
 
-             string direction = args[1].ToString();
 
-             double maxSpeed = (double)args[2];
 
-             int maxAcc = (int)args[3];
 
-             int maxDec = (int)args[4];
 
-             LinMotDeviceConfigManager.Instance.UpdateSpeedData(name, direction, maxSpeed,maxAcc,maxDec);
 
-             LOG.WriteLog(eEvent.INFO_LINMOT, Module, $"{Module} Speed related paramater was updated");
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 发送Curve指令 
 
-         /// </summary>
 
-         private void SendCurveCommand()
 
-         {
 
-             _motorTime = DateTime.Now;
 
-             _sendTime = DateTime.Now;
 
-             LinMotDeviceConfigManager.Instance.SendCurveOperation(Module.ToString(), _linmotId, _curveId,(ushort)_curverSpeed);
 
-         }
 
-         /// <summary>
 
-         /// 发送GAI GoToPosition
 
-         /// </summary>
 
-         /// <param name="position"></param>
 
-         /// <param name="speed"></param>
 
-         /// <param name="accel"></param>
 
-         /// <param name="decel"></param>
 
-         public bool SendVAIGoToPosition(int position,int speed,int accel,int decel)
 
-         {
 
-             _motorTime = DateTime.Now;
 
-             _sendTime = DateTime.Now;
 
-             return LinMotDeviceConfigManager.Instance.SendVAIGotoPosition(Module.ToString(), _linmotId, position, speed,accel, decel);
 
-         }
 
-         /// <summary>
 
-         /// Parameter Write RAM
 
-         /// </summary>
 
-         /// <param name="lowByte"></param>
 
-         /// <param name="highByte"></param>
 
-         /// <param name="intValue"></param>
 
-         /// <returns></returns>
 
-         public bool WriteRamIntValue(byte lowByte,byte highByte,int intValue)
 
-         {
 
-             _sendTime = DateTime.Now;
 
-             return LinMotDeviceConfigManager.Instance.SendWriteRamIntValue(Module.ToString(), _linmotId, lowByte, highByte, intValue);
 
-         }
 
-         /// <summary>
 
-         /// 发送Command Table
 
-         /// </summary>
 
-         /// <param name="entryId"></param>
 
-         /// <returns></returns>
 
-         public bool SendCommandTableOperation(short entryId)
 
-         {
 
-             _motorTime = DateTime.Now;
 
-             _sendTime = DateTime.Now;
 
-             return LinMotDeviceConfigManager.Instance.SendCommandTable(Module.ToString(), _linmotId, entryId);
 
-         }
 
-         /// <summary>
 
-         /// 发送GAI GoToPositionAfterActualCommand
 
-         /// </summary>
 
-         /// <param name="position"></param>
 
-         /// <param name="speed"></param>
 
-         /// <param name="accel"></param>
 
-         /// <param name="decel"></param>
 
-         public bool SendGAIGoToPositionAfterActualCommand(int position, int speed, int accel, int decel)
 
-         {
 
-             _motorTime = DateTime.Now;
 
-             _sendTime = DateTime.Now;
 
-            return  LinMotDeviceConfigManager.Instance.SendVAIGotoPositionAfterActualCommand(Module.ToString(), _linmotId,position, speed, accel, decel);
 
-         }
 
-         /// <summary>
 
-         /// 停止
 
-         /// </summary>
 
-         /// <param name="cmd"></param>
 
-         /// <param name="args"></param>
 
-         /// <returns></returns>
 
-         public bool StopOperation(string cmd, object[] args)
 
-         {
 
-             if (_currentOperation==LinMotOperation.StopMotor)
 
-             {
 
-                 LOG.WriteLog(eEvent.WARN_LINMOT, Module, "current operation is stop motor,cannot repet stop motor");
 
-                 return false;
 
-             }
 
-             if (_currentOperation==LinMotOperation.StartVAIGoToPosition)
 
-             {
 
-                 _startVAIPositionRoutine.Abort();
 
-             }
 
-             _status = RState.Running;
 
-             _currentOperation = LinMotOperation.StopMotor;
 
-             _stopMotorRoutine.Start(LastSwitchOff);
 
-             _direction = "";
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 定时器
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public bool OnTimer()
 
-         {
 
-             if (_status == RState.Running)
 
-             {
 
-                 IRoutine routine = GetCurrentRoutine();
 
-                 if (routine != null)
 
-                 {
 
-                     RState rsState = routine.Monitor();
 
-                     if (rsState == RState.Failed || rsState == RState.Timeout)
 
-                     {
 
-                         _status = RState.Failed;
 
-                         _currentOperation = LinMotOperation.None;
 
-                     }
 
-                     else if (rsState == RState.End)
 
-                     {
 
-                         _status = RState.End;
 
-                         _currentOperation = LinMotOperation.None;
 
-                     }
 
-                 }
 
-             }
 
-             SendReadStatusCommand();
 
-             if(DateTime.Now.Subtract(_statusWordDateTime).TotalSeconds>=2)
 
-             {
 
-                 _statusWord = 0;
 
-                 UpdateStatusWord(_statusWord);
 
-             }
 
-             return true;
 
-         }
 
-         /// <summary>
 
-         /// 当前Routine;
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         private IRoutine GetCurrentRoutine()
 
-         {
 
-             switch(_currentOperation)
 
-             {
 
-                 case LinMotOperation.StartVAIGoToPosition:
 
-                     return _startVAIPositionRoutine;
 
-                 case LinMotOperation.StartCurve:
 
-                     return _startContinueCurveRoutine;
 
-                 case LinMotOperation.Reset:
 
-                     return _resetRoutine;
 
-                 case LinMotOperation.StopMotor:
 
-                     return _stopMotorRoutine;
 
-                 default:
 
-                     return null;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 监控
 
-         /// </summary>
 
-         public void Monitor()
 
-         {
 
-            
 
-         }
 
-         /// <summary>
 
-         /// 发送读取状态命令
 
-         /// </summary>
 
-         private void SendReadStatusCommand()
 
-         {
 
-             if (LinMotDeviceConfigManager.Instance.GetDeviceConnect(Module.ToString()))
 
-             {
 
-                 if (DateTime.Now.Subtract(_sendTime).TotalMilliseconds >= 500)
 
-                 {
 
-                     SendOperation(LinMotOperation.ReadStatus);
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 _statusWord = 0;
 
-                 UpdateStatusWord(_statusWord);
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 发送消息
 
-         /// </summary>
 
-         /// <param name="operation"></param>
 
-         public bool SendOperation(LinMotOperation operation)
 
-         {
 
-             _sendTime = DateTime.Now;
 
-              return LinMotDeviceConfigManager.Instance.SendOperation(Module.ToString(), _linmotId,operation);
 
-         }
 
-         /// <summary>
 
-         /// 掉电
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         public bool SwitchOff()
 
-         {
 
-             return SendOperation(LinMotOperation.SwitchOff);
 
-         }
 
-         /// <summary>
 
-         /// 中止
 
-         /// </summary>
 
-         public void AbortCurrentRoutine()
 
-         {
 
-             StopOperation("", null);
 
-         }
 
-         public bool Initialize()
 
-         {
 
-             return true;
 
-         }
 
-         public void Terminate()
 
-         {
 
-             StopOperation("", null);
 
-         }
 
-         public void Reset()
 
-         {
 
-         }
 
-     }
 
- }
 
 
  |