コード例 #1
0
        //填充仓位
        void ShowPlate(PLC_Tcp_AP.PlateType type, string code, int num)
        {
            if (code != "" && num > 0)
            {
                if (type == PLC_Tcp_AP.PlateType.Left)
                {
                    plate_Left.DrugOnlyCode = code;
                    plate_Left.Num          = num;
                    tbNumL.Text             = plate_Left.Num.ToString();
                    btClearL.IsEnabled      = true;
                    gd_L.Background         = new SolidColorBrush(Colors.LightSalmon);
                    string sql = "select drugname,drugspec,drugfactory from drug_info where drugonlycode='{0}'";
                    sql = string.Format(sql, code);
                    DataTable dt;
                    csSql.ExecuteSelect(sql, Config.Soft.ConnString, out dt);
                    tbNameL.Text    = dt.Rows[0]["drugname"].ToString();
                    tbSpecL.Text    = dt.Rows[0]["drugspec"].ToString();
                    tbFactoryL.Text = dt.Rows[0]["drugfactory"].ToString();
                    //运动到预留位置
                    PLC_Tcp_CP.ChangeOut(1);
                    //获取药盒厚度
                    float drugThickness = 10;
                    sql = "select height from drug_infoannex where drugonlycode ='{0}'";
                    sql = string.Format(sql, code);
                    string s;
                    csSql.ExecuteScalar(sql, Config.Soft.ConnString, out s);
                    if (!string.IsNullOrEmpty(s))
                    {
                        drugThickness = float.Parse(s);
                    }
                    int pulse = Convert.ToInt32(num * drugThickness * Config.Mac_C.OneMMPulse_Plate);
                    PLC_Tcp_CP.PlateAutoMoveToPulse(PLC_Tcp_AP.PlateType.Left, float.Parse(Config.Mac_C.Pulse_Plate_Max_Left) - pulse);
                }
                else if (type == PLC_Tcp_AP.PlateType.Right)
                {
                    plate_Right.DrugOnlyCode = code;
                    plate_Right.Num          = num;
                    tbNumR.Text        = plate_Right.Num.ToString();
                    btClearR.IsEnabled = true;
                    gd_R.Background    = new SolidColorBrush(Colors.LightSalmon);
                    string sql = "select drugname,drugspec,drugfactory from drug_info where drugonlycode='{0}'";
                    sql = string.Format(sql, code);
                    DataTable dt;
                    csSql.ExecuteSelect(sql, Config.Soft.ConnString, out dt);
                    tbNameR.Text    = dt.Rows[0]["drugname"].ToString();
                    tbSpecR.Text    = dt.Rows[0]["drugspec"].ToString();
                    tbFactoryR.Text = dt.Rows[0]["drugfactory"].ToString();
                    //运动到预留位置
                    PLC_Tcp_CP.ChangeOut(1);
                    //获取药盒厚度
                    float drugThickness = 10;
                    sql = "select height from drug_infoannex where drugonlycode ='{0}'";
                    sql = string.Format(sql, code);
                    string s;
                    csSql.ExecuteScalar(sql, Config.Soft.ConnString, out s);
                    if (!string.IsNullOrEmpty(s))
                    {
                        drugThickness = float.Parse(s);
                    }
                    int pulse = Convert.ToInt32(num * drugThickness * Config.Mac_C.OneMMPulse_Plate);
                    PLC_Tcp_CP.PlateAutoMoveToPulse(PLC_Tcp_AP.PlateType.Right, float.Parse(Config.Mac_C.Pulse_Plate_Max_Right) - pulse);
                }
            }
            else
            {
                if (type == PLC_Tcp_AP.PlateType.Left)
                {
                    plate_Left.DrugOnlyCode = "";
                    plate_Left.Num          = 0;
                    tbNameL.Text            = "";
                    tbSpecL.Text            = "";
                    tbFactoryL.Text         = "";
                    tbNumL.Text             = "0";
                    btClearL.IsEnabled      = false;
                    gd_L.Background         = new SolidColorBrush(Colors.LightGreen);

                    PLC_Tcp_CP.PlateAutoMoveToPulse(PLC_Tcp_AP.PlateType.Left, float.Parse(Config.Mac_C.Pulse_Plate_Min_Left));
                }
                else if (type == PLC_Tcp_AP.PlateType.Right)
                {
                    plate_Right.DrugOnlyCode = code;
                    plate_Right.Num          = 0;
                    tbNameR.Text             = "";
                    tbSpecR.Text             = "";
                    tbFactoryR.Text          = "";
                    tbNumR.Text        = "0";
                    btClearR.IsEnabled = false;
                    gd_R.Background    = new SolidColorBrush(Colors.LightGreen);

                    PLC_Tcp_CP.PlateAutoMoveToPulse(PLC_Tcp_AP.PlateType.Right, float.Parse(Config.Mac_C.Pulse_Plate_Min_Right));
                }
            }
        }
コード例 #2
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);
        }