public void Class1AttributUnEnrolment(EnIPAttribut att)
 {
     if (UdpListener != null)
     {
         UdpListener.ItemMessageReceived -= new ItemMessageReceivedHandler(att.On_ItemMessageReceived);
     }
 }
        public EnIPNetworkStatus ForwardOpen(EnIPAttribut Config, EnIPAttribut O2T, EnIPAttribut T2O, out ForwardClose_Packet ClosePacket, ForwardOpen_Config conf, bool WriteConfig = false)
        {
            ClosePacket = null;

            byte[] DataPath = GetForwardOpenPath(Config, O2T, T2O);

            if ((WriteConfig == true) && (Config != null)) // Add data segment
            {
                DataPath = EnIPPath.AddDataSegment(DataPath, Config.RawData);

                /*
                 * byte[] FinaleFrame = new byte[DataPath.Length + 2 + Config.RawData.Length];
                 * Array.Copy(DataPath, FinaleFrame, DataPath.Length);
                 * FinaleFrame[DataPath.Length] = 0x80;
                 * FinaleFrame[DataPath.Length + 1] = (byte)(Config.RawData.Length / 2); // Certainly the lenght is always even !!!
                 * Array.Copy(Config.RawData, 0, FinaleFrame, DataPath.Length + 2, Config.RawData.Length);
                 * DataPath = FinaleFrame;
                 */
            }

            ForwardOpen_Packet FwPkt = new ForwardOpen_Packet(DataPath, conf);

            int Offset = 0;
            int Lenght = 0;

            byte[] packet;

            EnIPNetworkStatus Status;

            if (FwPkt.IsLargeForwardOpen)
            {
                Status = SendUCMM_RR_Packet(EnIPPath.GetPath(6, 1), CIPServiceCodes.LargeForwardOpen, FwPkt.toByteArray(), ref Offset, ref Lenght, out packet);
            }
            else
            {
                Status = SendUCMM_RR_Packet(EnIPPath.GetPath(6, 1), CIPServiceCodes.ForwardOpen, FwPkt.toByteArray(), ref Offset, ref Lenght, out packet);
            }

            if (Status == EnIPNetworkStatus.OnLine)
            {
                if (O2T != null)
                {
                    O2T.O2T_ConnectionId = BitConverter.ToUInt32(packet, Offset);                          // badly made
                    O2T.SequenceItem     = new SequencedAddressItem(O2T.O2T_ConnectionId, 0, O2T.RawData); // ready to send
                }

                if (T2O != null)
                {
                    T2O.Class1Enrolment();
                    T2O.T2O_ConnectionId = BitConverter.ToUInt32(packet, Offset + 4);
                }
                ClosePacket = new ForwardClose_Packet(FwPkt, T2O);
            }

            return(Status);
        }
        public EnIPNetworkStatus ForwardClose(EnIPAttribut T2O, ForwardClose_Packet ClosePacket)
        {
            int Offset = 0;
            int Lenght = 0;

            byte[] packet;

            if (T2O != null)
            {
                T2O.Class1UnEnrolment();
            }

            return(SendUCMM_RR_Packet(EnIPPath.GetPath(6, 1), CIPServiceCodes.ForwardClose, ClosePacket.toByteArray(), ref Offset, ref Lenght, out packet));
        }
示例#4
0
 public ForwardOpen_Config(EnIPAttribut Output, EnIPAttribut Input, bool InputP2P, uint cycleTime)
 {
     if (Output != null)
     {
         IsO2T        = true;
         O2T_datasize = (ushort)Output.RawData.Length;
         O2T_RPI      = cycleTime; // in microsecond,  here same for the two direction
         O2T_P2P      = true;      // by default in this direction
     }
     if (Input != null)
     {
         IsT2O        = true;
         T2O_datasize = (ushort)Input.RawData.Length;
         T2O_RPI      = cycleTime; // in microsecond, here same for the two direction
         T2O_P2P      = InputP2P;
     }
 }
        // Gives a compressed Path with a list of Attributs
        private byte[] GetForwardOpenPath(EnIPAttribut Config, EnIPAttribut O2T, EnIPAttribut T2O)
        {
            byte[] ConstructDataPath = new byte[20];
            int    offset            = 0;

            ushort?Cid, Aid;

            EnIPAttribut previousAtt = null;

            EnIPAttribut[] Atts = new EnIPAttribut[] { Config, O2T, T2O };

            foreach (EnIPAttribut att in Atts)
            {
                if (att != null)
                {
                    byte[] DataPath;

                    Cid = att.myInstance.myClass.Id;
                    if ((previousAtt != null) && (Cid == previousAtt.myInstance.myClass.Id))
                    {
                        Cid = null;
                    }

                    Aid = ((att.Id == 3) && (att.myInstance.myClass.Id == 4)) ? null : (ushort?)att.Id;

                    DataPath = EnIPPath.GetPath(Cid, att.myInstance.Id, Aid, att != Config);
                    Array.Copy(DataPath, 0, ConstructDataPath, offset, DataPath.Length);
                    offset += DataPath.Length;

                    previousAtt = att;
                }
            }

            byte[] FinalPath = new byte[offset];
            Array.Copy(ConstructDataPath, 0, FinalPath, 0, offset);
            return(FinalPath);

            // return something like  0x20, 0x04, 0x24, 0x80, 0x2C, 0x66, 0x2C, 0x65
        }
示例#6
0
 public ForwardClose_Packet(ForwardOpen_Packet FwOpen, EnIPAttribut T2O)
 {
     OrignalPkt = FwOpen;
     this.T2O   = T2O;
 }
        public EnIPNetworkStatus ForwardOpen(EnIPAttribut Config, EnIPAttribut O2T, EnIPAttribut T2O, out ForwardClose_Packet ClosePacket, uint CycleTime, bool P2P = false, bool WriteConfig = false)
        {
            ForwardOpen_Config conf = new ForwardOpen_Config(O2T, T2O, P2P, CycleTime);

            return(ForwardOpen(Config, O2T, T2O, out ClosePacket, conf, WriteConfig));
        }