Пример #1
0
 /// <summary>
 /// 启动
 /// </summary>
 public virtual bool Start()
 {
     try
     {
         IPAddress  ip   = IPAddress.Parse(ComPara.ServerIP);
         IPEndPoint ipep = new IPEndPoint(ip, ComPara.Port);//IP和端口
         Tcpsocket.Bind(new IPEndPoint(IPAddress.Parse(CoreData.SysParameter["LocalIP"]), 0));
         Tcpsocket.Connect(new IPEndPoint(ip, ComPara.Port));
         CurrToken = Guid.NewGuid().ToString();
         Communication(CurrToken);
         LastRecTime = DateTime.Now;
         return(true);
     }
     catch (Exception ex)
     {
         CarBaseStateInfo car = new CarBaseStateInfo();
         car.AgvID        = this.DeviceID;
         car.bIsCommBreak = true;
         DelegateState.InvokeCarFeedbackEvent(car);
         return(false);
     }
     finally
     {
         communicationobserve_timer.Enabled = true;
     }
 }
Пример #2
0
        /// <summary>
        /// 通讯状态观察
        /// </summary>
        private void CommunicationObser(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                communicationobserve_timer.Enabled = false;

                //先判断小车是否已经掉线
                if (LastRecLong > 2)
                {
                    //如果接受消息时间已经大于2秒,则认为车子掉线了。
                    DelegateState.InvokeDispatchStateEvent(this.DeviceID.ToString() + "车,已经掉线,将在1秒后重新尝试连接...");
                    //通知调度程序  小车已经掉线
                    CarBaseStateInfo car = new CarBaseStateInfo();
                    car.bIsCommBreak = true;
                    car.AgvID        = this.DeviceID;
                    DelegateState.InvokeCarFeedbackEvent(car);
                    if (LastConnectLong > 3)
                    {
                        //如果车子掉线且连接时间超过3秒则需要重连
                        LogHelper.WriteLog("重连小车" + DeviceID.ToString());
                        ReConnect();
                    }
                }
            }
            catch (Exception ex)
            {
                DelegateState.InvokeDispatchStateEvent(this.DeviceID.ToString() + "车,观察线程异常");
                LogHelper.WriteErrorLog(ex);
            }
            finally
            {
                { communicationobserve_timer.Enabled = true; }
            }
        }
Пример #3
0
 /// <summary>
 /// 重新创建连接
 /// </summary>
 public void ReConnect()
 {
     try
     {
         //LastConnectTime = DateTime.Now;
         if (Init())
         {
             CarBaseStateInfo car = new CarBaseStateInfo();
             car.AgvID = this.DeviceID;
             if (ReStart())
             {
                 LastConnectTime = DateTime.Now;
             }
             else
             {
                 //DelegateState.InvokeDispatchStateEvent("尝试连接" + this.DeviceID.ToString() + "车失败,将在1秒后重新尝试连接...");
                 //car.bIsCommBreak = true;
                 //DelegateState.InvokeCarFeedbackEvent(car);
             }
         }
     }
     catch (Exception ex)
     {
         LogHelper.WriteErrorLog(ex);
         //DelegateState.InvokeDispatchStateEvent("尝试连接" + this.DeviceID.ToString() + "车异常,将在3秒后重新尝试连接...");
     }
 }
Пример #4
0
 /// <summary>
 /// 判断是否改变
 /// </summary>
 /// <param name="car"></param>
 /// <returns></returns>
 public bool IsChange(CarBaseStateInfo car)
 {
     if (/*CurrSite != car.CurrSite ||*/ ErrorMessage != car.ErrorMessage || bIsCommBreak != car.bIsCommBreak ||
         ((DateTime.Now - PreCoordinateTime).TotalMilliseconds > 500) || CarState != car.CarState)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #5
0
 /// <summary>
 /// 触发小车反馈消息时事件
 /// </summary>
 /// <param name="e"></param>
 public static async void InvokeCarFeedbackEvent(CarBaseStateInfo e)
 {
     try
     {
         await Task.Factory.StartNew(() =>
         {
             CarFeedbackEvent?.Invoke(e);
         });
     }
     catch (Exception ex)
     {
         LogHelper.WriteErrorLog(ex);
     }
 }
Пример #6
0
 /// <summary>
 /// 重新创建连接
 /// </summary>
 public void ReConnect()
 {
     try
     {
         //LastConnectTime = DateTime.Now;
         if (Init())
         {
             CarBaseStateInfo car = new CarBaseStateInfo();
             car.AgvID       = this.DeviceID;
             LastConnectTime = DateTime.Now;
             ReStart();
         }
     }
     catch (Exception ex)
     {
         DelegateState.InvokeDispatchStateEvent("尝试连接" + this.DeviceID.ToString() + "车异常,将在3秒后重新尝试连接...");
     }
 }
Пример #7
0
 private bool Valid()
 {
     try
     {
         if (gvDetail.FocusedRowHandle < 0)
         {
             return(true);
         }
         CarBaseStateInfo currCar = bsDetail[gvDetail.FocusedRowHandle] as CarBaseStateInfo;
         if (currCar == null)
         {
             return(false);
         }
         if (string.IsNullOrEmpty(currCar.CarName))
         {
             MsgBox.ShowWarn("请维护车辆名称!");
             return(false);
         }
         if (string.IsNullOrEmpty(currCar.CarIP.Trim()))
         {
             MsgBox.ShowWarn("请维护车辆IP!");
             return(false);
         }
         if (string.IsNullOrEmpty(currCar.CarPort.Trim()))
         {
             MsgBox.ShowWarn("请维护车辆端口号!");
             return(false);
         }
         if (string.IsNullOrEmpty(currCar.StandbyLandMark.Trim()))
         {
             MsgBox.ShowWarn("请维护车辆待命地标!");
             return(false);
         }
         //LandmarkInfo land = AGVClientDAccess.LoadLandByCode(currCar.StandbyLandMark.Trim());
         //if (land == null)
         //{
         //    MsgBox.ShowWarn("车辆待命地标不存在!");
         //    return false;
         //}
         return(true);
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); return(false); }
 }
Пример #8
0
 /// <summary>
 /// 初始化
 /// </summary>
 public virtual bool Init()
 {
     try
     {
         Clear();
         Tcpsocket = new Socket(AddressFamily.InterNetwork,
                                SocketType.Stream, ProtocolType.Tcp);
         Tcpsocket.ReceiveTimeout = 200;
         return(true);
     }
     catch (Exception ex)
     {
         CarBaseStateInfo car = new CarBaseStateInfo();
         car.AgvID        = this.DeviceID;
         car.bIsCommBreak = true;
         DelegateState.InvokeCarFeedbackEvent(car);
         return(false);
     }
 }
Пример #9
0
 /// <summary>
 /// 获取值
 /// </summary>
 /// <param name="car"></param>
 /// <returns></returns>
 public void GetValue(CarBaseStateInfo car)
 {
     X               = car.X;
     Y               = car.Y;
     JCState         = car.JCState;
     speed           = car.speed;
     Angel           = car.Angel;
     fVolt           = car.fVolt;
     PBSValue        = car.PBSValue;
     CurrSite        = car.CurrSite;
     CarState        = car.CarState;
     bIsCommBreak    = car.bIsCommBreak;
     IsUpLand        = car.IsUpLand;
     IsUpQCode       = car.IsUpQCode;
     ErrorMessage    = car.ErrorMessage;
     BangState       = car.BangState;
     IsNeedFinshTask = car.IsNeedFinshTask;
     IsNeedRedoTask  = car.IsNeedRedoTask;
 }
Пример #10
0
 private void btnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         gvDetail.CloseEditor();
         if (bsDetail.Count > 0)
         {
             if (!Valid())
             {
                 return;
             }
         }
         CarBaseStateInfo newCar = new CarBaseStateInfo()
         {
             AgvID = bsDetail.Count + 1
         };
         bsDetail.Add(newCar);
         bsDetail.MoveLast();
         bsDetail.ResetBindings(false);
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }