GetSendData.cs 4.83 KB
using XingYe_ACS.BaseStruct;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XingYe_ACS.Common
{
    public class GetSendData
    {
        /// <summary>
        /// 获取新动作
        /// </summary>
        /// <param name="agvMsg">小车信息</param>
        /// <param name="listMotion">动作列表</param>
        /// <returns></returns>
        public static byte[] GetNewActionData(int intSonTaskNo, List<ClientMotion> listMotion)
        {
            byte[] Data = new byte[73];
            Data[0] = 69;
            //任务号
            byte[] TaskNo = new byte[4];
            TaskNo = BitConverter.GetBytes(UInt32.Parse(intSonTaskNo.ToString()));
            Data[1] = TaskNo[0];
            Data[2] = TaskNo[1];
            Data[3] = TaskNo[2];
            Data[4] = TaskNo[3];
            //手动控制
            if (listMotion == null)
            {
                //关机
                if (intSonTaskNo == 21) { Data[5] = 21; }

                //手动控制
                //1代表开始手动动作;0代表结束当前动作
                if (intSonTaskNo != 0) Data[71] = 1;
                else
                {
                    Data[71] = (byte)intSonTaskNo;
                }
                //手动控制动作类型
                Data[72] = (byte)intSonTaskNo;
                for (int i = 1; i < 5; i++) { Data[i] = 0; }
            }
            else if (listMotion.Count != 0)
            {
                Data[5] = (byte)listMotion[0].intTaskType; //动作类型
                int DTypeIndex = 0;
                foreach (ClientMotion newMotion in listMotion)
                {
                    byte[] BarCode1 = new byte[4];
                    byte[] DXpos = new byte[2];
                    byte[] DYpos = new byte[2];
                    byte[] DXdis = new byte[2];
                    byte[] DYdis = new byte[2];

                    UInt32 barCode1 = UInt32.Parse(newMotion.strBarcode);    //码值
                    BarCode1 = BitConverter.GetBytes(barCode1);
                    Data[6 + DTypeIndex] = BarCode1[0];
                    Data[7 + DTypeIndex] = BarCode1[1];
                    Data[8 + DTypeIndex] = BarCode1[2];
                    Data[9 + DTypeIndex] = BarCode1[3];

                    Int16 xpos = (Int16)newMotion.intX; //X坐标
                    DXpos = BitConverter.GetBytes(xpos);
                    Data[10 + DTypeIndex] = DXpos[0];
                    Data[11 + DTypeIndex] = DXpos[1];

                    Int16 ypos = (Int16)newMotion.intY;  //Y坐标
                    DYpos = BitConverter.GetBytes(ypos);
                    Data[12 + DTypeIndex] = DYpos[0];
                    Data[13 + DTypeIndex] = DYpos[1];

                    Int16 xdis = (Int16)newMotion.intXLength; //X间距
                    DXdis = BitConverter.GetBytes(xdis);
                    Data[14 + DTypeIndex] = DXdis[0];
                    Data[15 + DTypeIndex] = DXdis[1];

                    Int16 ydis = (Int16)newMotion.intYLength; //Y间距
                    DYdis = BitConverter.GetBytes(ydis);
                    Data[16 + DTypeIndex] = DYdis[0];
                    Data[17 + DTypeIndex] = DYdis[1];

                    Data[18 + DTypeIndex] = (byte)newMotion.intOriAgv;//车头方向
                    Data[19 + DTypeIndex] = (byte)newMotion.intPathPointType;//点属性
                    Data[20 + DTypeIndex] = (byte)newMotion.intAntiCollision;//防撞属性
                    Data[21 + DTypeIndex] = (byte)newMotion.intOriDial;//托盘属性

                    DTypeIndex = DTypeIndex + 16;
                }
            }
            else
            {
                Data[5] = 99; //动作类型
                string strFinish = string.Format("完成信号:", Data[5].ToString());
                App.ExFile.MessageLog("FinishSign", strFinish);
            }

            Data[70] = ComnMethod.checkCode(Data, 71);
            return Data;
        }

        public static byte[] GetBarcodeData(int intSonTaskNo, string Barcode)
        {
            byte[] Data = new byte[73];
            Data[0] = 69;
            Data[5] = (byte)103; //动作类型
            byte[] BarCode1 = new byte[4];
            UInt32 barCode1 = UInt32.Parse(Barcode);    //码值
            BarCode1 = BitConverter.GetBytes(barCode1);
            Data[6] = BarCode1[0];
            Data[7] = BarCode1[1];
            Data[8] = BarCode1[2];
            Data[9] = BarCode1[3];
            return Data;
        }


        /// <summary>
        /// 关机
        /// </summary>
        /// <returns></returns>
        public static byte[] GetOffData()
        {
            byte[] Data = new byte[4];
            Data[0] = 0;
            Data[1] = 5;
            Data[2] = 0;
            Data[3] = ComnMethod.checkCode(Data, 4);
            return Data;
        }
    }
}