Esempio n. 1
0
        public bool GetDeviceData(DataTable dt)
        {
            if (dt != null)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    for (int j = 0; j < dr.ItemArray.Length; j++)
                    {
                        if (string.IsNullOrWhiteSpace(dr[j].ToString()))
                        {
                            continue;
                        }
                    }

                    YBDTWorkInfo ybWorkInfo = new YBDTWorkInfo(dr);

                    YbdtWorkInfoLst.Add(ybWorkInfo);
                }
            }
            if (YbdtWorkInfoLst.Count < 1)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        void WorkClientAdd(object sender, Socket e)
        {
            string       strIp = (e.RemoteEndPoint as IPEndPoint).Address.ToString();
            YBDTWorkInfo yw    = GetWorkInfoFromLst(YbdtWorkInfoLst, strIp);

            if (yw != null)
            {
                YBDTWork ybdtwork = new YBDTWork(e, yw);
                if (ybdtwork.YbtdDevice.Status == Constant.DeviceConnected)
                {
                    YBDTWorkChanged(Constant.AddWork, ybdtwork);
                }
                else
                {
                    ybdtwork.Dispose();
                }
            }
        }
Esempio n. 3
0
        public YBDTWork(Socket soc, YBDTWorkInfo y0)
        {
            //加载数据如果不对 那就用户自己加载
            StrDataFormPath = new List <string>();
            StrDataFormPath.Add(Constant.PlcDataFilePathAuto);
            StrDataFormPath.Add(Constant.PlcDataFilePathHand);
            StrDataFormPath.Add(Constant.PlcDataFilePathParam);
            StrDataFormPath.Add(Constant.PlcDataFilePathIO);
            startTime = DateTime.Now;
            for (int i = StrDataFormPath.Count - 1; i >= 0; i--)
            {
                if (!File.Exists(StrDataFormPath[i]))
                {
                    StrDataFormPath.RemoveAt(i);
                    MessageBox.Show(Constant.ErrorPlcFile);
                    return;
                }
            }

            //这里需要特殊分开 因为有些模块是用老的用232 有些是485的
            if (y0.DeviceId.Equals("长机右") || y0.DeviceId.Equals("长机左"))
            {
                YbtdDevice = new YBDTDevice(StrDataFormPath, soc, Constant.TaiDaConnectMode232);
            }
            else
            {
                YbtdDevice = new YBDTDevice(StrDataFormPath, soc, Constant.TaiDaConnectMode485);
            }

            excelop = new ExcelNpoi();

            excelop.FileName = string.Concat(
                ConstantMethod.GetAppPath(), DateTime.Now.ToString("yyyMMdd"), Constant.prodResult, ".xlsx"); ////"\\configParam.xml"

            YbdtWorkInfo = y0;

            AllPlcSimpleLst = new List <List <DTPlcInfoSimple> >();
            PsLstAuto       = new List <DTPlcInfoSimple>();
            PsLstAuto.Add(startInPs);
            PsLstAuto.Add(startInPs1);
            PsLstAuto.Add(startInPs2);
            PsLstAuto.Add(startInPs3);
            PsLstAuto.Add(startInPs4);
            PsLstAuto.Add(startInPs5);
            PsLstAuto.Add(startInPs6);
            PsLstAuto.Add(startInPs7);
            PsLstAuto.Add(startInPs8);
            PsLstAuto.Add(startInPs9);
            PsLstAuto.Add(startInPs18);
            PsLstAuto.Add(startInPs10);
            PsLstAuto.Add(startInPs11);
            PsLstAuto.Add(startInPs12);
            PsLstAuto.Add(startInPs13);
            PsLstAuto.Add(startInPs14);
            PsLstAuto.Add(startInPs15);
            PsLstAuto.Add(startInPs16);
            PsLstAuto.Add(startInPs17);
            PsLstAuto.Add(startInPs12);
            PsLstAuto.Add(startInPs13);
            PsLstAuto.Add(startInPs14);
            PsLstAuto.Add(startInPs15);
            PsLstAuto.Add(startInPs16);
            PsLstAuto.Add(startInPs17);
            PsLstAuto.Add(proQuantityInOutPs);
            AllPlcSimpleLst.Add(PsLstAuto);
            StopTime = new List <int>();
            //SaveData();
            //设置数据库定时更新
            UpdateTimer           = new System.Timers.Timer();
            UpdateTimer.Elapsed  += UpdateSqlTimeEvent;
            UpdateTimer.Interval  = 1000;
            UpdateTimer.AutoReset = true;


            //设置数据结果导出
            UpdateFile           = new System.Timers.Timer();
            UpdateFile.Elapsed  += UpdateFileTimeEvent;
            UpdateFile.Interval  = 100000;
            UpdateFile.AutoReset = true;

            if (!YbtdDevice.getDeviceData())
            {
                //MessageBox.Show(Constant.ConnectMachineFail);
                Dispose();
                return;
            }

            SqlDeiviceInfoDatatable = new DataTable();

            // UpdateTimer.Enabled = true;
            //  UpdateFile.Enabled = true ;
        }