private void Lift_Run_Auto(float p) { Cursor = Cursors.Wait; PLC_Tcp_CP.ChangeOut(1); PLC_Tcp_CP.LiftAutoMoveByPulse(p); DateTime timeBegin = DateTime.Now; Thread.Sleep(200); while (!PLC_Tcp_CP.LiftAutoMoveIsOK()) { if (DateTime.Now > timeBegin.AddSeconds(Config.Mac_C.WaitTime_Auto_Lift)) { break; } Thread.Sleep(200); } if (DateTime.Now <= timeBegin.AddSeconds(Config.Mac_C.WaitTime_Auto_Lift)) { tbPulse_Lift_Now.Text = PLC_Tcp_CP.ReadLiftPulse().ToString(); } else { csMsg.ShowWarning("提升机未运行到指定位置", false); } Cursor = null; }
//填充仓位 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)); } } }
private void btLift_Down_PreviewMouseDown(object sender, MouseButtonEventArgs e) { PLC_Tcp_CP.ChangeOut(0); PLC_Tcp_CP.LiftManualMove(PLC_Tcp_AP.LiftMoveDir.Down); }
public Dictionary <string, int> dicsOut; //实际出药数据表 //开始出药 public void Out() { //锁定出药 IsOut = true; //添加计数列,初始化为0 dtToOut.Columns.Add("Record"); dtToOut.Columns.Add("Error"); foreach (DataRow row in dtToOut.Rows) { row["Record"] = 0; row["Error"] = 0; } bool haveOut = false; //检查每个储位库存是否足够出药,库存不足error=100,忽略出药 foreach (DataRow row in dtToOut.Rows) { string poscode = row["poscode"].ToString().Trim(); int num = int.Parse(row["num"].ToString().Trim()); //查询是否缺药 string s; string sql = "select isnull(drugnum,0) from drug_pos where maccode='{0}' and poscode='{1}' and errorNum<3"; sql = string.Format(sql, Config.Soft.MacCode, poscode); csSql.ExecuteScalar(sql, Config.Soft.ConnString, out s); int kc = 0; if (s != null) { kc = int.Parse(s); } if (num > kc) { row["error"] = 100; } } List <string> poss = new List <string>(); if (NeedOut(dtToOut, out poss)) { PLC_Tcp_CP.ChangeOut(1); if (!PLC_Tcp_CP.LiftOnMeet()) { PLC_Tcp_CP.LiftAutoMoveToPos(PLC_Tcp_AP.MovePos.Meet); } if (!PLC_Com_CP.BaffleOnClose()) { PLC_Com_CP.BaffleClose(); } //ThrowMsg("出药准备"); PLC_Tcp_CP.TransferBeltMove(PLC_Tcp_AP.TransferBeltMoveType.Right); Thread.Sleep(Config.Mac_C.WaitTime_Start); //ThrowMsg("等待提升机到位"); DateTime timeBegin = DateTime.Now; Thread.Sleep(200); while (!PLC_Tcp_CP.LiftOnMeet()) { if (DateTime.Now > timeBegin.AddSeconds(Config.Mac_C.WaitTime_Auto_Lift)) { ThrowMsg("提升机未到位"); IsOut = false; return; } Thread.Sleep(200); } //ThrowMsg("等待挡板关闭"); timeBegin = DateTime.Now; Thread.Sleep(200); while (!PLC_Com_CP.BaffleOnClose()) { if (DateTime.Now > timeBegin.AddSeconds(Config.Mac_C.WaitTime_Auto_Baffle)) { ThrowMsg("挡板未关闭"); IsOut = false; return; } Thread.Sleep(200); } } //出药开始标签 outStart: NeedOut(dtToOut, out poss); //计数清零 PLC_Tcp_CP.ClearRecordMutil(poss); Dictionary <string, int> dicsOldRecord = PLC_Tcp_CP.ReadRecordMutil(poss); Dictionary <string, int> dicsNewRecord; //ThrowMsg("开始出药"); while (NeedOut(dtToOut, out poss)) { //ThrowMsg("出药动作"); PLC_Tcp_CP.DCTMoveDownMutil(poss); //ThrowMsg("等待计数"); Thread.Sleep(1000); dicsNewRecord = PLC_Tcp_CP.ReadRecordMutil(poss); //ThrowMsg("更新出药数据表"); foreach (string p in dicsNewRecord.Keys) { int oldRecord = 0; if (dicsOldRecord.Keys.Contains(p)) { oldRecord = dicsOldRecord[p]; } else { dicsOldRecord.Add(p, 0); } int newRecord = dicsNewRecord[p]; DataRow[] rows = dtToOut.Select("poscode ='" + p + "'"); rows[0]["record"] = newRecord; if (newRecord - oldRecord != 1) { rows[0]["error"] = int.Parse(rows[0]["error"].ToString()) + 1; ThrowMsg("记录出药异常"); string sql = "insert into sys_error select '{0}','{1}',drugonlycode,'OE',1,'{2}',getdate() from drug_pos where poscode='{1}'"; sql = string.Format(sql, Config.Soft.MacCode, p, newRecord - oldRecord); sql += ";update drug_pos set errornum=(errornum+1) where maccode='{0}' and poscode='{1}'"; sql = string.Format(sql, Config.Soft.MacCode, p); csSql.ExecuteSql(sql, Config.Soft.ConnString); } } dicsOldRecord = dicsNewRecord; } //ThrowMsg("出药数据表"); foreach (DataRow row in dtToOut.Rows) { string poscode = row["poscode"].ToString().Trim(); int record = int.Parse(row["record"].ToString().Trim()); if (record > 0) { haveOut = true; if (dicsOut.Keys.Contains(poscode)) { dicsOut[poscode] += record; } else { dicsOut.Add(poscode, record); } } } //ThrowMsg("补偿出药"); if (BC) { DataTable dtBC = dtToOut.DefaultView.ToTable(); dtBC.Clear(); foreach (DataRow row in dtToOut.Rows) { string poscode = row["poscode"].ToString().Trim(); int num = int.Parse(row["num"].ToString().Trim()); int record = int.Parse(row["record"].ToString().Trim()); if (num > record) { string drugOnlyCode; string sql = "select drugonlycode from drug_pos where maccode='{0}' and poscode='{1}'"; sql = string.Format(sql, Config.Soft.MacCode, poscode); csSql.ExecuteScalar(sql, Config.Soft.ConnString, out drugOnlyCode); if (!string.IsNullOrEmpty(drugOnlyCode)) { BCOut(drugOnlyCode, num - record, ref dtBC); } } } dtToOut = dtBC; BC = false; goto outStart; } //ThrowMsg("更新库存"); UpdateStock(dicsOut); //ThrowMsg("更新出药结果(多出,少出)"); if (!string.IsNullOrEmpty(PrescNo)) { UpdateOutResult(dicsOut, dtDrug); } if (haveOut) { Thread.Sleep(Config.Mac_C.WaitTime_Stop); } PLC_Tcp_CP.TransferBeltMove(PLC_Tcp_AP.TransferBeltMoveType.Stop); if (haveOut) { if (OutPosition == PLC_Tcp_AP.MovePos.Top) { PLC_Tcp_CP.TopBeltMove(PLC_Tcp_AP.TopBeltMoveType.Turn); } //ThrowMsg("送至出药口"); PLC_Tcp_CP.LiftAutoMoveToPos(OutPosition); DateTime timeBegin = DateTime.Now; Thread.Sleep(500); while (!PLC_Tcp_CP.LiftAutoMoveIsOK()) { if (DateTime.Now > timeBegin.AddSeconds(Config.Mac_C.WaitTime_Auto_Lift)) { ThrowMsg("提升机未到位"); IsOut = false; return; } Thread.Sleep(200); } //ThrowMsg("出药"); PLC_Com_CP.BaffleOpen(); while (!PLC_Com_CP.BaffleOnOpen()) { Thread.Sleep(200); } Thread.Sleep(Config.Mac_C.OpenTime_Baffle); PLC_Com_CP.BaffleClose(); if (OutPosition == PLC_Tcp_AP.MovePos.Top) { Thread.Sleep(2000); PLC_Tcp_CP.TopBeltMove(PLC_Tcp_AP.TopBeltMoveType.Stop); } //ThrowMsg("出药返回"); PLC_Tcp_CP.LiftAutoMoveToPos(PLC_Tcp_AP.MovePos.Meet); IsOut = false; } else { IsOut = false; } }