private void frmMonitor_Load(object sender, EventArgs e) { Cranes.OnCrane += new CraneEventHandler(Monitor_OnCrane); //picCrane1.Parent = pictureBox1; //InitialP1 = picCrane1.Location; //picCrane1.BackColor = Color.Transparent; InitialP2 = picCar01.Location; picCar01.Parent = pictureBox1; picCar01.BackColor = Color.Transparent; InitialP3 = picCar02.Location; picCar02.Parent = pictureBox1; picCar02.BackColor = Color.Transparent; //InitialP4 = picCrane2.Location; //picCrane2.Parent = pictureBox1; //picCrane2.BackColor = Color.Transparent; AddDicKeyValue(); try { ServerInfo[] Servers = new MonitorConfig("Monitor.xml").Servers; Conveyors.OnConveyor += new ConveyorEventHandler(Monitor_OnConveyor); Cars.OnCar += new CarEventHandler(Monitor_OnCar); Miniloads.OnMiniload += new MiniloadEventHandler(Monitor_OnMiniload); for (int i = 0; i < Servers.Length; i++) { OPCServer opcServer = new OPCServer(Servers[i].Name); opcServer.Connect(Servers[i].ProgID, Servers[i].ServerName);// opcServer.Connect(config.ConnectionString); OPCGroup group = opcServer.AddGroup(Servers[i].GroupName, Servers[i].UpdateRate); foreach (ItemInfo item in Servers[i].Items) { group.AddItem(item.ItemName, item.OpcItemName, item.ClientHandler, item.IsActive); } if (Servers[i].Name == "TranLineServer") { opcServer.Groups.DefaultGroup.OnDataChanged += new OPCGroup.DataChangedEventHandler(Conveyor_OnDataChanged); } if (Servers[i].Name == "Car0101Server" || Servers[i].Name == "Car0102Server") { opcServer.Groups.DefaultGroup.OnDataChanged += new OPCGroup.DataChangedEventHandler(Car_OnDataChanged); } if (Servers[i].Name == "MiniloadServer") { opcServer.Groups.DefaultGroup.OnDataChanged += new OPCGroup.DataChangedEventHandler(Miniload_OnDataChanged); } } } catch (Exception ex) { Logger.Error(ex.Message); } //tmCrane1.Interval = 3000; //tmCrane1.Elapsed += new System.Timers.ElapsedEventHandler(tmCraneWorker1); //tmCrane1.Start(); }
public bool BindToPLC() { opcServer = new OPCServer(); if (!opcServer.Connect()) { return(false); } if (!opcServer.AddGroup()) { return(false); } int client = 1; if (commandDB != null) { OpcRcw.Da.OPCITEMDEF[] commandItem = new OPCITEMDEF[commandDB.Length]; for (int i = 0; i < commandDB.Length; i++) { commandItem[i].szAccessPath = ""; commandItem[i].bActive = 1; commandItem[i].hClient = client; commandItem[i].dwBlobSize = 1; commandItem[i].pBlob = IntPtr.Zero; commandItem[i].vtRequestedDataType = (int)VarEnum.VT_BSTR; commandItem[i].szItemID = string.Format("S7:[S7 connection_1]{0}", commandDB[i]); client++; } if (!opcServer.AddItems(commandItem, commandHandle)) { return(false); } } isBindToPLC = true; return(isBindToPLC); }
private void frmMonitor_Load(object sender, EventArgs e) { AddDicKeyValue(); try { dtCraneError = bll.FillDataTable("WCS.SelectCraneWarning"); for (int i = 1; i <= 5; i++) { Control[] ctl = this.Controls.Find("picCrane" + i.ToString(), true); if (ctl.Length > 0) { ((PictureBox)ctl[0]).Parent = pictureBox1; ((PictureBox)ctl[0]).BackColor = Color.Transparent; } } for (int i = 101; i <= 120; i++) { Control[] ctl = this.Controls.Find("picCar" + i.ToString(), true); if (ctl.Length > 0) { ((PictureBox)ctl[0]).Visible = false; ((PictureBox)ctl[0]).Parent = pictureBox1; ((PictureBox)ctl[0]).BackColor = Color.Transparent; } } PLCS.OnPLC += new PLCEventHandler(Monitor_OnPLC); Cranes.OnCrane += new CraneEventHandler(Monitor_OnCrane); ServerInfo[] Servers = new MonitorConfig("Monitor.xml").Servers; for (int i = 0; i < Servers.Length; i++) { OPCServer opcServer = new OPCServer(Servers[i].Name); opcServer.Connect(Servers[i].ProgID, Servers[i].ServerName);// opcServer.Connect(config.ConnectionString); OPCGroup group = opcServer.AddGroup(Servers[i].GroupName, Servers[i].UpdateRate); foreach (ItemInfo item in Servers[i].Items) { group.AddItem(item.ItemName, item.OpcItemName, item.ClientHandler, item.IsActive); } if (Servers[i].Name == "CarServer") { opcServer.Groups.DefaultGroup.OnDataChanged += new OPCGroup.DataChangedEventHandler(CarServer_OnDataChanged); } else { opcServer.Groups.DefaultGroup.OnDataChanged += new OPCGroup.DataChangedEventHandler(CraneServer_OnDataChanged); } } tmCrane.Interval = 2000; tmCrane.Elapsed += new System.Timers.ElapsedEventHandler(tmCraneWorker); tmCrane.Start(); } catch (Exception ex) { Logger.Error("监控界面中frmMonitor_Load出现异常" + ex.Message); } }
private void frmMonitorA_Load(object sender, EventArgs e) { DataTable dt = Program.dtUserPermission; //监控任务--取消堆垛机任务 string filter = "SubModuleCode='MNU_W00A_00A' and OperatorCode='1'"; DataRow[] drs = dt.Select(filter); if (drs.Length <= 0) { this.btnCancel1.Visible = false; this.btnCancel2.Visible = false; this.btnCancel3.Visible = false; this.btnCancel4.Visible = false; } else { this.btnCancel1.Visible = true; this.btnCancel2.Visible = true; this.btnCancel3.Visible = true; this.btnCancel4.Visible = true; } Cranes.OnCrane += new CraneEventHandler(Monitor_OnCrane); InitialP1 = btnSRM1.Location; InitialP2 = btnSRM2.Location; InitialP3 = btnSRM3.Location; InitialP4 = btnSRM4.Location; AddDicKeyValue(); try { ServerInfo[] Servers = new MonitorConfig("MonitorA.xml").Servers; for (int i = 0; i < Servers.Length; i++) { OPCServer opcServer = new OPCServer(Servers[i].Name); opcServer.Connect(Servers[i].ProgID, Servers[i].ServerName);// opcServer.Connect(config.ConnectionString); OPCGroup group = opcServer.AddGroup(Servers[i].GroupName, Servers[i].UpdateRate); foreach (ItemInfo item in Servers[i].Items) { group.AddItem(item.ItemName, item.OpcItemName, item.ClientHandler, item.IsActive); } if (Servers[i].Name.IndexOf("PLC") >= 0) { opcServer.Groups.DefaultGroup.OnDataChanged += new OPCGroup.DataChangedEventHandler(Crane_OnDataChanged); } } } catch (Exception ex) { Logger.Error(ex.Message); } tmWorkTimer.Interval = Program.SendInterval; tmWorkTimer.Elapsed += new System.Timers.ElapsedEventHandler(tmWorker); tmWorkTimer.Start(); }
public void CreateGroup(string p_GroupName) { try { m_Group = m_Server.AddGroup(p_GroupName, true, m_ServerView.GetUpdateRate()); m_Group.DataChanged += new DataChangeEventHandler(Group_DataChange); } catch (Exception l_Ex) { Disconnect(); throw l_Ex; } }
private void frmMonitor_Load(object sender, EventArgs e) { DataTable dt = Program.dtUserPermission; //监控任务--取消堆垛机任务 string filter = "SubModuleCode='MNU_W00A_00A' and OperatorCode='1'"; DataRow[] drs = dt.Select(filter); if (drs.Length <= 0) { this.btnCancel0101.Visible = false; } else { this.btnCancel0101.Visible = true; } P2 = pictureBox2.Location; AddDicKeyValue(); Cranes.OnCrane += new CraneEventHandler(Monitor_OnCrane); Conveyors.OnConveyor+=new ConveyorEventHandler(Conveyors_OnConveyor); try { ServerInfo[] Servers = new MonitorConfig("Monitor.xml").Servers; for (int i = 0; i < Servers.Length; i++) { OPCServer opcServer = new OPCServer(Servers[i].Name); opcServer.Connect(Servers[i].ProgID, Servers[i].ServerName);// opcServer.Connect(config.ConnectionString); OPCGroup group = opcServer.AddGroup(Servers[i].GroupName, Servers[i].UpdateRate); foreach (ItemInfo item in Servers[i].Items) { group.AddItem(item.ItemName, item.OpcItemName, item.ClientHandler, item.IsActive); } if (Servers[i].Name.IndexOf("CranePLC") >= 0) { opcServer.Groups.DefaultGroup.OnDataChanged += new OPCGroup.DataChangedEventHandler(CranePLC_OnDataChanged); } if (Servers[i].Name.IndexOf("Convey") >= 0) { opcServer.Groups.DefaultGroup.OnDataChanged += new OPCGroup.DataChangedEventHandler(Convey_OnDataChanged); } } } catch (Exception ex) { Logger.Error(ex.Message); } }
public override void Initialize(string file) { opcServer = new OPCServer(Name); Config.Configuration config = new Config.Configuration(file); opcServer.Connect(config.ProgID, config.ServerName);// opcServer.Connect(config.ConnectionString); OPCGroup group = opcServer.AddGroup(config.GroupName, config.UpdateRate); foreach (Config.ItemInfo item in config.Items) { group.AddItem(item.ItemName, item.OpcItemName, item.ClientHandler, item.IsActive); } opcServer.Groups.DefaultGroup.OnDataChanged += new OPCGroup.DataChangedEventHandler(DefaultGroup_OnDataChanged); }
private void frmMonitor_Load(object sender, EventArgs e) { AddDicKeyValue(); try { ServerInfo[] Servers = new MonitorConfig("Monitor.xml").Servers; Miniloads.OnMiniload += new MiniloadEventHandler(Monitor_OnMiniload); System.Threading.Thread.Sleep(300); Cranes.OnCrane += new CraneEventHandler(Monitor_OnCrane); for (int i = 0; i < Servers.Length; i++) { OPCServer opcServer = new OPCServer(Servers[i].Name); opcServer.Connect(Servers[i].ProgID, Servers[i].ServerName);// opcServer.Connect(config.ConnectionString); OPCGroup group = opcServer.AddGroup(Servers[i].GroupName, Servers[i].UpdateRate); foreach (ItemInfo item in Servers[i].Items) { group.AddItem(item.ItemName, item.OpcItemName, item.ClientHandler, item.IsActive); } //if (Servers[i].Name == "TranLineServer") //{ // opcServer.Groups.DefaultGroup.OnDataChanged += new OPCGroup.DataChangedEventHandler(Conveyor_OnDataChanged); //} //if (Servers[i].Name == "Car0101Server" || Servers[i].Name == "Car0102Server") //{ // //opcServer.Groups.DefaultGroup.OnDataChanged += new OPCGroup.DataChangedEventHandler(Car_OnDataChanged); //} if (Servers[i].Name.IndexOf("MiniloadServer") >= 0) { opcServer.Groups.DefaultGroup.OnDataChanged += new OPCGroup.DataChangedEventHandler(Miniload_OnDataChanged); } if (Servers[i].Name.IndexOf("CraneServer") >= 0) { opcServer.Groups.DefaultGroup.OnDataChanged += new OPCGroup.DataChangedEventHandler(Crane_OnDataChanged); } } } catch (Exception ex) { Logger.Error(ex.Message); } }
private bool PLCConnection() //非通用 { //初始化PLCSystem类 plcSystemMS = new PlcSystemMS(this); //只有一个主站 if (!plcSystemMS.RefreshStatus()) { return(false); } if (!cmdDeviceOpcServer.Connect()) { return(false); } if (!cmdDeviceOpcServer.AddGroup()) { return(false); } return(true); }
private void frmMonitorB_Load(object sender, EventArgs e) { Cranes.OnCrane += new CraneEventHandler(Monitor_OnCrane); InitialP5 = btnSRM5.Location; InitialP6 = btnSRM6.Location; InitialP7 = btnSRM7.Location; AddDicKeyValue(); try { ServerInfo[] Servers = new MonitorConfig("MonitorB.xml").Servers; for (int i = 0; i < Servers.Length; i++) { OPCServer opcServer = new OPCServer(Servers[i].Name); opcServer.Connect(Servers[i].ProgID, Servers[i].ServerName);// opcServer.Connect(config.ConnectionString); OPCGroup group = opcServer.AddGroup(Servers[i].GroupName, Servers[i].UpdateRate); foreach (ItemInfo item in Servers[i].Items) { group.AddItem(item.ItemName, item.OpcItemName, item.ClientHandler, item.IsActive); } if (Servers[i].Name.IndexOf("PLC") >= 0) { opcServer.Groups.DefaultGroup.OnDataChanged += new OPCGroup.DataChangedEventHandler(Crane_OnDataChanged); } } } catch (Exception ex) { Logger.Error(ex.Message); } tmWorkTimer.Interval = 30000; tmWorkTimer.Elapsed += new System.Timers.ElapsedEventHandler(tmWorker); tmWorkTimer.Start(); }
public override bool BindToPLC() { //同步OPC opcServer = new OPCServer(); if (!opcServer.Connect()) { return(false); } if (!opcServer.AddGroup()) { return(false); } int client = 1; if (controlDB != null) { OpcRcw.Da.OPCITEMDEF[] controlitem = new OPCITEMDEF[controlDB.Length]; for (int i = 0; i < controlDB.Length; i++) { controlitem[i].szAccessPath = ""; controlitem[i].bActive = 1; controlitem[i].hClient = client; controlitem[i].dwBlobSize = 1; controlitem[i].pBlob = IntPtr.Zero; controlitem[i].vtRequestedDataType = (int)VarEnum.VT_BSTR; controlitem[i].szItemID = string.Format("S7:[S7 connection_1]{0}", controlDB[i]); //状态DB client++; } if (!opcServer.AddItems(controlitem, controlHandle)) { return(false); } } //if (failureDB != null) //{ // OpcRcw.Da.OPCITEMDEF[] failureitem = new OPCITEMDEF[failureDB.Length]; // for (int i = 0; i < failureDB.Length; i++) // { // failureitem[i].szAccessPath = ""; // failureitem[i].bActive = 1; // failureitem[i].hClient = client; // failureitem[i].dwBlobSize = 1; // failureitem[i].pBlob = IntPtr.Zero; // failureitem[i].vtRequestedDataType = (int)VarEnum.VT_BSTR; // failureitem[i].szItemID = string.Format("S7:[S7 connection_1]{0}", failureDB[i]); //状态DB // client++; // } // if (!opcServer.AddItems(failureitem, failureHandle)) return false; //} //异步OPC if (!BindToPLCAsyn()) { return(false); } isBindToPLC = true; return(isBindToPLC); }
public Int64 lastRefreshTicks; //保存上次刷新的时间,当两次刷新时间间隔较小(小于100ms)时,不进行刷新。 public virtual bool BindToPLC() { opcServer = new OPCServer(); if (!opcServer.Connect()) { return(false); } if (!opcServer.AddGroup()) { return(false); } int client = 1; if (commandDB != null) { OpcRcw.Da.OPCITEMDEF[] commandItem = new OPCITEMDEF[commandDB.Length]; for (int i = 0; i < commandDB.Length; i++) { commandItem[i].szAccessPath = ""; commandItem[i].bActive = 1; commandItem[i].hClient = client; commandItem[i].dwBlobSize = 1; commandItem[i].pBlob = IntPtr.Zero; commandItem[i].vtRequestedDataType = (int)VarEnum.VT_BSTR; commandItem[i].szItemID = string.Format("S7:[S7 connection_1]{0}", commandDB[i]); //状态DB client++; } if (!opcServer.AddItems(commandItem, commandHandle)) { return(false); } } if (returnDB != null) { OpcRcw.Da.OPCITEMDEF[] returnitem = new OPCITEMDEF[returnDB.Length]; for (int i = 0; i < returnDB.Length; i++) { returnitem[i].szAccessPath = ""; returnitem[i].bActive = 1; returnitem[i].hClient = client; returnitem[i].dwBlobSize = 1; returnitem[i].pBlob = IntPtr.Zero; returnitem[i].vtRequestedDataType = (int)VarEnum.VT_BSTR; returnitem[i].szItemID = string.Format("S7:[S7 connection_1]{0}", returnDB[i]); //状态DB client++; } if (!opcServer.AddItems(returnitem, returnHandle)) { return(false); } } if (controlDB != null) { OpcRcw.Da.OPCITEMDEF[] controlitem = new OPCITEMDEF[controlDB.Length]; for (int i = 0; i < controlDB.Length; i++) { controlitem[i].szAccessPath = ""; controlitem[i].bActive = 1; controlitem[i].hClient = client; controlitem[i].dwBlobSize = 1; controlitem[i].pBlob = IntPtr.Zero; controlitem[i].vtRequestedDataType = (int)VarEnum.VT_BSTR; controlitem[i].szItemID = string.Format("S7:[S7 connection_1]{0}", controlDB[i]); //状态DB client++; } if (!opcServer.AddItems(controlitem, controlHandle)) { return(false); } } if (statusDB != null) { OpcRcw.Da.OPCITEMDEF[] statusitem = new OPCITEMDEF[statusDB.Length]; for (int i = 0; i < statusDB.Length; i++) { statusitem[i].szAccessPath = ""; statusitem[i].bActive = 1; statusitem[i].hClient = client; statusitem[i].dwBlobSize = 1; statusitem[i].pBlob = IntPtr.Zero; statusitem[i].vtRequestedDataType = (int)VarEnum.VT_BSTR; statusitem[i].szItemID = string.Format("S7:[S7 connection_1]{0}", statusDB[i]); //状态DB client++; } if (!opcServer.AddItems(statusitem, statusHandle)) { return(false); } } if (failureDB != null) { OpcRcw.Da.OPCITEMDEF[] failureitem = new OPCITEMDEF[failureDB.Length]; for (int i = 0; i < failureDB.Length; i++) { failureitem[i].szAccessPath = ""; failureitem[i].bActive = 1; failureitem[i].hClient = client; failureitem[i].dwBlobSize = 1; failureitem[i].pBlob = IntPtr.Zero; failureitem[i].vtRequestedDataType = (int)VarEnum.VT_BSTR; failureitem[i].szItemID = string.Format("S7:[S7 connection_1]{0}", failureDB[i]); //状态DB client++; } if (!opcServer.AddItems(failureitem, failureHandle)) { return(false); } } isBindToPLC = true; return(isBindToPLC); }