/// <summary>
        /// Attempts to retrieve the Psu Serial Number. This method
        /// calls down to the Chassis Manager with SendReceive
        /// </summary>
        private PsuSerialNumberPacket GetPsuSerialNumber(byte psuId)
        {
            PsuSerialNumberPacket returnPacket = new PsuSerialNumberPacket();

            returnPacket.CompletionCode = CompletionCode.UnspecifiedError;
            returnPacket.SerialNumber   = "";

            try
            {
                PsuSerialResponse myResponse = new PsuSerialResponse();
                myResponse = (PsuSerialResponse)this.SendReceive(this.PsuDeviceType, this.PsuId, new PsuRequest((byte)PmBusCommand.MFR_SERIAL, (byte)PmBusResponseLength.MFR_SERIAL), typeof(PsuSerialResponse));

                // check for completion code
                if (myResponse.CompletionCode != 0)
                {
                    returnPacket.CompletionCode = (CompletionCode)myResponse.CompletionCode;
                }
                else
                {
                    returnPacket.CompletionCode = CompletionCode.Success;
                    if (myResponse.PsuSerialNumber != null)
                    {
                        byte[] inSerialNumber  = myResponse.PsuSerialNumber;
                        byte[] outSerialNumber = null;
                        PmBus.PsuSerialNumberParser(ref inSerialNumber, out outSerialNumber);
                        returnPacket.SerialNumber = System.BitConverter.ToString(outSerialNumber, 0);
                    }
                    else
                    {
                        returnPacket.SerialNumber = "";
                    }
                }
            }
            catch (System.Exception ex)
            {
                returnPacket.CompletionCode = CompletionCode.UnspecifiedError;
                returnPacket.SerialNumber   = "";
                Tracer.WriteError(this.PsuId, DeviceType.Psu, ex);
            }

            return(returnPacket);
        }
        /// <summary>
        /// Attempts to retrieve the Psu Serial Number. This method
        /// calls down to the Chassis Manager with SendReceive
        /// </summary>
        private PsuSerialNumberPacket GetPsuSerialNumber(byte psuId)
        {
            PsuSerialNumberPacket returnPacket = new PsuSerialNumberPacket();
            returnPacket.CompletionCode = CompletionCode.UnspecifiedError;
            returnPacket.SerialNumber = "";

            try
            {
                PsuSerialResponse myResponse = new PsuSerialResponse();
                myResponse = (PsuSerialResponse)this.SendReceive(this.PsuDeviceType, this.PsuId, new PsuRequest((byte)PmBusCommand.MFR_SERIAL,(byte)PmBusResponseLength.MFR_SERIAL), typeof(PsuSerialResponse));

                // check for completion code
                if (myResponse.CompletionCode != 0)
                {
                    returnPacket.CompletionCode = (CompletionCode)myResponse.CompletionCode;
                }
                else
                {
                    returnPacket.CompletionCode = CompletionCode.Success;
                    if (myResponse.PsuSerialNumber != null)
                    {
                        byte[] inSerialNumber = myResponse.PsuSerialNumber;
                        byte[] outSerialNumber = null;
                        PmBus.PsuSerialNumberParser(ref inSerialNumber, out outSerialNumber);
                        returnPacket.SerialNumber = System.BitConverter.ToString(outSerialNumber, 0);
                    }
                    else
                    {
                        returnPacket.SerialNumber = "";
                    }
                }
            }
            catch (System.Exception ex)
            {
                returnPacket.CompletionCode = CompletionCode.UnspecifiedError;
                returnPacket.SerialNumber = "";
                Tracer.WriteError(this.PsuId, DeviceType.Psu, ex);
            }

            return returnPacket;
        }
        /// <summary>
        /// Standalone Command to get Power Consumption Info,  
        /// used with Data Center Power Monitoring integration
        /// </summary>
        private List<PsuInfo> GetPsuInfo()
        {
            // Create Response Collection
            List<PsuInfo> response = new List<PsuInfo>(ConfigLoaded.NumPsus);

            try
            {
                for (int psuId = 0; psuId < ConfigLoaded.NumPsus; psuId++)
                {
                    // Step 1: Create PsuInfo Response object
                    Contracts.PsuInfo psuInfo = new Contracts.PsuInfo();
                    psuInfo.id = (uint)(psuId + 1);

                    // Add object to list.
                    response.Add(psuInfo);

                    // If PSU firmware update in progress, do not read status
                    if (ChassisState.PsuFwUpdateInProgress[psuId])
                    {
                        response[psuId].completionCode = Contracts.CompletionCode.PSUFirmwareUpdateInProgress;
                        response[psuId].statusDescription = "PSU firmware update in progress";
                        continue;
                    }

                    lock (ChassisState.psuLock[psuId])
                    {
                        // subsequent commands are permitted to change upon failure.
                        response[psuId].completionCode = Contracts.CompletionCode.Success;

                        // Step 2:  Get Psu Power
                        PsuPowerPacket psuPower = ChassisState.Psu[psuId].GetPsuPower();
                        if (psuPower.CompletionCode != CompletionCode.Success)
                        {
                            Tracer.WriteWarning("GetPsuPower failed for psu: " + psuInfo.id);
                            response[psuId].powerOut = 0;
                            response[psuId].completionCode = ChassisManagerUtil.GetContractsCompletionCodeMapping((byte)psuPower.CompletionCode);
                            response[psuId].statusDescription = psuPower.CompletionCode.ToString();
                        }
                        else
                        {
                            response[psuId].powerOut = (uint)psuPower.PsuPower;
                        }

                        // Step 3: Get Psu Serial Number
                        PsuSerialNumberPacket serialNumberPacket = new PsuSerialNumberPacket();
                        serialNumberPacket = ChassisState.Psu[psuId].GetPsuSerialNumber();
                        if (serialNumberPacket.CompletionCode != CompletionCode.Success)
                        {
                            Tracer.WriteWarning("GetPsuSerialNumber failed for psu: " + psuInfo.id);
                            response[psuId].serialNumber = string.Empty;
                            response[psuId].completionCode = ChassisManagerUtil.GetContractsCompletionCodeMapping((byte)serialNumberPacket.CompletionCode);
                            response[psuId].statusDescription = serialNumberPacket.CompletionCode.ToString();
                        }
                        else
                        {
                            response[psuId].serialNumber = serialNumberPacket.SerialNumber;
                        }

                        // Step 4: Get Psu Status
                        PsuStatusPacket psuStatusPacket = new PsuStatusPacket();
                        psuStatusPacket = ChassisState.Psu[psuId].GetPsuStatus();
                        if (psuStatusPacket.CompletionCode != CompletionCode.Success)
                        {
                            Tracer.WriteWarning("GetPsuStatus failed for psu " + psuInfo.id);
                            response[psuId].state = PowerState.NA;
                            response[psuId].completionCode = ChassisManagerUtil.GetContractsCompletionCodeMapping((byte)psuStatusPacket.CompletionCode);
                            response[psuId].statusDescription = psuStatusPacket.CompletionCode.ToString();
                        }
                        else
                        {
                            if (psuStatusPacket.PsuStatus == (byte)Contracts.PowerState.OFF)
                            {
                                response[psuId].state = PowerState.OFF;
                            }
                            else if (psuStatusPacket.PsuStatus == (byte)Contracts.PowerState.ON)
                            {
                                response[psuId].state = PowerState.ON;
                            }
                            else
                            {
                                response[psuId].state = PowerState.NA;
                            }
                        }
                    } // lock...
                } // for...
            }
            catch (Exception ex)
            {
                Tracer.WriteError("GetPsuInfo failed with exception: {0}", ex);
            }

            return response;
        }