Example #1
0
        //public CRLConveryControl(string ip)
        //{
        //    _ip = ip;
        //    mPLC = new RWLOPCServerl(_ip);
        //}

        //public bool InitOPCData(DataSet ds)
        //{
        //    if (ds != null)
        //    {
        //        DataTable dt = ds.Tables[0];
        //        for (int i = 0; i < dt.Rows.Count; i++)
        //        {
        //            if (dt.Rows[i]["userid"].ToString() == _ip)
        //            {
        //                if (dt.Rows[i]["groupname"].ToString() == "Convery")
        //                {
        //                    CRLStationInfo si = new CRLStationInfo();
        //                    si.stationno = int.Parse(dt.Rows[i]["stationno"].ToString());
        //                    si.stationtype = int.Parse(dt.Rows[i]["stationtype"].ToString());
        //                    si.LocationX = int.Parse(dt.Rows[i]["field1"].ToString());
        //                    si.LocationY = int.Parse(dt.Rows[i]["field2"].ToString());
        //                    si.Width = SplitWidth(dt.Rows[i]["remark"].ToString())[0];
        //                    si.Height = SplitWidth(dt.Rows[i]["remark"].ToString())[1];
        //                    si.value = int.Parse(dt.Rows[i]["value"].ToString());
        //                    si.config = dt.Rows[i]["field3"].ToString();
        //                    StationInfo.Add(si);

        //                    CRLOPCItem findco = ItemInfo.Find(
        //                        delegate(CRLOPCItem ii)
        //                        {
        //                            return ii.groupname == "Convery";
        //                        }
        //                    );
        //                    if (findco == null)
        //                    {
        //                        CRLOPCItem coi = new CRLOPCItem();
        //                        coi.groupname = dt.Rows[i]["groupname"].ToString();
        //                        coi.ipaddress = dt.Rows[i]["userid"].ToString();
        //                        coi.DBAddress = int.Parse(dt.Rows[i]["objects"].ToString());
        //                        coi.start = int.Parse(dt.Rows[i]["value"].ToString());
        //                        coi.length = int.Parse(dt.Rows[i]["signaltype"].ToString());
        //                        ItemInfo.Add(coi);
        //                    }
        //                    else
        //                        findco.length += 20;//leo 30 to 20
        //                }
        //                else
        //                {
        //                    CRLOPCItem co = new CRLOPCItem();
        //                    co.groupname = dt.Rows[i]["groupname"].ToString();
        //                    co.ipaddress = dt.Rows[i]["userid"].ToString();
        //                    co.DBAddress = int.Parse(dt.Rows[i]["objects"].ToString());
        //                    co.start = int.Parse(dt.Rows[i]["value"].ToString());
        //                    co.length = int.Parse(dt.Rows[i]["stationno"].ToString());
        //                    ItemInfo.Add(co);
        //                }
        //            }
        //        }
        //        return true;
        //    }
        //    return false;
        //}

        public bool InitOPCData(DataSet ds)
        {
            if (ds != null)
            {
                DataTable dt = ds.Tables[0];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    _ip = dt.Rows[i]["userid"].ToString();
                    if (!PLCList.ContainsKey(_ip))
                    {
                        PLCList.Add(_ip, new RWLOPCServerl(_ip));
                        PLCFlag.Add(_ip, false);
                        PLCList[_ip].Connect();
                    }

                    switch (dt.Rows[i]["groupname"].ToString())
                    {
                    case "Convery": ConveryInit(dt.Rows[i]); break;

                    //case "OutPick": OutPickInit(dt.Rows[i]); break;
                    //case "InPick": InPickInit(dt.Rows[i]); break;
                    default: OtherInit(dt.Rows[i]); break;
                    }
                    //if (dt.Rows[i]["groupname"].ToString() == "Convery")
                    //{
                    //    CRLOPCItem findco = ItemInfo.Find(
                    //        delegate(CRLOPCItem ii)
                    //        {
                    //            return ii.groupname == "Convery";
                    //        }
                    //    );
                    //    if (findco == null)
                    //    {
                    //        CRLOPCItem coi = new CRLOPCItem();
                    //        coi.groupname = dt.Rows[i]["groupname"].ToString();
                    //        coi.ipaddress = dt.Rows[i]["userid"].ToString();
                    //        coi.DBAddress = int.Parse(dt.Rows[i]["objects"].ToString());
                    //        coi.start = int.Parse(dt.Rows[i]["value"].ToString());
                    //        coi.length = int.Parse(dt.Rows[i]["signaltype"].ToString());
                    //        ItemInfo.Add(coi);
                    //    }
                    //    else
                    //        findco.length += 20;//leo 30 to 20
                    //}
                    //else
                    //{
                    //    CRLOPCItem co = new CRLOPCItem();
                    //    co.groupname = dt.Rows[i]["groupname"].ToString();
                    //    co.ipaddress = dt.Rows[i]["userid"].ToString();
                    //    co.DBAddress = int.Parse(dt.Rows[i]["objects"].ToString());
                    //    co.start = int.Parse(dt.Rows[i]["value"].ToString());
                    //    co.length = int.Parse(dt.Rows[i]["stationno"].ToString());
                    //    ItemInfo.Add(co);
                    //}
                }
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// 初始化输送机对应参数
        /// </summary>
        /// <returns></returns>
        public bool TransDeviceInit()
        {
            DataSet ds = DataTrans.D_GetDeviceSSJ();

            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    //获取设备编号第一个字母,用于与绑定IP地址
                    _SSJDhead = ds.Tables[0].Rows[i]["VAR1"].ToString().Substring(0, 1);
                    string _ip = ConfigurationManager.AppSettings[_SSJDhead].ToString();

                    //需要改进,将端口,DB块,端口等也进行构造函数初始化l
                    if (!PLCList.ContainsKey(_SSJDhead))
                    {
                        PLCList.Add(_SSJDhead, new RWLOPCServerl(_ip));
                        PLCFlag.Add(_SSJDhead, false);
                        PLCList[_SSJDhead].Connect();
                    }
                    if (!HsPLCList.ContainsKey(_SSJDhead))
                    {
                        HsPLCList.Add(_SSJDhead, new HsControlServer(_ip));
                        bool   flag = HsPLCList[_SSJDhead].HsServerConnect();
                        string res  = flag ? "成功" : "失败";
                        NotifyEvent?.Invoke($"PLC{_ip}连接{res}");
                    }

                    TransportStr tp = new TransportStr();
                    tp.SSJID    = ds.Tables[0].Rows[i]["SSJID"].ToString();
                    tp.BTID     = ds.Tables[0].Rows[i]["BTID"].ToString();
                    tp.DTYPE    = ds.Tables[0].Rows[i]["DTYPE"].ToString();
                    tp.ZXRWH    = ds.Tables[0].Rows[i]["ZXRWH"].ToString();
                    tp.DWXH     = ds.Tables[0].Rows[i]["DWXH"].ToString();
                    tp.KXBZ     = ds.Tables[0].Rows[i]["KXBZ"].ToString();
                    tp.TRAYCODE = ds.Tables[0].Rows[i]["TRAYCODE"].ToString();
                    tp.JYM      = ds.Tables[0].Rows[i]["JYM"].ToString();
                    tp.BFLAG    = ds.Tables[0].Rows[i]["BFLAG"].ToString();
                    tp.ALLEYID  = ds.Tables[0].Rows[i]["ALLEYID"].ToString();
                    //tp.ALLEYID = "";
                    tp.VAR1      = ds.Tables[0].Rows[i]["VAR1"].ToString();
                    tp.VAR2      = ds.Tables[0].Rows[i]["VAR2"].ToString();
                    tp.VAR3      = ds.Tables[0].Rows[i]["VAR3"].ToString();
                    tp.VAR4      = ds.Tables[0].Rows[i]["VAR4"].ToString();
                    tp.VAR5      = ds.Tables[0].Rows[i]["VAR5"].ToString();
                    tp.SSRWLX    = ds.Tables[0].Rows[i]["SSRWLX"].ToString();
                    tp.SSJIDhead = _SSJDhead;
                    lsTransport.Add(tp);
                }
                return(true);
            }
            return(false);
        }