StoreMoveInfo.cs 13.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
 

namespace OnlineStore.DeviceLibrary
{
    /// <summary>
    /// 料仓当前运动信息类(出入库状态,步骤记录)
    /// </summary>
    public class StoreMoveInfo
    {
        private string Name;
        /// <summary>
        /// 超时时间
        /// </summary>
        public int TimeOutSeconds = 60;
        public StoreMoveInfo(int storeId,string name)
        {
            this.Name = name;
            moveType = StoreMoveType.None;
            
            MoveParam = new InOutParam();
            this.storeId = storeId;
            this.moveStep = StoreMoveStep.Wait;
            IsInWait = false;
            MoveNum = 0;
        }

        public int MoveNum { get; set; }

        public DateTime LastSetpTime { get; set; }

        /// <summary>
        /// =true表示满足一个等待条件,就可以完成此步骤的等待
        /// </summary>
        public bool OneWaitCanEndStep = false;
        
        /// <summary>
        /// 操作类型
        /// </summary>
        private StoreMoveType moveType = StoreMoveType.None;

        public StoreMoveType MoveType
        {
            get { return moveType; }
        }
        public TimeSpan StepSpan()
        {
            TimeSpan span = DateTime.Now - LastSetpTime;
            return span;
        }
        public bool IsTimeOut(int timeOutSeconds = 60)
        {
            TimeSpan span = DateTime.Now - LastSetpTime;
            if (span.TotalSeconds > timeOutSeconds)
            {
                return true;
            }
            return false;
        }
        /// <summary>
        ///出入库参数
        /// </summary>
        public InOutParam MoveParam { get; set; }
        /// <summary>
        /// 当前运动是哪个料仓
        /// </summary>
        public int storeId { get; set; }

        /// <summary>
        /// 是否再当前步骤等待中
        /// </summary>
        public bool IsInWait { get; set; }
        /// <summary>
        /// 上一个执行步骤
        /// </summary>
        public StoreMoveStep PreMoveStep { get; set; }
        /// <summary>
        /// 当前执行到的步骤
        /// </summary>
        private StoreMoveStep moveStep;
        /// <summary>
        /// 可以循环运动的次数(轴卡运动才需要)
        /// </summary>
        public int CanWhileCount = 0;
        /// <summary>
        /// 料仓运动步骤记录
        /// </summary>
        public StoreMoveStep MoveStep
        {
            get { return moveStep; }
        }
 
        public void NextMoveStep(StoreMoveStep step)
        {
            stepMoveLog();
            PreMoveStep = moveStep;
            moveStep = step;
            LastSetpTime = DateTime.Now; 
            IsInWait = true;
            WaitList = new List<WaitResultInfo>();
            OneWaitCanEndStep = false;
            CanWhileCount = 5;
            TimeOutSeconds = 60;
        }
        /// <summary>
        /// 当前步骤执行完成
        /// </summary>
        public void EndStepWait()
        {
            IsInWait = false;
            WaitList = new List<WaitResultInfo>();
        }
        public void NewMove(StoreMoveType type )
        {
            moveStep = StoreMoveStep.Wait;
            this.moveType = type; 
            LastSetpTime = DateTime.Now;
            WaitList = new List<WaitResultInfo>();
            MoveNum++;
        }
        public void NewMove(StoreMoveType type, InOutParam param)
        {
            moveStep = StoreMoveStep.Wait;
            this.moveType = type;
            this.MoveParam = param;
            LastSetpTime = DateTime.Now;
            WaitList = new List<WaitResultInfo>();
        }
        public void EndMove()
        {
            stepMoveLog();
            this.moveType = StoreMoveType.None;
            this.MoveParam = null; 
            moveStep = StoreMoveStep.Wait;
            LastSetpTime = DateTime.Now;
            IsInWait = false;
            WaitList = new List<WaitResultInfo>();
            CanWhileCount = 0;
        }
        public StoreMoveInfo clone()
        {
            return (StoreMoveInfo)this.MemberwiseClone();
        }

        public List<WaitResultInfo> WaitList = new List<WaitResultInfo>();
        /// <summary>
        /// 重置之后继续出入库时,退回上一个步骤执行
        /// </summary>
        public void BackStep()
        {
            moveStep = PreMoveStep;
            IsInWait = false;
        }
        private void stepMoveLog()
        {
            try
            {
                RunLogUtil.MoveLog(new MoveLog(Name, GetMoveType(), GetStepDes(), LastSetpTime, DateTime.Now, MoveParam.PosInfo?.PosId, MoveParam.PosInfo?.barcode));
            }
            catch (Exception ex)
            {

            }
        }
        public string GetStepDes()
        {
            string currName = moveStep.ToString();
            try
            {
                if (StoreManager.StepDesMap.ContainsKey(currName))
                {
                    return StoreManager.StepDesMap[currName];
                }
            }
            catch (Exception ex)
            {
                LogUtil.error("GetStepDes 出错:" + ex.ToString());
            }
            return currName;
        }
        public string GetMoveType()
        {
            switch (moveType)
            {
                case StoreMoveType.InStore:
                    return "入料";
                    break;
                case StoreMoveType.OutStore:
                    return "出料";
                    break;
                case StoreMoveType.StoreReset:
                    return "复位";
                    break;
                case StoreMoveType.ReturnHome:
                    return "回原";
                    break;
            }
            return "";
        }

    }
    public static class EnumDesHelper
    {
        public static string GetStepDes(this Enum val)
        {
            var type = val.GetType();

            var memberInfo = type.GetMember(val.ToString());

            var attributes = memberInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);

            if (attributes == null || attributes.Length != 1)
            {
                //如果没有定义描述,就把当前枚举值的对应名称返回
                return val.ToString();
            }

            return (attributes.Single() as DescriptionAttribute).Description;
        }
    }
    public class WaitResultInfo
    {
        private WaitResultInfo()
        {
        }

        public static  WaitResultInfo WaitIO(string ioType, IO_VALUE ioValue)
        {
            WaitResultInfo wait = new WaitResultInfo();
            wait.CanWhileMoveCount = 0;
            wait.WaitType = 2;
            wait.IoType = ioType;
            wait.IoValue = ioValue;
            wait.IsEnd = false;
            return wait;
        }
        public static WaitResultInfo WaitAxis(ConfigMoveAxis axis,int targetPosition,int targetSpeed )
        {
            WaitResultInfo wait = new WaitResultInfo();
            wait.CanWhileMoveCount = 0;
            wait.WaitType = 1;
            wait.AxisInfo = axis;
            wait.IsHomeMove = false;
            wait.TargetPosition = targetPosition;
            wait.TargetSpeed = targetSpeed;
            wait.IsEnd = false;
            return wait;
        }
        public static WaitResultInfo WaitAxisHome(ConfigMoveAxis axis, int AxisOrgValue)
        {
            WaitResultInfo wait = new WaitResultInfo();
            wait.CanWhileMoveCount = 0;
            wait.WaitType = 1;
            wait.AxisInfo = axis;
            wait.IsHomeMove = true;
            wait.IsEnd = false;
            wait.AxisOrgValue = AxisOrgValue;
            wait.LastHasOrgTime = DateTime.Now;
            return wait;
        } 
        public static WaitResultInfo WaitTime(int MScends)
        {
            WaitResultInfo wait = new WaitResultInfo();
            wait.CanWhileMoveCount = 0;
            wait.WaitType = 3;
            wait.TimeMSeconds = MScends;
            wait.IsEnd = false;
            return wait;
        }
        public static WaitResultInfo WaitAxisOrg(ConfigMoveAxis axis,IO_VALUE value )
        {
            WaitResultInfo wait = new WaitResultInfo();
            wait.CanWhileMoveCount = 0;
            wait.WaitType = 6;
            wait.AxisInfo = axis;
            wait.IsHomeMove = true;
            wait.IoValue = value;
            wait.IsEnd = false;
            return wait;
        }
        /// <summary>
        /// 等待有料
        /// </summary>
        /// <returns></returns>
        public static WaitResultInfo WaitVisionComp(string planName, IO_VALUE value)
        {
            WaitResultInfo wait = new WaitResultInfo();
            wait.CanWhileMoveCount = 0;
            wait.WaitType = 8;
            wait.IoValue = value;
            wait.IsEnd = false;
            wait.PlanName = planName;
            return wait;
        }

        //public static WaitResultInfo WaitHeight(int height)
        //{
        //    WaitResultInfo wait = new WaitResultInfo(); 
        //    wait.WaitType = 7;
        //    wait.HeightValue = height;
        //    wait.IsEnd = false;
        //    return wait;
        //}
        public string ToStr()
        {
            if (WaitType == 1)
            {
                if (IsHomeMove)
                {
                    return "轴【" + AxisInfo.DisplayStr  + "】原点返回";
                }
                else
                {
                    return "轴【" + AxisInfo.DisplayStr + "】绝对运动,目标位置【" + TargetPosition + "】";
                }
            }
            else if (WaitType == 2)
            {
                return "IO信号等待,IO类型【" + IoType + "】,等待值【" + IoValue + "】";
            }
            else if (WaitType == 3)
            {
                return "时间等待:【" + TimeMSeconds + "】毫秒";
            }
            else if (WaitType == 4)
            {
                return "电钢目标位置:【" + TargetPosition + "】 ";
            }
            else if (WaitType == 5)
            {
                return "硕科电机目标位置:【" + TargetPosition + "】 ";
            }
            else if (WaitType == 6)
            {
                return "轴【" + AxisInfo.DisplayStr  + "】ORG信号:【" + IoValue + "】 ";
            }else if (WaitType == 7)
            {
                return "料盘高度【" + HeightValue + "】  ";
            }else if (WaitType == 8)
            {
                if (IoValue.Equals(IO_VALUE.LOW))
                {
                    return "视觉识别门口无料"; 
                }
                else
                {
                    return "视觉识别门口有料"; 
                }
            }
            else 
            {
                return "Wait位置类型:WaitType=【" + WaitType + "】";
            }
        }
        /// <summary>
        /// 当未结束时可以重复运动的次数
        /// </summary>
        public int CanWhileMoveCount { get; set; }
        /// <summary>
        /// 等待结果,1=轴运动,2=IO运动,3=时间,4=电钢,5=硕科电机,6=等待轴原点信号
        /// </summary>
        public int WaitType { get; set; }
        /// <summary>
        /// 轴运动时表示轴信息
        /// </summary>
        public ConfigMoveAxis AxisInfo { get; set; }
        /// <summary>
        /// 电钢地址
        /// </summary>
        public byte SlvAddr { get; set; }
        /// <summary>
        /// IO类型
        /// </summary>
        public String  IoType { get; set; }
        /// <summary>
        /// IO值
        /// </summary>
        public IO_VALUE  IoValue { get; set; }
        /// <summary>
        /// 等待的毫秒
        /// </summary>
        public int TimeMSeconds { get; set; }
        /// <summary>
        /// 是否是原点返回
        /// </summary>
        public bool IsHomeMove = false;

        /// <summary>
        /// 轴目标位置
        /// </summary>
        public int TargetPosition { get; set; }
        /// <summary>
        /// 轴目标速度
        /// </summary>
        public int TargetSpeed { get; set; }
        /// <summary>
        /// 是否已经结束
        /// </summary>
        public bool IsEnd{ get; set; }
        /// <summary>
        /// 高度
        /// </summary>
        public int HeightValue { get; set; }


        public int AxisOrgValue = 0;
        public string PlanName = "";
        public DateTime LastHasOrgTime = DateTime.Now;

     
    }
    public enum StoreMoveType
    {
        /// <summary>
        /// 没有任何操作
        /// </summary>
        None = 0,
        /// <summary>
        /// 入库
        /// </summary>
        InStore = 1,
        /// <summary>
        /// 出库
        /// </summary>
        OutStore = 2,
        /// <summary>
        /// 原点返回
        /// </summary>
        ReturnHome = 3,
        /// <summary>
        /// 重置
        /// </summary>
        StoreReset = 4,
        ///// <summary>
        ///// 移栽装置的停止,需要先远点返回,然后停止
        ///// </summary>
        //StopMove=5,
        ///// <summary>
        ///// 移栽检测托盘
        ///// </summary>
        //CheckFixture=6,
        /// <summary>
        /// 盘点
        /// </summary>
        CheckPosition,
    }
}