コード例 #1
0
        /// <summary>
        /// 轴回原点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGoHome_Click(object sender, EventArgs e)
        {
            //气缸上
            var fRtn = MoveExecute.SetBaffle(true);

            if (!fRtn)
            {
                return;
            }

            var tasks = new List <Task>();

            foreach (var axisInfo in this.listAxisInfo)
            {
                tasks.Add(Task.Factory.StartNew(() =>
                {
                    MoveExecute.HomeMove(axisInfo, true);
                }));
            }

            Task.WaitAll(tasks.ToArray());

            if (this.listAxisInfo.Count == 1)
            {
                MoveExecute.HomeMove(this.listAxisInfo[0], true);
            }

            //获取当前位置
            this.GetCurrentPosition(this.listAxisInfo[0]);
        }
コード例 #2
0
        /// <summary>
        /// 定长运动
        /// </summary>
        /// <param name="axisinfo">轴实体</param>
        /// <param name="moveType">运动方向</param>
        public void Pmove(AxisInfo axisInfo, string moveType)
        {
            //气缸上
            var fRtn = MoveExecute.SetBaffle(true);

            if (!fRtn)
            {
                return;
            }

            switch (moveType)
            {
            case "正":
            {
                //设置移动距离
                axisInfo.Dist = Convert.ToInt32(Convert.ToInt32(txtDistance.Text) * axisInfo.Step / axisInfo.Lead);

                if (Global.ControlCard.GetPosition(axisInfo, true) + axisInfo.Dist > axisInfo.Step)
                {
                    Log.GetInstance().WarningWrite(string.Format("[{0}]轴移动距离超出了物理正极限,自动移动到极限位置"));

                    this.txtDistance.Text = (axisInfo.Lead / (axisInfo.Step / (axisInfo.Step - Global.ControlCard.GetPosition(axisInfo, true)))).ToString("f0");

                    axisInfo.Dist = Convert.ToInt32(Convert.ToInt32(txtDistance.Text) * axisInfo.Step / axisInfo.Lead);
                }

                break;
            }

            case "负":
            {
                //设置移动距离
                axisInfo.Dist = Convert.ToInt32(Convert.ToInt32(txtDistance.Text) * axisInfo.Step / axisInfo.Lead * -1);

                if (Global.ControlCard.GetPosition(axisInfo, true) - axisInfo.Dist < 0)
                {
                    Log.GetInstance().WarningWrite(string.Format("[{0}]轴移动距离超出了物理负极限,自动移动到极限位置"));

                    txtDistance.Text = (axisInfo.Lead / (axisInfo.Step / Global.ControlCard.GetPosition(axisInfo, true))).ToString("f0");

                    axisInfo.Dist = Convert.ToInt32(Convert.ToInt32(txtDistance.Text) * axisInfo.Step / axisInfo.Lead * -1);
                }

                break;
            }

            default:
            {
                return;
            }
            }

            axisInfo.PosiMode = 0;
            MoveExecute.Pmove(axisInfo, true);

            //获取当前位置
            this.txtCurrentPosition.Text = (axisInfo.Lead / (axisInfo.Step / Global.ControlCard.GetPosition(axisInfo, true))).ToString("f0");
        }
コード例 #3
0
        private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            this.timerReset.Stop();
            var f = MoveExecute.AllAxisReset();

            AxisInfo axisInfo = Global.ListAxis.Where(info => info.AxisName == "转盘").FirstOrDefault();

            if (axisInfo != null)
            {
                this.currentWorkPos = axisInfo.WorkPos1;
            }
        }
コード例 #4
0
        /// <summary>
        /// 设置气缸位置
        /// </summary>
        /// <param name="isUp"></param>
        public static bool SetBaffle(bool isUp)
        {
            try
            {
                var tasks = new List <Task>();

                bool fLeft  = false;
                bool fRight = false;

                //气缸上去
                tasks.Add(Task.Factory.StartNew(() =>
                {
                    fLeft = MoveExecute.SetBaffle(SvrType.Left, isUp);
                }));

                tasks.Add(Task.Factory.StartNew(() =>
                {
                    fRight = MoveExecute.SetBaffle(SvrType.Right, isUp);
                }));

                Task.WaitAll(tasks.ToArray());

                if (!fLeft || !fRight)
                {
                    Log.GetInstance().ErrorWrite(string.Format("气缸{0}失败", isUp == true ? "上移" : "下移"));
                    return(false);
                }
                else
                {
                    Log.GetInstance().NormalWrite(string.Format("气缸{0}成功", isUp == true ? "上移" : "下移"));
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Log.WriterExceptionLog(ex.ToString());
                return(false);
            }
        }
コード例 #5
0
        /// <summary>
        /// 所有轴复位
        /// </summary>
        public static bool AllAxisReset()
        {
            bool f = false;

            try
            {
                Log.GetInstance().NormalWrite("轴正在开始复位......");

                var fRtn = MoveExecute.SetBaffle(true);

                //气缸移动不到位不处理
                if (!fRtn)
                {
                    f = false;
                    return(false);
                }

                var tasks = new List <Task>();

                foreach (var axisInfo in Global.ListAxis)
                {
                    tasks.Add(Task.Factory.StartNew(() =>
                    {
                        //轴回原点
                        fRtn = MoveExecute.HomeMove(axisInfo, false);

                        if (!fRtn)
                        {
                            f = false;
                        }

                        axisInfo.Dist     = Convert.ToInt32(axisInfo.WorkPos1 * axisInfo.Step / axisInfo.Lead);
                        axisInfo.PosiMode = 1;

                        //轴到工作1位置
                        fRtn = MoveExecute.Pmove(axisInfo, false);

                        if (!fRtn || Global.ControlCard.GetPosition(axisInfo, false) != axisInfo.Dist)
                        {
                            f = false;
                        }
                    }));
                }

                Task.WaitAll(tasks.ToArray());

                if (f)
                {
                    Global.isReset = false;
                    //亮黄灯
                    Global.ControlCard.WriteOutbit((ushort)Global.GetIOPortNoByName("红灯"), 1);

                    MoveExecute.NoticePgShooting(Global.WorkPos);

                    return(f);
                }
                else
                {
                    //报警提示
                    Global.ControlCard.WriteOutbit(28, 1);
                    //亮红灯
                    Global.ControlCard.WriteOutbit((ushort)Global.GetIOPortNoByName("红灯"), 1);

                    return(f);
                }
            }
            catch (Exception ex)
            {
                Log.WriterExceptionLog(ex.ToString());
                return(false);
            }
            finally
            {
                if (f)
                {
                    Log.GetInstance().NormalWrite("轴复位成功,可以开始Demura检测");
                }
                else
                {
                    Log.GetInstance().ErrorWrite("轴复位失败,请重启设备");
                }
                Log.GetInstance().NormalWrite("轴复位结束");
            }
        }
コード例 #6
0
        /// <summary>
        /// VCR扫码
        /// </summary>
        /// <param name="iixServer"></param>
        /// <returns></returns>
        public static bool SweepCode(IIXServer iixServer, ref string code)
        {
            try
            {
                var tasks = new List <Task>();
                var fX    = false;
                var fY    = false;

                tasks.Add(Task.Factory.StartNew(() =>
                {
                    var axisInfoX      = Global.ListAxis.Where(info => info.AxisName == "VCR-X").FirstOrDefault();
                    axisInfoX.PosiMode = 1;

                    if (iixServer.AssociatedPanelPos == "#1")
                    {
                        axisInfoX.Dist = (int)axisInfoX.WorkPos1;
                    }
                    else if (iixServer.AssociatedPanelPos == "#2")
                    {
                        axisInfoX.Dist = (int)axisInfoX.WorkPos2;
                    }
                    else if (iixServer.AssociatedPanelPos == "#3")
                    {
                        axisInfoX.Dist = (int)axisInfoX.WorkPos3;
                    }

                    fX = MoveExecute.Pmove(axisInfoX, false);
                }));

                tasks.Add(Task.Factory.StartNew(() =>
                {
                    var axisInfoZ = Global.ListAxis.Where(info => info.AxisName == "VCR-Z").FirstOrDefault();

                    axisInfoZ.PosiMode = 1;

                    if (iixServer.AssociatedPanelPos == "#1")
                    {
                        axisInfoZ.Dist = (int)axisInfoZ.WorkPos1;
                    }
                    else if (iixServer.AssociatedPanelPos == "#2")
                    {
                        axisInfoZ.Dist = (int)axisInfoZ.WorkPos2;
                    }
                    else if (iixServer.AssociatedPanelPos == "#3")
                    {
                        axisInfoZ.Dist = (int)axisInfoZ.WorkPos3;
                    }

                    fY = MoveExecute.Pmove(axisInfoZ, false);
                }));

                Task.WaitAll(tasks.ToArray());

                if (!fX || !fY)
                {
                    Log.GetInstance().ErrorWrite("VCR移动到指定位置失败");
                    return(false);
                }

                //发送扫码指令
                Global.SocketServer.Send("Trigger");
                //休眠500毫秒,等待扫码完成
                Thread.Sleep(500);

                //获取二维码编号
                code = Global.SocketServer.Code;

                Log.GetInstance().NormalWrite(string.Format(""));

                //清空二维码
                Global.SocketServer.Code = "";

                //判断二维码的结果

                var codeResult = MoveExecute.Result.Successful;

                //查询当前屏幕是否在集合中存在
                OLEDPanel panel = Global.ListOLEDPanel.Where(info => info.PanelPos == iixServer.AssociatedPanelPos).FirstOrDefault();

                //存在则删除
                if (panel != null)
                {
                    //操作检测屏幕集合时加锁,防止线程启动过快导致集合修改的异常
                    lock (Global.ListOLEDPanel)
                    {
                        Global.ListOLEDPanel.Remove(panel);
                    }
                }

                lock (Global.ListOLEDPanel)
                {
                    panel              = new OLEDPanel();
                    panel.PanelNumber  = code;
                    panel.PanelPos     = iixServer.AssociatedPanelPos;
                    panel.DmrSvrApi    = iixServer.DmrSvrApi;
                    panel.PanelWorkPos = "工位#1";
                    panel.CmdResWork   = codeResult == MoveExecute.Result.Successful ? CmdResultCode.Success : CmdResultCode.Other;
                    panel.bRotated     = false;
                    panel.IsPanelOn    = false;

                    //将屏添加到集合中
                    Global.ListOLEDPanel.Add(panel);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.WriterExceptionLog(ex.ToString());

                return(false);
            }
        }
コード例 #7
0
        /// <summary>
        /// 加载当前项目信息
        /// </summary>
        private bool LoadProduct()
        {
            try
            {
                if (MoveExecute.LoadSettings(Global.ProductName))
                {
                    Log.GetInstance().NormalWrite("加载项目配置文件配置成功。");
                }
                else
                {
                    Log.GetInstance().ErrorWrite("加载项目配置文件配置失败。");

                    return(false);
                }

                var currentProductPath = Path.Combine(Application.StartupPath + "\\Product", Global.ProductName);
                var fileName           = Global.IsExistFileBySuffixName(currentProductPath, ".bin");

                if (fileName == "")
                {
                    Log.GetInstance().ErrorWrite(string.Format("目录 '{0}' 下没有找到该项目的bin文件,切换项目失败。", currentProductPath));
                    return(false);
                }

                ///
                ///设置Recipe
                ///
                var           tasks = new List <Task>();
                CmdResultCode cmdRes;
                bool          f = false;

                foreach (var iixServer in Global.ListIIXSerevr)
                {
                    if (iixServer.IsEnable == false)
                    {
                        continue;
                    }

                    tasks.Add(Task.Factory.StartNew(() =>
                    {
                        cmdRes = IIXExecute.SetRecipe(iixServer, Path.Combine(currentProductPath, fileName));

                        if (cmdRes != CmdResultCode.Success)
                        {
                            f = false;
                        }
                    }));
                }

                Task.WaitAll(tasks.ToArray());

                if (!f)
                {
                    Log.GetInstance().ErrorWrite(string.Format("设置Recipe失败,请重启软件。"));
                    return(false);
                }

                //修改配置文件中当前项目名
                IniFile.IniWriteValue("Product", "ProductName", Global.ProductName, Global.ConfigPath);

                //修改主界面项目名

                return(true);
            }
            catch (Exception ex)
            {
                Log.GetInstance().ErrorWrite("系统错误,请查询日志文件检查。");
                Log.WriterExceptionLog(ex.ToString());
                return(false);
            }
        }
コード例 #8
0
        /// <summary>
        /// 移动到指定工作位置
        /// </summary>
        /// <param name="axisInfo"></param>
        /// <param name="workNumber"></param>
        public void MoveWorkPos(List <AxisInfo> listAxisInfo, int workNumber)
        {
            //气缸上
            var fRtn = MoveExecute.SetBaffle(true);

            if (!fRtn)
            {
                return;
            }

            double workPos = 0;

            foreach (var axisInfo in listAxisInfo)
            {
                switch (workNumber)
                {
                case 1:
                {
                    workPos = axisInfo.WorkPos1;
                    break;
                }

                case 2:
                {
                    workPos = axisInfo.WorkPos2;
                    break;
                }

                case 3:
                {
                    workPos = axisInfo.WorkPos3;
                    break;
                }

                case 4:
                {
                    workPos = axisInfo.WorkPos4;
                    break;
                }

                default:
                {
                    return;
                }
                }

                if (axisInfo.AxisName == "转盘")
                {
                    //如果移动后的位置大于最大位置,则轴的当前位置设置为0
                    if (currentWorkPos + workPos > axisInfo.Lead)
                    {
                        axisInfo.CurrentPosition = 0;
                        Global.ControlCard.SetPosition(axisInfo, false);
                    }
                }

                axisInfo.Dist     = Convert.ToInt32(workPos * axisInfo.Step / axisInfo.Lead);
                axisInfo.PosiMode = 1;

                MoveExecute.Pmove(axisInfo, true);

                this.userMove1.GetCurrentPosition(axisInfo);

                if (axisInfo.AxisName == "转盘")
                {
                    this.currentWorkPos = Global.ControlCard.GetPosition(axisInfo, true);
                }
            }
        }
コード例 #9
0
        private void btnCloseIo_Click(object sender, EventArgs e)
        {
            if (this.cbbIO.SelectedItem.ToString() == "真空")
            {
                var tasks = new List <Task>();

                foreach (var _iixServer in Global.ListIIXSerevr)
                {
                    if (_iixServer.IsEnable == false)
                    {
                        continue;
                    }

                    if (_iixServer.SvrType == SvrType.Right)
                    {
                        tasks.Add(Task.Factory.StartNew(() =>
                        {
                            MoveExecute.SetVacuum(_iixServer, false);
                        }));
                    }
                }
            }
            else if (this.cbbIO.SelectedItem.ToString() == "治具防呆")
            {
                var tasks = new List <Task>();

                foreach (var _iixServer in Global.ListIIXSerevr)
                {
                    if (_iixServer.IsEnable == false)
                    {
                        continue;
                    }

                    if (_iixServer.SvrType == SvrType.Right)
                    {
                        tasks.Add(Task.Factory.StartNew(() =>
                        {
                            MoveExecute.SetPanelLock(_iixServer, false);
                        }));
                    }
                }
            }
            else if (this.cbbIO.SelectedItem.ToString() == "暗室气缸")
            {
                MoveExecute.SetBaffle(false);
            }
            else if (this.cbbIO.SelectedItem.ToString() == "轴使能")
            {
                MoveExecute.SetAxisLock(false);
            }
            else if (this.cbbIO.SelectedItem.ToString() == "报警")
            {
                Global.ControlCard.WriteOutbit((ushort)Global.GetIOPortNoByName("报警"), 0);
            }
            else if (this.cbbIO.SelectedItem.ToString() == "黄灯")
            {
                Global.ControlCard.WriteOutbit((ushort)Global.GetIOPortNoByName("黄灯"), 0);
            }
            else if (this.cbbIO.SelectedItem.ToString() == "红灯")
            {
                Global.ControlCard.WriteOutbit((ushort)Global.GetIOPortNoByName("红灯"), 0);
            }
            else if (this.cbbIO.SelectedItem.ToString() == "绿灯")
            {
                Global.ControlCard.WriteOutbit((ushort)Global.GetIOPortNoByName("绿灯"), 0);
            }
            else if (this.cbbIO.SelectedItem.ToString() == "启动按钮1灯")
            {
                Global.ControlCard.WriteOutbit((ushort)Global.GetIOPortNoByName("启动按钮1灯"), 0);
            }
            else if (this.cbbIO.SelectedItem.ToString() == "启动按钮2灯")
            {
                Global.ControlCard.WriteOutbit((ushort)Global.GetIOPortNoByName("启动按钮2灯"), 0);
            }
            else if (this.cbbIO.SelectedItem.ToString() == "按钮1灯")
            {
                Global.ControlCard.WriteOutbit((ushort)Global.GetIOPortNoByName("按钮1灯"), 0);
            }
            else if (this.cbbIO.SelectedItem.ToString() == "按钮2灯")
            {
                Global.ControlCard.WriteOutbit((ushort)Global.GetIOPortNoByName("按钮2灯"), 0);
            }
            else if (this.cbbIO.SelectedItem.ToString() == "按钮3灯")
            {
                Global.ControlCard.WriteOutbit((ushort)Global.GetIOPortNoByName("按钮3灯"), 0);
            }
        }