Ejemplo n.º 1
0
        public static string GetSlaveStateDescription(IntPtr context, IEnumerable <SlaveInfo> slaves)
        {
            var slaveStateDescription = new StringBuilder();

            foreach (var slave in slaves)
            {
                var slaveIndex = Convert.ToUInt16(slaves.ToList().IndexOf(slave) + 1);

                // Since the registers 0x092c and 0x0932 cannot be read always, the value will be reset before
                var systemTimeDifference   = int.MaxValue;
                var speedCounterDifference = ushort.MaxValue;

                ushort requestedState = 0;
                ushort actualState    = 0;
                ushort alStatusCode   = 0;
                ushort outputPdoCount = 0;
                ushort inputPdoCount  = 0;

                var returnValue = EcHL.ReadSlaveState(context, slaveIndex, ref requestedState, ref actualState, ref alStatusCode, ref systemTimeDifference, ref speedCounterDifference, ref outputPdoCount, ref inputPdoCount);

                // ActualState <> RequestedState OrElse AlStatusCode > 0x0 Then
                if (true)
                {
                    if (returnValue < 0)
                    {
                        slaveStateDescription.AppendLine($"-- Error reading data ({slave.DynamicData.Name}) --");
                    }
                    else
                    {
                        string hasCompleteAccess = slave.Esi.Mailbox?.CoE?.CompleteAccess == true
                            ? " True"
                            : "False";

                        slaveStateDescription.AppendLine($"Slave {slaveIndex,3} | CA: {hasCompleteAccess} | Req-State: 0x{requestedState:X4} | Act-State: 0x{actualState:X4} | AL-Status: 0x{alStatusCode:X4} | Sys-Time Diff: 0x{systemTimeDifference:X8} | Speed Counter Diff: 0x{speedCounterDifference:X4} | #Pdo out: {outputPdoCount} | #Pdo in: {inputPdoCount} | ({slave.DynamicData.Name})");
                    }
                }
            }

            return(slaveStateDescription.ToString());
        }