Example #1
0
        public Dictionary <int, string> Endbag_State(string db)
        {
            string errText = string.Empty;

            string[] sArray = Regex.Split(db, "&", RegexOptions.IgnoreCase);
            for (int k = 0; k <= sArray.Length; k++)
            {
                string state = PlcFactory.Instance().ReadPlcDbValue(sArray[k], ref errText);
                if (state != "" || state != null)
                {
                    byte   b     = Convert.ToByte(state);
                    byte[] bytes = toBits(b);
                    //倒叙
                    byte[] byteNew = new byte[bytes.Length];
                    for (int i = bytes.Length - 1; i >= 0; i--)
                    {
                        byteNew[bytes.Length - i + 1] = bytes[i];
                    }
                    //将格口转态以键值对的形式添加到map
                    for (int m = 0; m < byteNew.Length; m++)
                    {
                        map.Add(m, byteNew[m].ToString());
                    }
                }
            }

            return(map);
        }
Example #2
0
        /// <summary>
        /// 格口状态查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void SelectState()
        {
            string errText = string.Empty;

            try
            {
                for (short prot = 1; prot < 19; prot++)
                {
                    string val = PlcFactory.Instance().ReadPlcDbValue("满袋" + prot.ToString() + "%", ref errText);
                    //1 锁定  0 解锁
                    if (val == "-1")
                    {
                        createdata.UpdateErrProtSts(prot.ToString(), "", "1");
                        createdata.clearCount(prot.ToString());
                    }
                    else if (val == "0")
                    {
                        createdata.UpdateErrProtSts(prot.ToString(), "", "0");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteLog2("袋子满了 ex" + ex.Message);
            }
        }
Example #3
0
 static Globals()
 {
     Log = ChoreoLogger.GetLogging();
     VM  = new ViewModel();
     Storage.LoadAll();
     Plc = PlcFactory.New();
     VM.Init();
 }
Example #4
0
 static Globals()
 {
     Log = ChoreoLogger.GetLogging();
     VM  = new ViewModel();
     Storage.LoadAll();
     Plc = PlcFactory.New();
     Plc.SymbolsUpdated += Plc_SymbolsUpdated;
 }
Example #5
0
        static void Main()
        {
            #region 初始化PLC

            try
            {
                System.Threading.Thread.Sleep(300);
                Dictionary <string, List <string> > typeClass = new Dictionary <string, List <string> >();

                DataTable table = RfConfig.Create().plcds.Tables[0];
                foreach (DataRow row in table.Rows)
                {
                    string[]      plcstr  = row["plcvalaue"].ToString().Split('%');
                    List <string> listPlc = new List <string>();
                    for (int i = 0; i < plcstr.Length; i++)
                    {
                        if (plcstr[i].ToString().Trim().Length > 0)
                        {
                            listPlc.Add(plcstr[i].ToString());
                        }
                    }

                    typeClass.Add(row["vlaue"].ToString(), listPlc);
                }

                PlcFactory.Instance().typeClass = typeClass;
            }
            catch (Exception ex)
            {
                // SystemParam.ErrText = ex.Message.ToString();
                DevExpress.XtraSplashScreen.SplashScreenManager.Default.SendCommand(
                    SplashScreen1.SplashScreenCommand.labelControl2, "初始化PLC失败");
                //  SystemParam.plcStatus = false;
            }

            #endregion
            CreateData.createDataBase();
            Application.Run(new FrmMain());
        }
Example #6
0
        private void ListenData()
        {
            while (true)
            {
                Thread.Sleep(20);
                string errText = string.Empty;
                string seq     = PlcFactory.Instance().ReadPlcDbValue("FromPlc_seq%", ref errText);
                string code    = PlcFactory.Instance().ReadPlcDbValue("FromPlc_barcode%", ref errText);

                //string code = code0.Replace("&", "");
                if (seq.Trim().Equals("") || int.Parse(seq) <= 10000 || code.Trim().Equals("") || seqOld.Equals(seq))
                {
                    Thread.Sleep(200);
                    continue;
                }

                seqOld  = seq;
                codeOld = code;
                if (oldExpressNo != code || oldplcid != seq)
                {
                    DataChange(code, int.Parse(seq));
                }
            }
        }
Example #7
0
        public void BagCount()
        {
            while (true)
            {
                Thread.Sleep(20);
                try
                {
                    string errText = string.Empty;
                    for (int i = 0; i <= 18; i++)
                    {
                        string plcid = PlcFactory.Instance().ReadPlcDbValue("EndBag" + i + "%1", ref errText);
                        //Log.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff")+" 读取到PLCID:" + plcid);
                        //string mouthid = PlcFactory.Instance().ReadPlcDbValue("满袋" + i + "%", ref errText);
                        //Console.WriteLine(mouthid);
                        HashForeach.HashAdd(plcid, i);
                        //HashForeach.HashStateAdd(i, mouthid);
                    }
                    Dictionary <string, int> openWith1 = HashForeach.openWith;
                    Dictionary <int, string> openWith2 = HashForeach.openstate;

                    DataTable tb = createdata.MatchingData();
                    if (tb != null)
                    {
                        if (tb.Rows.Count > 0)
                        {
                            foreach (DataRow row in tb.Rows)
                            {
                                string plcid = row["plcid"].ToString();
                                string seqId = string.Empty;
                                string code  = row["ExpressNo"].ToString();

                                if (code == "ERROR\r")
                                {
                                    // 更改实际落袋格口 endport
                                    //createdata.UpdateEndprot(19, code);
                                    //更改格口数量
                                    createdata.UpdateCount(19);
                                    createdata.UpdateMatching(plcid);
                                    createdata.UpdateEndprot(19, plcid);
                                    Log.WriteLog(DateTime.Now + " 条码为空。 条码:" + code);
                                    break;
                                }
                                //格口锁定情况下
                                bool st = createdata.SelectState(plcid, code);
                                if (st)
                                {
                                    createdata.UpdateCount(19);
                                    createdata.UpdateMatching(plcid);
                                    createdata.UpdateEndprot(19, plcid);
                                    Log.WriteLog(DateTime.Now + " 格口锁定。 条码:" + code);
                                    break;
                                }
                                else
                                {
                                    try
                                    {
                                        int i = openWith1[plcid];
                                        openWith1.Remove(plcid);
                                        createdata.UpdateCount(i);
                                        createdata.UpdateMatching(plcid);
                                        createdata.UpdateEndprot(i, plcid);
                                        break;
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.WriteLog2(DateTime.Now + "更改正常条码落袋数据异常:" + ex.Message.ToString());
                                    }
                                }
                                DateTime time1       = Convert.ToDateTime(row["begindate"]);
                                DateTime d1          = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));//当前日期
                                int      unusualtime = Convert.ToInt32(d1.Subtract(time1).TotalSeconds.ToString());
                                if (unusualtime > 20)
                                {
                                    createdata.UpdateCount(19);
                                    createdata.UpdateMatching(plcid);
                                    createdata.UpdateEndprot(19, plcid);
                                    Log.WriteLog(DateTime.Now + " 条码异常。 条码:" + code);
                                }
                            }
                            BindData();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.WriteLog(DateTime.Now + "读取或对比PLC DB异常:" + ex.Message.ToString());
                }
            }
        }