コード例 #1
0
        //机械手运行到指定脉冲
        private void btRunAuto_Click(object sender, RoutedEventArgs e)
        {
            ShowKey(false);
            //csKey.Close();
            Cursor = Cursors.Wait;
            PLC_Tcp_CP.ChangeAdd(1);
            string x = tbTargetX.Text.Trim();
            string z = tbTargetZ.Text.Trim();

            if (string.IsNullOrEmpty(x))
            {
                csMsg.ShowWarning("X轴脉冲不能为空", false);
                Cursor = null;
                return;
            }
            if (string.IsNullOrEmpty(z))
            {
                csMsg.ShowWarning("Z轴脉冲不能为空", false);
                Cursor = null;
                return;
            }
            float xp; float zp;

            if (float.TryParse(x, out xp) && float.TryParse(z, out zp))
            {
                PLC_Tcp_CP.ExtramanAutoMoveToPulse(xp, zp);
                DateTime timeBegin = DateTime.Now;
                Thread.Sleep(200);
                while (!PLC_Tcp_CP.ExtramanAutoMoveIsOK())
                {
                    if (DateTime.Now > timeBegin.AddSeconds(Config.Mac_C.WaitTime_Auto_Extraman))
                    {
                        break;
                    }
                    Thread.Sleep(200);
                }
                if (DateTime.Now <= timeBegin.AddSeconds(Config.Mac_C.WaitTime_Auto_Extraman))
                {
                    tbNowX.Text = PLC_Tcp_CP.ReadExtramanPulseX().ToString();
                    tbNowZ.Text = PLC_Tcp_CP.ReadExtramanPulseZ().ToString();
                }
                else
                {
                    csMsg.ShowWarning("机械手未运行到指定位置", false);
                }
            }
            else
            {
                csMsg.ShowWarning("脉冲值格式不正确", false);
            }

            Cursor = null;
        }
コード例 #2
0
        private void Back()
        {
            SetErrorVisibility(Visibility.Hidden);

            ShowPlate(PLC_Tcp_AP.PlateType.Left, "", 0);

            ShowPlate(PLC_Tcp_AP.PlateType.Right, "", 0);

            PLC_Tcp_CP.ChangeAdd(1);
            //运行到接药口
            PLC_Tcp_CP.ExtramanAutoMoveToPulse(float.Parse(Config.Mac_C.Pulse_Meet_X), float.Parse(Config.Mac_C.Pulse_Meet_Z));
            //推药板复位
            PLC_Tcp_CP.PlateAutoMoveToPulse(PLC_Tcp_AP.PlateType.Left, float.Parse(Config.Mac_C.Pulse_Plate_Min_Left));
            PLC_Tcp_CP.PlateAutoMoveToPulse(PLC_Tcp_AP.PlateType.Right, float.Parse(Config.Mac_C.Pulse_Plate_Min_Right));
        }
コード例 #3
0
        //加药
        private void Add()
        {
            bool stop = false;

            if (plate_Left.Num > 0)
            {
                //查询缺药储位
                string sql = "select poscode from drug_pos where drugnummax>drugnum and (substring(poscode,1,1)<" + Config.Mac_C.Count_Unit + " or substring(poscode,4,2)<={2}) and maccode='{0}' and drugonlycode='{1}' order by (drugnummax-drugnum) desc";
                sql = string.Format(sql, Config.Soft.MacCode, plate_Left.DrugOnlyCode, Config.Mac_C.MaxCol);

                DataTable dt = new DataTable();
                csSql.ExecuteSelect(sql, Config.Soft.ConnString, out dt);
                List <string> poss = new List <string>();
                foreach (DataRow row in dt.Rows)
                {
                    poss.Add(row["poscode"].ToString());
                }
                //获取左侧最短加药路径
                List <string> shortestPoss = poss;// GetShortestPath(poss, "A", "L");

                //int haveNum = plate_Left.Num;
                string drugOnlyCode = plate_Left.DrugOnlyCode;
                foreach (string pos in shortestPoss)
                {
                    if (plate_Left.Num > 0)
                    {
                        //先盘点
                        if (Config.Mac_C.PDBeforeAdd == "Y")
                        {
                            int n = PLC_Tcp_CP.PDNum(pos, false);
                            if (n >= 0)
                            {
                                sql = "update drug_pos set drugnum='{0}' where maccode='{1}' and poscode='{2}'";
                                sql = string.Format(sql, n, Config.Soft.MacCode, pos);
                                csSql.ExecuteSql(sql, Config.Soft.ConnString);
                            }
                        }
                        sql = "select (drugnummax-drugnum) from drug_pos where maccode='{0}' and poscode='{1}'";
                        sql = string.Format(sql, Config.Soft.MacCode, pos);
                        int shortNum = 0; string v;
                        csSql.ExecuteScalar(sql, Config.Soft.ConnString, out v);
                        if (!string.IsNullOrEmpty(v))
                        {
                            shortNum = int.Parse(v);
                        }
                        int addNum = 0;
                        if (shortNum > 0)
                        {
                            int n = int.Parse(v);
                            if (plate_Left.Num > n)
                            {
                                addNum = n;
                                //plate_Left.Num -= n;
                            }
                            else
                            {
                                addNum = plate_Left.Num;
                                //haveNum = 0;
                            }
                        }
                        int a = Add(pos, "L", addNum, plate_Left.Batch, plate_Left.QZ, ref stop);
                        plate_Left.Num -= a;
                        SetNumL(plate_Left.Num);

                        if (stop)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (!stop)
                {
                    //推药板复位
                    //PLC_Tcp.ChangeAdd(1);
                    PLC_Tcp_CP.PlateAutoMoveToPulse(PLC_Tcp_AP.PlateType.Left, float.Parse(Config.Mac_C.Pulse_Plate_Min_Left));
                }
                plate_Left.DrugOnlyCode = "";
                plate_Left.Num          = 0;
            }
            if (plate_Right.Num > 0 && !stop)
            {
                //查询缺药储位
                string sql = "select poscode from drug_pos where drugnummax>drugnum and (substring(poscode,1,1)>1 or substring(poscode,4,2)>={2}) and maccode='{0}' and drugonlycode='{1}' order by (drugnummax-drugnum) desc";
                sql = string.Format(sql, Config.Soft.MacCode, plate_Right.DrugOnlyCode, Config.Mac_C.MinCol);

                DataTable dt = new DataTable();
                csSql.ExecuteSelect(sql, Config.Soft.ConnString, out dt);
                List <string> poss = new List <string>();
                foreach (DataRow row in dt.Rows)
                {
                    poss.Add(row["poscode"].ToString());
                }
                //获取右侧最短加药路径
                List <string> shortestPoss = poss;// GetShortestPath(poss, "A", "R");

                //int haveNum = plate_Right.Num;
                string drugOnlyCode = plate_Right.DrugOnlyCode;
                foreach (string pos in shortestPoss)
                {
                    if (plate_Right.Num > 0)
                    {
                        //先盘点
                        if (Config.Mac_C.PDBeforeAdd == "1")
                        {
                            int n = PLC_Tcp_CP.PDNum(pos, false);
                            if (n >= 0)
                            {
                                sql = "update drug_pos set drugnum='{0}' where maccode='{1}' and poscode='{2}'";
                                sql = string.Format(sql, n, Config.Soft.MacCode, pos);
                                csSql.ExecuteSql(sql, Config.Soft.ConnString);
                            }
                        }
                        sql = "select (drugnummax-drugnum) from drug_pos where maccode='{0}' and poscode='{1}'";
                        sql = string.Format(sql, Config.Soft.MacCode, pos);
                        int shortNum = 0; string v;
                        csSql.ExecuteScalar(sql, Config.Soft.ConnString, out v);
                        if (!string.IsNullOrEmpty(v))
                        {
                            shortNum = int.Parse(v);
                        }
                        int addNum = 0;
                        if (shortNum > 0)
                        {
                            int n = int.Parse(v);
                            if (plate_Right.Num > n)
                            {
                                addNum = n;
                                //plate_Right.Num -= n;
                            }
                            else
                            {
                                addNum = plate_Right.Num;
                                //haveNum = 0;
                            }
                        }
                        int a = Add(pos, "R", addNum, plate_Right.Batch, plate_Right.QZ, ref stop);
                        //haveNum -= a;
                        plate_Right.Num -= a;
                        SetNumR(plate_Right.Num);

                        if (stop)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (!stop)
                {
                    //推药板复位
                    //PLC_Tcp.ChangeAdd(1);
                    PLC_Tcp_CP.PlateAutoMoveToPulse(PLC_Tcp_AP.PlateType.Right, float.Parse(Config.Mac_C.Pulse_Plate_Min_Right));
                }
                plate_Right.DrugOnlyCode = "";
                plate_Right.Num          = 0;
            }
            IsBusy = false;

            //ShowPlate(PLC.PlateType.Left, "", 0);
            //ShowPlate(PLC.PlateType.Right, "", 0);
            //ShowPos(tbCode.Text.Trim());

            if (!stop)
            {
                PLC_Tcp_CP.ExtramanAutoMoveToPulse(float.Parse(Config.Mac_C.Pulse_Meet_X), float.Parse(Config.Mac_C.Pulse_Meet_Z));
            }
        }
コード例 #4
0
        private void PDItem()
        {
            toPD = false;
            Pos[] ps    = lvPos.ItemsSource as Pos[];
            Pos   p     = null;
            int   index = 0;

            for (int i = 0; i < ps.Length; i++)
            {
                if (string.IsNullOrEmpty(ps[i].PDNum))
                {
                    p     = ps[i];
                    index = i;
                    break;
                }
            }
            if (p != null)
            {
                if (index > lvPos.Items.Count - 10)
                {
                    lvPos.ScrollIntoView(lvPos.Items[lvPos.Items.Count - 1]);
                }
                else
                {
                    lvPos.ScrollIntoView(lvPos.Items[index + 5]);
                }

                int n = PLC_Tcp_CP.PDNum(p.PosCode, false);
                if (n < 0)
                {
                    p.PDNum     = "-1";
                    p.BackColor = color_Error;
                }
                else
                {
                    p.PDNum = n.ToString();

                    int num = int.Parse(p.DrugNum);
                    if (n == num)
                    {
                        p.BackColor = color_Ok;
                    }
                    else
                    {
                        if (n > num)
                        {
                            p.BackColor = color_Ying;
                        }
                        else if (n < num)
                        {
                            p.BackColor = color_Kui;
                        }
                        string sql = "insert into sys_error values('{0}','{1}','{2}','PE',{3},{4},getdate())";
                        sql = string.Format(sql, Config.Soft.MacCode, p.PosCode, p.DrugOnlyCode, num, n);
                        csSql.ExecuteSql(sql, Config.Soft.ConnString);
                    }
                    string s = "update drug_pos set drugnum={2} where maccode='{0}' and poscode='{1}'";
                    s = string.Format(s, Config.Soft.MacCode, p.PosCode, p.PDNum);
                    csSql.ExecuteSql(s, Config.Soft.ConnString);
                    p.DrugNum = n.ToString();
                }

                lvPos.ItemsSource = ps.ToList().ToArray();

                toPD = true;
            }
            else
            {
                toPD = false;
                timer_PD.Stop();

                csMsg.ShowInfo("盘点完成", false);
                //运行到接药口
                PLC_Tcp_CP.ExtramanAutoMoveToPulse(float.Parse(Config.Mac_C.Pulse_Meet_X), float.Parse(Config.Mac_C.Pulse_Meet_Z));
            }
        }
コード例 #5
0
        //指定储位加药
        private int Add(string posCode, string dir, int num, string batch, bool qz, ref bool stopAdd)
        {
            int    result = 0;
            string sql    = "select pulsex,pulsez from pos_pulse where maccode='{0}' and poscode='{1}' and pulselr='{2}' and pulsetype='A'";

            sql = string.Format(sql, Config.Soft.MacCode, posCode, dir);
            DataTable dt;

            csSql.ExecuteSelect(sql, Config.Soft.ConnString, out dt);
            if (dt.Rows.Count <= 0)
            {
                return(0);
            }
            float targetX = float.Parse(dt.Rows[0][0].ToString());
            float targetZ = float.Parse(dt.Rows[0][1].ToString());

            //PLC.ChangeAdd(1);
            //运行到加药位置
            if (PLC_Tcp_CP.ExtramanAutoMoveToPulse(targetX, targetZ))
            {
                DateTime timeBegin = DateTime.Now;
                Thread.Sleep(200);
                while (!PLC_Tcp_CP.ExtramanAutoMoveIsOK())
                {
                    if (DateTime.Now > timeBegin.AddSeconds(Config.Mac_C.WaitTime_Auto_Extraman))
                    {
                        csMsg.ShowWarning("加药定位失败", false);
                        return(0);
                    }
                    Thread.Sleep(200);
                }
            }
            else
            {
                csMsg.ShowWarning("加药定位指令发送失败", false);
                return(0);
            }

            float maxPulse = float.Parse(Config.Mac_C.Pulse_Plate_Max_Left);

            PLC_Tcp_AP.PlateType type = PLC_Tcp_AP.PlateType.Left;

            if (dir == "R")
            {
                type     = PLC_Tcp_AP.PlateType.Right;
                maxPulse = float.Parse(Config.Mac_C.Pulse_Plate_Max_Right);
            }

            float nowPulse = PLC_Tcp_CP.ReadPlatePulse(type);

            //计数清零
            PLC_Tcp_CP.ResetPlateRecord(type);

            int oldRecord = 0, newRecord = 0;

            stopAdd = false;

            //获取药盒厚度
            float drugThickness = 10;

            sql = "select height from drug_infoannex where drugonlycode in(select drugonlycode from drug_pos where poscode='{0}')";
            sql = string.Format(sql, posCode);
            string s;

            csSql.ExecuteScalar(sql, Config.Soft.ConnString, out s);
            if (!string.IsNullOrEmpty(s))
            {
                drugThickness = float.Parse(s);
            }
            //上推脉冲
            float upPulse = Convert.ToInt32(drugThickness * Config.Mac_C.OneMMPulse_Plate);

            //补偿脉冲值
            //int bcPulse = 500;

            for (int i = 0; i < num;)
            {
                //有障碍物,暂停
                //int z = PLC.PlateErrorZHA();
                //while (z == 1 || z == 2)
                //{
                //    Thread.Sleep(200);
                //    if (z == 1)
                //        ThrowMsg("左侧加药手有障碍物");
                //    else if (z == 1)
                //        ThrowMsg("右侧加药手有障碍物");
                //    z = PLC.PlateErrorZHA();
                //}

                //加药+补偿
                for (int j = 1; j <= (Config.Mac_C.Count_BC + 1); j++)
                {
                    if (j == 1)
                    {
                        nowPulse += upPulse;
                    }
                    else
                    {
                        nowPulse += Config.Mac_C.OneMMPulse_Plate * (drugThickness * Config.Mac_C.Height_BC);
                    }

                    if (nowPulse > maxPulse)
                    {
                        nowPulse = maxPulse;
                    }
                    //上推
                    PLC_Tcp_CP.PlateAutoMoveToPulse(type, nowPulse);
                    DateTime timeBegin = DateTime.Now;
                    Thread.Sleep(100);
                    while (!PLC_Tcp_CP.PlateAutoMoveToPulseIsOK(type))
                    {
                        if (DateTime.Now > timeBegin.AddSeconds(Config.Mac_C.WaitTime_Auto_Plate))
                        {
                            csMsg.ShowWarning("推板定位失败", false);
                            break;
                        }
                        Thread.Sleep(100);
                    }
                    //上推完成,判断计数
                    if (DateTime.Now <= timeBegin.AddSeconds(Config.Mac_C.WaitTime_Auto_Plate))
                    {
                        DateTime t1 = DateTime.Now;
                        Thread.Sleep(200);
                        while (true)
                        {
                            newRecord = PLC_Tcp_CP.ReadPlateRecord(type);
                            if (newRecord > oldRecord)
                            {
                                break;
                            }
                            else if (DateTime.Now > t1.AddSeconds(2))
                            {
                                break;
                            }
                            Thread.Sleep(200);
                        }
                        if (newRecord > oldRecord)
                        {
                            oldRecord = newRecord;

                            if (dir == "L")
                            {
                                SetNumL(plate_Left.Num - newRecord);
                            }
                            else
                            {
                                SetNumR(plate_Right.Num - newRecord);
                            }

                            break;
                        }
                        else
                        {
                            if (j < (Config.Mac_C.Count_BC + 1))
                            {
                                continue;
                            }
                            else
                            {
                                //故障
                                SetErrorVisibility(Visibility.Visible);
                                stopAdd = true;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                i = newRecord;
                if (nowPulse >= maxPulse)
                {
                    break;
                }
                if (stopAdd)
                {
                    break;
                }
            }
            result = newRecord;

            string drugBatch = "";

            if (qz)
            {
                drugBatch = batch;
            }
            else
            {
                sql = "select * from drug_pos where (drugbatch<'{0}' or drugbatch is null) and maccode='{1}' and poscode='{2}' order by drugbatch";
                sql = string.Format(sql, batch, Config.Soft.MacCode, posCode);
                csSql.ExecuteSelect(sql, Config.Soft.ConnString, out dt);
                if (dt.Rows.Count > 0)
                {
                    drugBatch = dt.Rows[0]["drugbatch"].ToString().Trim();
                }
                else
                {
                    drugBatch = batch;
                }
            }
            //更新储位库存
            s   = "update drug_pos set drugnum=(drugnum+{0}),drugbatch='{1}' where maccode='{2}' and poscode='{3}';";
            sql = string.Format(s, result, drugBatch, Config.Soft.MacCode, posCode);
            //增加加药明细
            s    = "insert into drug_import select '{0}',drugonlycode,'{1}','I','{2}',drugunit,'{3}',getdate(),'' from drug_pos where maccode='{0}' and poscode='{4}';";
            sql += string.Format(s, Config.Soft.MacCode, batch, result, Config.Soft.UserCode, posCode);

            csSql.ExecuteSql(sql, Config.Soft.ConnString);

            return(result);
        }