Exemple #1
0
        private void BGWConn_DoWork(object sender, DoWorkEventArgs e)
        {
            //GetData(true);
            opcServer = new OPCServer();
            WriteLog.GetLog().Write("正在尝试连接服务器......");

            string[] str = opcServer.Connection();
            if (string.IsNullOrWhiteSpace(str[0]))
            {
                opcServer.OnlyTaskGroup.addItem(PlcItemCollection.GetOnlyUnnormalItem());     //任务交互区
                opcServer.SpyBiaozhiGroup.addItem(PlcItemCollection.GetSpanUnnormalItem());   //监控任务标识位
                opcServer.FinishOnlyGroup.addItem(PlcItemCollection.GetFinishUnnormalItem()); //完成信号交互区;

                WriteLog.GetLog().Write("opC服务器创成功!");
                opcServer.ConnectState = opcServer.CheckConnection();
                if (opcServer.ConnectState)
                {
                    GetData();
                    opcServer.SpyBiaozhiGroup.callback = OnDataChange;
                    opcServer.FinishOnlyGroup.callback = OnDataChange;
                    WriteLog.GetLog().Write("PLC连接成功!");
                    WriteLog.GetLog().Write("触发定时器");
                    if (opcServer.SpyBiaozhiGroup.Read(0).ToString() != "1" && !opcServer.IsSendOn)//监控标志位第一组 产生跳变
                    {
                        opcServer.IsSendOn = true;
                        opcServer.SpyBiaozhiGroup.Write(2, 0);
                        opcServer.SpyBiaozhiGroup.Write(0, 0);
                        ReadFinish();
                        opcServer.IsSendOn = false;
                        WriteLog.GetLog().Write("发送任务");
                    }
                    else
                    {
                        WriteLog.GetLog().Write("强制跳变失败");
                    }
                }
                else
                {
                    WriteLog.GetLog().Write("PLC连接失败!");
                    databaselinkcheck("plc连接失败");
                    TSender.Stop();
                    TRefresh.Stop();
                }
            }
            else
            {
                TSender.Stop();
                TRefresh.Stop();
                databaselinkcheck("plc连接失败");
                WriteLog.GetLog().Write(str[0]);
            }
        }
Exemple #2
0
 public void databaselinkcheck(string str)
 {
     if (lblpack.InvokeRequired)
     {
         lblpack.Invoke(new HandleDelegate(databaselinkcheck), str);
     }
     else
     {
         lblpack.Text      = str;//;
         lblpack.Location  = new Point(0, 10);
         lblpack.Width     = 750;
         lblpack.BackColor = Color.Red;
         BtnSeq.Enabled    = false;
         //BtnSearch.Enabled = false;
         BtnRefresh.Enabled = false;
         TRefresh.Stop();
     }
 }