Exemplo n.º 1
0
 public AGVSession_OMARK_New(int agvid, AGVComPara compara) : base()
 {
     this.DeviceID   = agvid;
     this.DeviceType = 0;
     communicationobserve_timer.Elapsed += new System.Timers.ElapsedEventHandler(CommunicationObser);
     this.ComPara    = ComPara;
     this.DeviceName = "AGV小车";
 }
Exemplo n.º 2
0
 public AGVSession_OMARK(int agvid, AGVComPara ComPara) : base()
 {
     try
     {
         this.DeviceID   = agvid;
         this.DeviceType = 0;
         this.DeviceName = "AGV小车";
         this.ComPara    = ComPara;
         communicationobserve_timer.Elapsed += new System.Timers.ElapsedEventHandler(CommunicationObser);
         connect    = ConnectSocket;
         SocketSend = SendData;
     }
     catch (Exception ex)
     {
         LogHelper.WriteErrorLog(ex);
     }
 }
Exemplo n.º 3
0
 public IOSession_Fbell(int IOID, AGVComPara ComPara) : base()
 {
     try
     {
         this.DeviceID   = IOID;
         this.DeviceType = 2;
         this.DeviceName = IOID.ToString() + "号IO设备";
         this.ComPara    = ComPara;
         communicationobserve_timer.Elapsed += new System.Timers.ElapsedEventHandler(CommunicationObser);
         connect = ConnectSocket;
         //SocketSend = SendData;
         ////初始化读
         //readbytelist.AddRange(BitConverter.GetBytes(NextDataIndex()));
         //readbytelist.AddRange(new byte[] { 0x00, 0x00 });
         //readbytelist.AddRange(new byte[] { 0x00, 0x06 });
         //readbytelist.Add((byte)IOID);
         //readbytelist.Add(0x03);
         //readbytelist.AddRange(new byte[] { 0x01, 0x2c, 0x00, 0x02 });
     }
     catch (Exception ex)
     { LogHelper.WriteErrorLog(ex); }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 通讯初始化
        /// </summary>
        public bool CommInit()
        {
            try
            {
                #region 小车
                DispatchAssembly AgvCommunitClass = CoreData.DispathAssemblies.FirstOrDefault(p => p.AssemblyType == 0);
                if (AgvCommunitClass == null)
                {
                    DelegateState.InvokeDispatchStateEvent("未配置AGV通信处理程序!");
                    LogHelper.WriteLog("未配置AGV通信处理程序!");
                    return(false);
                }

                DispatchAssembly ChargeCommunitClass = CoreData.DispathAssemblies.FirstOrDefault(q => q.AssemblyType == 1);
                if (ChargeCommunitClass == null)
                {
                    DelegateState.InvokeDispatchStateEvent("未配置充电桩通信处理程序!");
                    LogHelper.WriteLog("未配置充电桩通信处理程序!");
                    return(false);
                }

                //先停止清除所有的通信管道
                foreach (var item in AGVSessions)
                {
                    ExcuteRflectMethod(item, "Stop", null);
                }
                AGVSessions.Clear();
                //初始化所有AGV小车的通信
                foreach (CarInfo car in CoreData.CarList)
                {
                    AGVComPara para = new AGVComPara();
                    para.ServerIP = car.CarIP;
                    para.Port     = Convert.ToInt32(car.CarPort);
                    int    agvid   = Convert.ToInt32(car.AgvID);
                    Type   objType = Type.GetType(AgvCommunitClass.ClassName, true);
                    object obj     = Activator.CreateInstance(objType);
                    SetModelValue("DeviceID", agvid, obj);
                    SetModelValue("ComPara", para, obj);
                    //obj.DeviceID = agvid;
                    //obj.ComPara = para;
                    AGVSessions.Add(obj);
                }
                foreach (var item in AGVSessions)
                {
                    bool InitResult = (bool)ExcuteRflectMethod(item, "Init", null);
                    if (InitResult)
                    {
                        DelegateState.InvokeDispatchStateEvent(GetModelValue("DeviceID", item).ToString() + "号AGV通讯初始化成功");
                        LogHelper.WriteLog(GetModelValue("DeviceID", item).ToString() + "号AGV通讯初始化成功");
                    }
                    else
                    {
                        DelegateState.InvokeDispatchStateEvent(GetModelValue("DeviceID", item).ToString() + "号AGV通讯初始化失败");
                        LogHelper.WriteLog(GetModelValue("DeviceID", item).ToString() + "号AGV通讯初始化失败");
                    }
                }
                #endregion

                #region 充电桩
                foreach (var item in ChargeStationSessions)
                {
                    ExcuteRflectMethod(item, "Stop", null);
                }
                ChargeStationSessions.Clear();


                foreach (ChargeStationInfo Charge in CoreData.ChargeList)
                {
                    AGVComPara para = new AGVComPara();
                    para.ServerIP = Charge.IP;
                    para.Port     = Convert.ToInt32(Charge.Port);
                    int    ChargeID = Convert.ToInt32(Charge.ID);
                    Type   objType  = Type.GetType(ChargeCommunitClass.ClassName, true);
                    object obj      = Activator.CreateInstance(objType);
                    SetModelValue("DeviceID", ChargeID, obj);
                    SetModelValue("ComPara", para, obj);
                    ChargeStationSessions.Add(obj);
                }

                foreach (var item in ChargeStationSessions)
                {
                    bool InitResult = (bool)ExcuteRflectMethod(item, "Init", null);
                    if (InitResult)
                    {
                        DelegateState.InvokeDispatchStateEvent(GetModelValue("DeviceID", item).ToString() + "号充电桩通讯初始化成功");
                    }
                    else
                    {
                        DelegateState.InvokeDispatchStateEvent(GetModelValue("DeviceID", item).ToString() + "号充电桩通讯初始化失败");
                    }
                }
                #endregion
                #region io设备
                foreach (var item in IOSessions)
                {
                    item.Stop();
                }
                IOSessions.Clear();


                foreach (IODeviceInfo node in CoreData.IOList)
                {
                    AGVComPara para = new AGVComPara();
                    para.ServerIP = node.IP;
                    para.Port     = Convert.ToInt32(node.Port);
                    int ioid = Convert.ToInt32(node.ID);
                    IOSessions.Add(new IOSession_Fbell(ioid, para));
                }

                foreach (var item in IOSessions)
                {
                    if (item.Init())
                    {
                        DelegateState.InvokeDispatchStateEvent(item.DeviceID.ToString() + "号IO设备通讯初始化成功");
                    }
                    else
                    {
                        DelegateState.InvokeDispatchStateEvent(item.DeviceID.ToString() + "号IO设备通讯初始化失败");
                    }
                }
                #endregion
                return(true);
            }
            catch (Exception ex)
            {
                DelegateState.InvokeDispatchStateEvent("初始化客户端通讯异常");
                LogHelper.WriteErrorLog(ex);
                return(false);
            }
        }