예제 #1
0
        private void OCPCallBack(int TransactionID, int NumItems, ref Array ClientHandles, ref Array Values, ref Array Qualities, ref Array TimeStamps, ref Array Errors)
        {
            Plc p = Plcs.ElementAt(TransactionID - 1).Value;

            string[] v    = new string[61];
            string   zone = "ZONE" + TransactionID.ToString("00");

            for (int i = 1; i <= 60; i++)
            {
                string kjr1 = ClientHandles.GetValue(i).ToString();
                string kjr2 = Values.GetValue(i).ToString();
                v[int.Parse(ClientHandles.GetValue(i).ToString())] = Values.GetValue(i).ToString();
            }

            for (int i = 1; i <= 30; i++)
            {
                int    ms   = int.Parse(v[i]);
                string desc = v[i + 30];
                if (ms > 0)
                {
                    Sequence s = p.AddSequence(i, zone, ms, desc);
                    NewSeq?.Invoke(p, s);
                }
            }
        }
예제 #2
0
        public void GetTestData()
        {
            Plcs.Clear();

            string       filePath = @"TestPlcs.csv";
            StreamReader sr       = new StreamReader(filePath);

            sr.ReadLine().Split(',');

            while (!sr.EndOfStream)
            {
                string[] Line = sr.ReadLine().Split(',');
                Plc      p;

                if (Plcs.ContainsKey(Line[0]))
                {
                    p = Plcs[Line[0]];
                }

                else
                {
                    p = _AddPLC(Line[0]);
                }


                int ms = int.Parse(Line[2]);
                if (ms > 0)
                {
                    Sequence s = p.AddSequence(int.Parse(Line[1]), Line[4], ms, Line[3]);
                    NewSeq?.Invoke(p, s);
                }
            }
            sr.Close();
        }
예제 #3
0
        public void ProjectAddSeq(Sequence s)
        {
            oProject.dynamicMode = Dynamic;

            if (oProject.Objects[s.ID] != null)
            {
                Plcs[s.Plc.Tag].Sequnces.Remove(s.Key);
            }

            CimObjectInstance oObj = new CimObjectInstance();

            oObj.ClassID = Class;
            if (Dynamic)
            {
                Cimplicity.PointSet(@"IMPORT.PROGRESS", $"Start Seq: {s.ID} for: {s.Plc.ObjRoot}");
            }

            oObj.ID = s.ID;
            oObj.Attributes.Set("$DESCRIPTION", s.Station);
            oObj.Attributes.Set("$DEVICE_ID", s.Plc.DEVICE_ID);
            oObj.Attributes.Set("$RESOURCE_ID", $"ZONE{s.Plc.ID.ToString("00")}");
            //oObj.Attributes.Set("AL", this.SafetyAreas[s.msObj].ALARM_CLASS);
            oObj.Attributes.Set("SA", this.SafetyAreas[s.msObj].SA);
            oObj.Attributes.Set("PLC", s.Plc.Tag);
            oObj.Attributes.Set("SEQ", s.SeqNum.ToString());

            oObj.Routing.AddAll();

            oProject.Objects.Save(oObj, Dynamic);

            oTableLG_BAD_PART.AddLoggedPoint(s.ID + ".BAD_PART");
            oTableLG_CYCLE_TIME.AddLoggedPoint(s.ID + ".CYCLE_TIME");
            oTableLG_FAULT_CODE.AddLoggedPoint(s.ID + ".FAULT_CODE");
            oTableLG_GOOD_PART.AddLoggedPoint(s.ID + ".GOOD_PART");
            oTableLG_PART_TYPE.AddLoggedPoint(s.ID + ".PART_TYPE");
            oTableLG_REASON_CODE.AddLoggedPoint(s.ID + ".REASON_CODE");
            oTableLG_STATUS.AddLoggedPoint(s.ID + ".STATUS");

            if (Dynamic)
            {
                Cimplicity.PointSet(@"IMPORT.PROGRESS", $"End Seq: {s.ID} for: {s.Plc.ObjRoot}");
                Cimplicity.PointSet(@"IMPORT.NEW_SEQ_NAME", s.ID);
            }

            Plc      p  = AddPLC(s.Plc.Tag, s.Plc.DEVICE_ID);
            Sequence s1 = AddSequence(this.Plcs[s.Plc.Tag], s.SeqNum, $"ZONE0{s.Plc.ID.ToString()}", s.MSNum, s.Station);

            NewSeq?.Invoke(s1.Plc, s);
        }
예제 #4
0
        public void GetSeqences()
        {
            Plcs.Clear();

            foreach (CimObjectInstance o in oProject.Objects)
            {
                if (o.ClassID == Class)
                {
                    string plc = o.Attributes["PLC"].Value;
                    int    ms  = int.Parse(o.Attributes["SA"].Value.Substring(2, 2));
                    //string MS = o.Attributes["AL"].Value;
                    int    seq    = int.Parse(o.Attributes["SEQ"].Value);
                    string desc   = o.Attributes["$DESCRIPTION"].Value;
                    string device = o.Attributes["$DEVICE_ID"].Value;
                    string zone   = o.Attributes["$RESOURCE_ID"].Value;

                    Plc p = AddPLC(plc, device);

                    Sequence s = AddSequence(p, seq, zone, ms, desc);
                    NewSeq?.Invoke(p, s);
                }
            }
        }
예제 #5
0
        private void GetSeqences(Plc plc)
        {
            Array ItemIDs  = Array.CreateInstance(typeof(string), 61);
            Array ClntHndl = Array.CreateInstance(typeof(int), 61);

            Array  SvrHndl;
            Array  SvrErr;
            Array  Values;
            object qual = new object();
            object TS   = new object();
            string tag  = "";

            try
            {
                for (int i = 1; i <= 30; i++)
                {
                    switch (type)
                    {
                    case OPCType.Kepware:

                        tag = $"{plc.Tag}.ZZSEQ[{(i).ToString()}].SA";
                        ItemIDs.SetValue(tag, i);
                        tag = $"{plc.Tag}.ZZSEQ[{(i).ToString()}].DESC.DATA/8";
                        ItemIDs.SetValue(tag, i + 30);
                        break;

                    case OPCType.Matrikon:
                        tag = $"{plc.Tag}:PLC:SCADA_CONFIG:ZZSEQ[{(i).ToString()}].SEQ.VALUE";
                        ItemIDs.SetValue(tag, i);
                        //"A3_01_R01_S01: PLC: SCADA_CONFIG: ZZMISSEQ[1].DESC.VALUE"
                        tag = $"{plc.Tag}:PLC:SCADA_CONFIG:ZZSEQ[{(i).ToString()}].DESC.VALUE";
                        ItemIDs.SetValue(tag, i + 30);
                        break;
                    }

                    ClntHndl.SetValue(i, i);
                    ClntHndl.SetValue(i + 30, i + 30);
                }

                oGroup.OPCItems.AddItems(60, ref ItemIDs, ref ClntHndl, out SvrHndl, out SvrErr);
                if (this.Sync)
                {
                    oGroup.SyncRead((short)OPCAutomation.OPCDataSource.OPCDevice, 60, ref SvrHndl, out Values, out SvrErr, out qual, out TS);

                    string zone = "ZONE" + plc.ID.ToString("00");

                    for (int j = 1; j <= 30; j++)
                    {
                        double ms   = double.Parse(Values.GetValue(j).ToString());
                        string desc = Values.GetValue(j + 30).ToString();
                        if (ms > 0)
                        {
                            Sequence s = plc.AddSequence(j, zone, ms, desc);
                            NewSeq?.Invoke(plc, s);
                        }
                    }

                    oGroup.OPCItems.Remove(60, ref SvrHndl, out SvrErr);
                }
                else
                {
                    int ic;
                    oGroup.AsyncRead(60, ref SvrHndl, out SvrErr, plc.ID, out ic);
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.ToString()); }
        }