Exemplo n.º 1
0
 public void Disconnect()
 {
     if (pIOPCServer != null)
     {
         Marshal.ReleaseComObject(pIOPCServer);
         pIOPCServer = null;
     }
     if (OnlyTaskGorup1 != null)
     {
         OnlyTaskGorup1.Release();
     }
     if (OnlyTaskGorup2 != null)
     {
         OnlyTaskGorup2.Release();
     }
     if (FinishOnlyGoroup1 != null)
     {
         FinishOnlyGoroup1.Release();
     }
     if (FinishOnlyGoroup2 != null)
     {
         FinishOnlyGoroup2.Release();
     }
     if (SpyBiaozhiGroup != null)
     {
         SpyBiaozhiGroup.Release();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 检验opc连接
        /// </summary>
        /// <returns></returns>
        public bool CheckConnection()
        {
            //包装机异型烟链板机(合包)plc连接状态
            int flag1 = SpyBiaozhiGroup.ReadD(0).CastTo <int>(-1);//读取标志

            if (flag1 == -1)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 3
0
 private void timerSendTask_Tick(object sender, EventArgs e)
 {
     updateListBox("触发定时器");
     if (SpyBiaozhiGroup.Read(0).ToString() != "1" && !issendone)//监控标志位第一组 产生跳变
     {
         SpyBiaozhiGroup.Write(2, 0);
         SpyBiaozhiGroup.Write(0, 0);
     }
     //if (SpyBiaozhiGroup.Read(1).ToString() != "1" && !issendone)//监控标志位第二组 产生跳变
     //{
     //    SpyBiaozhiGroup.Write(2, 1);
     //    SpyBiaozhiGroup.Write(0, 1);
     //}
     timerSendTask.Stop();
 }
Exemplo n.º 4
0
        private void button12_Click(object sender, EventArgs e)
        {
            DialogResult MsgBoxResult = MessageBox.Show("确定要退出程序?",                       //对话框的显示内容
                                                        "操作提示",                           //对话框的标题
                                                        MessageBoxButtons.YesNo,          //定义对话框的按钮,这里定义了YSE和NO两个按钮
                                                        MessageBoxIcon.Question,          //定义对话框内的图表式样,这里是一个黄色三角型内加一个感叹号
                                                        MessageBoxDefaultButton.Button2); //定义对话框的按钮式样


            if (MsgBoxResult == DialogResult.Yes)
            {
                if (pIOPCServer != null)
                {
                    Marshal.ReleaseComObject(pIOPCServer);
                    pIOPCServer = null;
                }
                if (OnlyTaskGorup != null)
                {
                    OnlyTaskGorup.Release();
                }
                if (FinishOnlyGoroup != null)
                {
                    FinishOnlyGoroup.Release();
                }
                if (SpyBiaozhiGroup != null)
                {
                    SpyBiaozhiGroup.Release();
                }
                if (SpecialSmokeGroup1 != null)
                {
                    SpecialSmokeGroup1.Release();
                }
                if (SpecialSmokeGroup2 != null)
                {
                    SpecialSmokeGroup2.Release();
                }
                list_data.Items.Clear();
                updateListBox("任务停止发送!");
                writeLog.Write("任务停止发送!");
                updateControlEnable(true, button10);
            }
            else
            {
                return;
            }
            //  updateControlEnable(true, button10);
        }
Exemplo n.º 5
0
        public void checkConnection()
        {
            int flag = SpyBiaozhiGroup.ReadD(0).CastTo <int>(-1);

            if (flag != -1)
            {
                updateListBox("连接服务器成功......");
                writeLog.Write(" 连接服务器成功......");
                updateControlEnable(false, button10);
                strat  = true;
                isInit = true;
                AutoFinishTask();
            }
            else
            {
                updateListBox("连接服务器失败,请检查网络.");
                writeLog.Write(" 连接服务器失败,请检查网络.");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///特异形烟1线
        /// </summary>
        void sendSSTask1()
        {
            try
            {
                issendone = true;
                int flag = SpyBiaozhiGroup.ReadD(1).CastTo <int>(-1);//发送数据前读标志位
                writeLog.Write("1线特异形烟发送数据前读标志位:" + flag);
                if (flag == 0)
                {
                    string   OutStr = "";
                    object[] datas  = UnPokeService.GetSpecialSmokeData(10, "1", out listSS1B, out OutStr);//获取可发送任务
                    if (int.Parse(datas[0].ToString()) == 0)
                    {
                        updateListBox("1线特异形烟分拣数据发送完毕");

                        return;
                    }
                    writeLog.Write("1线特异形烟分拣线:" + OutStr);
                    updateListBox("1线特异形烟分拣线:" + OutStr);
                    SpecialSmokeGroup1.SyncWrite(datas);
                }
                else
                {
                    writeLog.Write("1线特异形烟标志位读取到异常:" + flag);
                    updateListBox("1线特异形烟标志位读取到异常:" + flag);
                }
            }
            catch (Exception ex)
            {
                writeLog.Write(ex.Message);
                updateListBox(ex.Message);
                Thread.Sleep(10000);
                if (ex.InnerException != null && ex.InnerException.Message != null)
                {
                    writeLog.Write(ex.InnerException.Message);
                    updateListBox(ex.InnerException.Message);
                }
                sendSSTask1();//异常后重新发送
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 写入异型烟链板机(合包)任务发送区DB块的内容
        /// </summary>
        /// <returns></returns>
        public StringBuilder SendOnlyTask(object[] datas, StringBuilder OutStr)
        {
            StringBuilder sb = new StringBuilder();

            IsSendOn = true;
            int flag = SpyBiaozhiGroup.ReadD(0).CastTo <int>(-1);

            WriteLog.GetLog().Write("烟仓烟柜发送数据前读标志位:" + flag + flag);
            if (flag == 0)
            {
                if (int.Parse(datas[0].ToString()) == 0)
                {
                    sb.AppendLine("烟仓烟柜分拣数据发送完毕");
                    return(sb);
                }
                //WriteLog.GetLog().Write("烟仓烟柜分拣线:" + OutStr);
                sb.AppendLine("烟仓烟柜分拣线:" + OutStr);
                OnlyTaskGroup.SyncWrite(datas);
            }
            IsSendOn = false;
            return(sb);
        }
Exemplo n.º 8
0
        public void checkConnection()
        {
            int flag = SpyBiaozhiGroup.ReadD(0).CastTo <int>(-1);

            if (flag == -1)
            {
                updateListBox("连接服务器失败,请检查网络.");
                writeLog.Write(" 连接服务器失败,请检查网络.");
            }
            else
            {
                updateListBox("连接服务器成功......");
                writeLog.Write(" 连接服务器成功......");
                SpyBiaozhiGroup.Write(2, 0);
                SpyBiaozhiGroup.Write(0, 0);
                SpyBiaozhiGroup.Write(2, 1);
                SpyBiaozhiGroup.Write(0, 1);
                SpyBiaozhiGroup.Write(2, 2);
                SpyBiaozhiGroup.Write(0, 2);
                updateControlEnable(false, button10);
                isInit = true;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 一组交互
        /// </summary>
        void sendOnlyTask()
        {
            try
            {
                issendone = true;
                int flag = SpyBiaozhiGroup.ReadD(0).CastTo <int>(-1);
                writeLog.Write("烟仓烟柜发送数据前读标志位:" + flag);
                if (flag == 0)
                {
                    #region
                    //int pcgm = 4;
                    //while (!UnPokeService.CheckExistPreSendTask("1", 1, 12) && UnPokeService.CheckExistCanSendPackeMachine("1", 1))
                    //{
                    //    decimal sortnum, xyqty;
                    //    for (int i = 1; i <= 8; i++)
                    //    {

                    //        try
                    //        {
                    //            sortnum = 0;
                    //            xyqty = 0;
                    //        }
                    //        catch
                    //        {
                    //            sortnum = 0;
                    //            xyqty = 0;
                    //        }
                    //        if (!UnPokeService.CheckExistTaskNo(sortnum))
                    //        {
                    //            xyqty = 0;
                    //        }
                    //        sortNumList.Add(sortnum);
                    //        zqNumList.Add(xyqty);
                    //    }
                    //        decimal DISPATCHESIZE = 0;
                    //        pcgm = UnPokeService.GetSendPackageMachineYC(1, sortNumList, zqNumList, out DISPATCHESIZE);//获取包装机
                    //        if (packagemachine > 0)
                    //        {
                    //            UnPokeService.UpdateSendtasknumByPM(pcgm, (int)DISPATCHESIZE);//计算可发送任务
                    //        }
                    //        if (pcgm - 1 > 0)
                    //        {
                    //            pcgm -= 1;
                    //        }
                    //        else
                    //        {
                    //            pcgm = 4;
                    //        }
                    //        Thread.Sleep(100);

                    //}
                    #endregion
                    string   OutStr = "";
                    object[] datas  = UnPokeService.getAllLineTask(10, out listOnly, out OutStr);//获取可发送任务
                    if (int.Parse(datas[0].ToString()) == 0)
                    {
                        updateListBox("烟仓烟柜分拣数据发送完毕");
                        return;
                    }
                    writeLog.Write("烟仓烟柜分拣线:" + OutStr);
                    updateListBox("烟仓烟柜分拣线:" + OutStr);
                    OnlyTaskGorup.SyncWrite(datas);
                }
            }
            catch (Exception ex)
            {
                writeLog.Write(ex.Message);
                updateListBox(ex.Message);
                Thread.Sleep(10000);
                if (ex.InnerException != null && ex.InnerException.Message != null)
                {
                    writeLog.Write(ex.InnerException.Message);
                    updateListBox(ex.InnerException.Message);
                }
                sendOnlyTask();//异常后重新发送
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// 任务交互
 /// </summary>
 void sendOnlyTask1()
 {
     try
     {
         issendone = true;
         List <decimal> sortNumList = new List <decimal>(); //当前任务号集合
         List <decimal> xyNumList   = new List <decimal>(); //当前吸烟数量集合
         int            flag        = SpyBiaozhiGroup.ReadD(0).CastTo <int>(-1);
         writeLog.Write(ListLineNum[0] + "线烟仓发送数据前读标志位:" + flag);
         if (flag == 0)
         {
             while (!UnPokeService.CheckExistCanSendTask(12, ListLineNum[0]) && UnPokeService.CheckExistCanSendTask(10, ListLineNum[0]))
             {
                 sortNumList.Clear();
                 xyNumList.Clear();
                 decimal sortNum, xyNum;
                 decimal packagemachine = 0;
                 if (SendWay == 2)
                 {
                     for (int i = ListPackge[0]; i <= ListPackge[1]; i++)
                     {
                         try
                         {
                             if (UnPokeService.checkExist(i, ListLineNum[0]))
                             {
                                 sortNum = listPM[i - 1].ReadD(2).CastTo <decimal>(-1); //包装机读取出来的任务号
                                 xyNum   = listPM[i - 1].ReadD(3).CastTo <decimal>(-1); //包装机读取出来的数量
                             }
                             else
                             {
                                 sortNum = 0;
                                 xyNum   = 0;
                             }
                         }
                         catch
                         {
                             sortNum = 0; //读取出错的情况下 默认为0
                             xyNum   = 0;
                         }
                         writeLog.Write(ListLineNum[0] + "线plc地址:S7:[PackageMachine" + i + "]DB1,D506" + " ,包装机:" + i + "号, 包装机读取任务号:" + sortNum + " ,包装机读取抓取数量:" + xyNum);
                         updateListBox(ListLineNum[0] + "线plc地址:S7:[PackageMachine" + i + "]DB1,D506" + " ,包装机:" + i + " 号,包装机读取任务号:" + sortNum + ", 包装机读取抓取数量:" + xyNum);
                         sortNumList.Add(sortNum);
                         xyNumList.Add(xyNum);
                     }
                 }
                 else
                 {
                     for (int i = 0; i < 2; i++)
                     {
                         sortNumList.Add(0);
                         xyNumList.Add(0);
                     }
                 }
                 // decimal DISPATCHESIZE = 0;
                 packagemachine = UnPokeService.GetSendPackageMachine_New(sortNumList, xyNumList, SendWay, ListLineNum[0]);
                 if (packagemachine > 0)
                 {
                     UnPokeService.UpdateTaskByPackMachine(packagemachine);
                 }
                 Thread.Sleep(100);
             }
             string   OutStr = "";
             object[] datas  = UnPokeService.getOneDateBaseTask(12, ListLineNum[0], out OutStr);//获取可发送任务
             if (int.Parse(datas[0].ToString()) == 0)
             {
                 updateListBox(ListLineNum[0] + "线烟仓烟柜分拣数据发送完毕");
                 return;
             }
             writeLog.Write(ListLineNum[0] + "线烟仓烟柜分拣线:" + OutStr);
             updateListBox(ListLineNum[0] + "线烟仓烟柜分拣线:" + OutStr);
             OnlyTaskGorup1.SyncWrite(datas);
         }
     }
     catch (Exception ex)
     {
         writeLog.Write(ex.Message);
         updateListBox(ex.Message);
         Thread.Sleep(10000);
         if (ex.InnerException != null && ex.InnerException.Message != null)
         {
             writeLog.Write(ex.InnerException.Message);
             updateListBox(ex.InnerException.Message);
         }
         sendOnlyTask1();//异常后重新发送
     }
     issendone = false;
 }