예제 #1
0
        public UCMM_RR_Packet(CIPServiceCodes Service, bool IsRequest, byte[] Path, byte[] Data)
        {
            this.Service = (byte)Service;
            if (!IsRequest)
            {
                this.Service = (byte)(this.Service | 0x80);
            }

            this.Path = Path;
            this.Data = Data;
        }
예제 #2
0
        protected EnIPNetworkStatus WriteDataToNetwork(byte[] Path, CIPServiceCodes Service)
        {
            int Offset = 0;
            int Lenght = 0;

            byte[] packet;

            Status = RemoteDevice.SetClassInstanceAttribut_Data(Path, Service, RawData, ref Offset, ref Lenght, out packet);

            return(Status);
        }
예제 #3
0
        protected EnIPNetworkStatus ReadDataFromNetwork(byte[] Path, CIPServiceCodes Service)
        {
            int Offset = 0;
            int Lenght = 0;

            byte[] packet;
            Status = RemoteDevice.GetClassInstanceAttribut_Data(Path, Service, ref Offset, ref Lenght, out packet);

            if (Status == EnIPNetworkStatus.OnLine)
            {
                RawData = new byte[Lenght - Offset];
                Array.Copy(packet, Offset, RawData, 0, Lenght - Offset);
            }
            return(Status);
        }
예제 #4
0
        public bool IsService(CIPServiceCodes Service)
        {
            byte s = (byte)(this.Service & 0x7F);

            if (s == (byte)Service)
            {
                return(true);
            }

            if ((this.Service > 0x80) && (s == (byte)CIPServiceCodes.UnconnectedSend))
            {
                return(true);
            }

            return(false);
        }
예제 #5
0
 public EnIPNetworkStatus GetClassInstanceAttribut_Data(byte[] ClassDataPath, CIPServiceCodes Service, ref int Offset, ref int Lenght, out byte[] packet)
 {
     return(SendUCMM_RR_Packet(ClassDataPath, Service, null, ref Offset, ref Lenght, out packet));
 }
예제 #6
0
        public EnIPNetworkStatus SendUCMM_RR_Packet(byte[] DataPath, CIPServiceCodes Service, byte[] data, ref int Offset, ref int Lenght, out byte[] packet)
        {
            packet = this.packet;

            if (autoRegisterSession)
            {
                RegisterSession();
            }
            if (SessionHandle == 0)
            {
                return(EnIPNetworkStatus.OffLine);
            }

            try
            {
                UCMM_RR_Packet       m = new UCMM_RR_Packet(Service, true, DataPath, data);
                Encapsulation_Packet p = new Encapsulation_Packet(EncapsulationCommands.SendRRData, SessionHandle, m.toByteArray());

                Encapsulation_Packet rep;
                Offset = 0;

                lock (LockTransaction)
                    Lenght = Tcpclient.SendReceive(p, out rep, out Offset, ref packet);

                String ErrorMsg = "TCP mistake";

                if (Lenght > 24)
                {
                    if ((rep.IsOK) && (rep.Command == EncapsulationCommands.SendRRData))
                    {
                        m = new UCMM_RR_Packet(packet, ref Offset, Lenght);
                        if ((m.IsOK) && (m.IsService(Service)))
                        {
                            // all is OK, and Offset is ready set at the beginning of data[]
                            return(EnIPNetworkStatus.OnLine);
                        }
                        else
                        {
                            ErrorMsg = m.GeneralStatus.ToString();
                        }
                    }
                    else
                    {
                        ErrorMsg = rep.Status.ToString();
                    }
                }

                Trace.WriteLine(Service.ToString() + " : " + ErrorMsg + " - Node " + EnIPPath.GetPath(DataPath) + " - Endpoint " + ep.ToString());

                if (ErrorMsg == "TCP mistake")
                {
                    return(EnIPNetworkStatus.OffLine);
                }

                if (Service == CIPServiceCodes.SetAttributeSingle)
                {
                    return(EnIPNetworkStatus.OnLineWriteRejected);
                }
                else
                {
                    return(EnIPNetworkStatus.OnLineReadRejected);
                }
            }
            catch
            {
                Trace.TraceWarning("Error while sending reques to endpoint " + ep.ToString());
                return(EnIPNetworkStatus.OffLine);
            }
        }