示例#1
0
        public static void InitData()
        {
            EqpPoint.Clear();


            DataTable device = DevicePoint.GetDistinctDevice();

            if (device == null || device.Rows.Count == 0)
            {
            }
            else
            {
                string deviceid = "";
                for (int i = 0; i < device.Rows.Count; i++)
                {
                    deviceid = device.Rows[i]["deviceid"].ToString().Trim();
                    if (!string.IsNullOrEmpty(deviceid))
                    {
                        DataTable dt = DevicePoint.GetDataPointByDeviceID(deviceid);
                        if (dt == null || dt.Rows.Count == 0)
                        {
                        }
                        else
                        {
                            ArrayList list = new ArrayList();
                            for (int j = 0; j < dt.Rows.Count; j++)
                            {
                                RowDataPoint point = new RowDataPoint();
                                point.IP        = dt.Rows[j]["IP"].ToString().Trim();
                                point.TagID     = dt.Rows[j]["TagID"].ToString().Trim();
                                point.TagName   = dt.Rows[j]["TagName"].ToString().Trim();
                                point.type      = dt.Rows[j]["type"].ToString().Trim();
                                point.datatype  = Convert.ToInt32(dt.Rows[j]["dataType"].ToString().Trim());
                                point.dbNumber  = Convert.ToInt32(dt.Rows[j]["dbNumber"].ToString().Trim());
                                point.startByte = Convert.ToInt32(dt.Rows[j]["startByte"].ToString().Trim());
                                point.bitNumber = Convert.ToInt32(dt.Rows[j]["bitNumber"].ToString().Trim());
                                point.vartype   = Convert.ToInt32(dt.Rows[j]["varType"].ToString().Trim());
                                list.Add(point);
                            }
                            EqpPoint.Add(deviceid, list);
                        }
                    }
                }
            }
        }
示例#2
0
        public static void GetFirstDataFromPLC()
        {
            try
            {
                UInt32     str     = 0;
                ArrayList  list    = null;
                string     openstr = "OK";
                object     readobj = null;
                PLCHisData plchis  = null;
                foreach (var adapter in RowConfig.EqpPoint)
                {
                    list = adapter.Value;
                    if (list != null)
                    {
                        RowDataPoint eqp = (RowDataPoint)list[0];
                        Plc          plc = PLCSingleton.CreatePLC(CpuType.S7300, eqp.IP, 0, 2); //new Plc(CpuType.S7300, "10.21.189.139", 0, 2);

                        try
                        {
                            openstr = plc.QMOpen();
                            if (openstr == "OK")
                            {
                                foreach (var V in list)
                                {
                                    eqp = (RowDataPoint)V;
                                    try
                                    {
                                        readobj = plc.QMRead((DataType)eqp.datatype, eqp.dbNumber, eqp.startByte, (VarType)eqp.vartype, 1);
                                        // str = (UInt32)plc.QMRead((DataType)eqp.datatype, eqp.dbNumber, eqp.startByte, (VarType)eqp.vartype, 1);
                                        if (readobj != null)
                                        {
                                            str = (UInt32)readobj;

                                            plchis = FrontData.dic[eqp.TagID];

                                            plchis.Value = str;
                                            plchis.TagID = eqp.TagID;
                                            plchis.type  = RowConfig.TagDic[plchis.TagID].type;

                                            plchis.refid = DTKAG.KAGCreateNewDT(eqp.TagID, plchis.type, str);
                                            plchis.Time  = DateTime.Now;

                                            if (eqp.TagID == EqpName.FillerStatusTagID)
                                            {
                                                plchis.formid = PersisDTFiller.CL1NewDTFiller("", "", "", str);
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Error(ex.ToString());
                                    }
                                }
                                plc.Close();
                            }
                            else
                            {
                                SetEQPRealDataMax(eqp.EQP);
                                Log.Error("[PLC][Link Fail] IP Address is : " + eqp.IP);
                                Log.Error(openstr);
                            }
                            //  throw new InvalidAddressException("To few periods for DB address");
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }
示例#3
0
        public static void GetDataFromPLC()
        {
            try
            {
                UInt32    str     = 0;
                ArrayList list    = null;
                string    openstr = "OK";
                object    readobj = null;
                foreach (var adapter in RowConfig.EqpPoint)
                {
                    list = adapter.Value;
                    if (list != null)
                    {
                        RowDataPoint eqp = (RowDataPoint)list[0];
                        Plc          plc = PLCSingleton.CreatePLC(CpuType.S7300, eqp.IP, 0, 2); //new Plc(CpuType.S7300, "10.21.189.139", 0, 2);

                        try
                        {
                            openstr = plc.QMOpen();
                            if (openstr == "OK")
                            {
                                foreach (var V in list)
                                {
                                    eqp = (RowDataPoint)V;
                                    try
                                    {
                                        readobj = plc.QMRead((DataType)eqp.datatype, eqp.dbNumber, eqp.startByte, (VarType)eqp.vartype, 1);
                                        // str = (UInt32)plc.QMRead((DataType)eqp.datatype, eqp.dbNumber, eqp.startByte, (VarType)eqp.vartype, 1);
                                        if (readobj != null)
                                        {
                                            str = (UInt32)readobj;
                                            RealData.dic[eqp.TagID] = str;

                                            Console.WriteLine(eqp.TagID + "  Value is: " + str);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Error(ex.ToString());
                                    }
                                }
                            }
                            else
                            {
                                SetEQPRealDataMax(eqp.EQP);
                                Log.Error("[PLC][Link Fail] IP Address is : " + eqp.IP);
                                Log.Error(openstr);
                            }
                            //  throw new InvalidAddressException("To few periods for DB address");
                            plc.Close();
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }