Esempio n. 1
0
        /// <summary>
        /// 指令解析
        /// </summary>
        /// <param name="socketOpt">自定义Socket对象</param>
        public static void DataTranslate(SocketOpt socketOpt)
        {
            byte[] DataRecv = socketOpt.Data;
            string AgvNo    = Encoding.ASCII.GetString(DataRecv, 3, 10).Replace("\0", "");

            //try
            //{
            AgvMsg agvMsg     = new AgvMsg();
            int    DataLength = DataRecv[2];

            agvMsg.AgvNo = Encoding.ASCII.GetString(DataRecv, 3, 10).Replace("\0", "");

            socketOpt.agv = App.AgvList.FirstOrDefault(a => a.agvNo == agvMsg.AgvNo);
            if (socketOpt.agv == null)
            {
                throw new Exception("更新状态失败:找不到小车号。");
            }

            agvMsg.Barcode  = BitConverter.ToUInt32(DataRecv, 13).ToString();
            agvMsg.Voltage  = BitConverter.ToInt16(DataRecv, 17) / 100;
            agvMsg.State    = DataRecv[19];
            agvMsg.Height   = (HeightEnum)DataRecv[20];
            agvMsg.ErrCode1 = DataRecv[21];
            agvMsg.ErrCode2 = DataRecv[22];
            agvMsg.ErrCode3 = DataRecv[23];

            string sid = Encoding.ASCII.GetString(DataRecv, 26, 20).Replace("\0", "");

            if (string.IsNullOrEmpty(sid))
            {
                agvMsg.SID = 0;
            }
            else
            {
                agvMsg.SID = int.Parse(sid);
            }
            agvMsg.sTaskType = (STaskType)DataRecv[46];

            int CrcR = DataRecv[47];
            int CrcC = Commond.CRC(DataRecv, DataLength + 14);

            if (CrcC == CrcR)
            {
                Agv agv = socketOpt.agv;
                UpdateAgvShelfPoint(agvMsg, agv);

                if (agvMsg.SID == 0)
                {
                    SendTask(agvMsg, socketOpt);
                }
                else
                {
                    UpdataPointOri(agvMsg, agv);
                    AgvDoTask(agvMsg, socketOpt);
                }
            }
            //}
            //catch (Exception ex)
            //{
            //    App.ExFile.MessageLog("DataTranslate", ex.Message + "\r"
            //              + Encoding.Default.GetString(DataRecv));
            //}

            socketOpt.Data = SendData.GetRepeatData(AgvNo);
            ManageTcp.Send(socketOpt);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取新动作
        /// </summary>
        /// <param name="agvMsg">小车信息</param>
        /// <param name="listMotion">动作列表</param>
        /// <returns></returns>
        public static byte[] GetNewActionData(AgvMsg agvMsg, List <Motion> listMotion)
        {
            byte[] Data = new byte[89];
            Data[0] = 0;
            Data[1] = 3;    //功能码
            Data[2] = 75;

            byte[] DataAdress = Encoding.ASCII.GetBytes(agvMsg.AgvNo);
            for (int index = 3; index < 3 + DataAdress.Length; index++)
            {
                Data[index] = DataAdress[index - 3];
            }

            //动作报文拼接
            int DTypeIndex = 0;

            foreach (Motion 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];

                Data[13 + DTypeIndex] = (byte)newMotion.sTaskType; //动作类型

                UInt32 barCode1 = UInt32.Parse(newMotion.barcode); //码值
                BarCode1 = BitConverter.GetBytes(barCode1);
                Data[14 + DTypeIndex] = BarCode1[0];
                Data[15 + DTypeIndex] = BarCode1[1];
                Data[16 + DTypeIndex] = BarCode1[2];
                Data[17 + DTypeIndex] = BarCode1[3];

                Int16 xpos = (Int16)newMotion.x; //X坐标
                DXpos = BitConverter.GetBytes(xpos);
                Data[18 + DTypeIndex] = DXpos[0];
                Data[19 + DTypeIndex] = DXpos[1];

                Int16 ypos = (Int16)newMotion.y;  //Y坐标
                DYpos = BitConverter.GetBytes(ypos);
                Data[20 + DTypeIndex] = DYpos[0];
                Data[21 + DTypeIndex] = DYpos[1];

                Int16 xdis = (Int16)newMotion.xLength; //X间距
                DXdis = BitConverter.GetBytes(xdis);
                Data[22 + DTypeIndex] = DXdis[0];
                Data[23 + DTypeIndex] = DXdis[1];

                Int16 ydis = (Int16)newMotion.yLength; //Y间距
                DYdis = BitConverter.GetBytes(xdis);
                Data[24 + DTypeIndex] = DYdis[0];
                Data[25 + DTypeIndex] = DYdis[1];

                Data[26 + DTypeIndex] = (byte)newMotion.pointType; //点属性
                Data[27 + DTypeIndex] = 1;                         //托盘属性        是否需要??

                DTypeIndex = DTypeIndex + 15;
            }

            Data[88] = Commond.CRC(Data, 87);
            string s = Encoding.ASCII.GetString(Data, 0, Data.Length);

            App.ExFile.MessageLog("DataTranslate", s + "\r");
            return(Data);
        }