/// <summary>
        /// 发送并获取反馈
        /// </summary>
        /// <param name="frame"></param>
        /// <param name="timeout">超时时间,单位ms</param>
        /// <returns></returns>
        public AGVComFrame SendAndGet(AGVComFrame frame, int timeout = 300)
        {
            if (null == frame || null == frame.Pack())
            {
                return(null);
            }

            int ret = socket.Send(frame.Pack());

            if (ret > 0)
            {
                if (socket.Poll(timeout * 1000, SelectMode.SelectRead))
                {
                    byte[] buf = new byte[socket.Available];
                    socket.Receive(buf);
                    return(new AGVComFrame().Parse(buf));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        public static AGVComFrame NoData_Request(AGVTypes type)
        {
            AGVComFrame frame = new AGVComFrame(new AGVProtocolHeader()
            {
                type = (UInt16)type, length = 0
            }, null);

            return(frame);
        }
Пример #3
0
 public static bool CheckResponse(AGVTypes sendType, ref AGVComFrame response)
 {
     if (null != response && response.header.type == (UInt16)(sendType + AGVProtocolHeader.TypeResponseOffset))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #4
0
        /// <summary>
        /// 发送并获取反馈
        /// </summary>
        /// <param name="frame"></param>
        /// <param name="timeout">超时时间,单位ms</param>
        /// <returns></returns>
        public AGVComFrame SendAndGet(AGVComFrame frame, int timeout = 300)
        {
            if (null != frame)
            {
                var msg = client.WriteLineAndGetReply(frame.Pack(), new TimeSpan(0, 0, 0, 0, timeout));
                if (null == msg)
                {
                    return(null);
                }

                return(new AGVComFrame().Parse(msg.Data));
            }
            else
            {
                return(null);
            }
        }
Пример #5
0
        public static AGVTaskStatus Response_状态_查询机器人导航状态(ref AGVComFrame response)
        {
            if (CheckResponse(AGVTypes.状态_查询机器人导航状态, ref response))
            {
                AGVTaskStatus status = null;
                try
                {
                    string data = System.Text.ASCIIEncoding.UTF8.GetString(response.data);
                    status = JsonConvert.DeserializeObject <AGVTaskStatus>(data);
                }
                catch
                {
                }
                return(status);
            }

            return(null);
        }