Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="DBNumber">DB Number</param>
        /// <param name="Buffer">Destination buffer</param>
        /// <param name="SizeRead">How many bytes were read</param>
        /// <returns></returns>

        public int DBGet(int DBNumber, byte[] Buffer, IntByRef SizeRead)
        {
            S7BlockInfo Block = new S7BlockInfo();

            // Query the DB Length
            LastError = GetAgBlockInfo(S7.Block_DB, DBNumber, Block);
            if (LastError == 0)
            {
                int SizeToRead = Block.MC7Size();
                // Checks the room
                if (SizeToRead <= Buffer.Length)
                {
                    LastError = ReadArea(S7.S7AreaDB, DBNumber, 0, SizeToRead, Buffer);
                    if (LastError == 0)
                    {
                        SizeRead.Value = SizeToRead;
                    }
                }
                else
                {
                    LastError = errS7BufferTooSmall;
                }
            }
            return(LastError);
        }
Ejemplo n.º 2
0
        public int GetPlcStatus(IntByRef Status)
        {
            int Length;

            LastError = 0;
            SendPacket(S7_GET_STAT);
            if (LastError == 0)
            {
                Length = RecvIsoPacket();
                if (Length > 30) // the minimum expected
                {
                    if (S7.GetWordAt(PDU, 27) == 0)
                    {
                        switch (PDU[44])
                        {
                        case S7.S7CpuStatusUnknown:
                        case S7.S7CpuStatusRun:
                        case S7.S7CpuStatusStop:
                            Status.Value = PDU[44];
                            break;

                        default:
                            // Since RUN status is always 0x08 for all CPUs and CPs, STOP status
                            // sometime can be coded as 0x03 (especially for old cpu...)
                            Status.Value = S7.S7CpuStatusStop;
                            break;
                        }
                    }
                    else
                    {
                        LastError = errS7FunctionError;
                    }
                }
                else
                {
                    LastError = errS7InvalidPDU;
                }
            }
            return(LastError);
        }