Exemple #1
0
        //=================================================================================================//

        private bool GetRegisterValue(ModbusRegs_InputRegs_RO register, ref double value, ref string units)
        {
            bool success;

            //
            // Find the register mapping
            //
            int index = this.FindRegisterMapping(register);
            RegisterMapping_InputRegs mapping = RegisterMap_InputRegs[index];

            //
            // The register map is contiguous so they can be read with one command
            //
            float[] values = null;
            if ((success = this.ReadInputRegisters(RegisterMap_InputRegs[0].register, ref values, RegisterMap_InputRegs.Length)) == true)
            {
                //
                // Get the value and the units
                //
                value = values[index];
                units = mapping.units;
            }

            return(success);
        }
Exemple #2
0
        //-------------------------------------------------------------------------------------------------//

        public bool ReadRegisters()
        {
            const string STRLOG_MethodName = "ReadAllRegisters";

            Logfile.WriteCalled(this.logLevel, STRLOG_ClassName, STRLOG_MethodName);

            bool success = false;

            this.lastError = null;
            string logMessage;

            try
            {
                //
                // The register map is contiguous so they can be read with one command
                //
                ushort[] values = null;
                if (this.ReadInputRegisters(RegisterMap_InputRegs[0].register, ref values, RegisterMap_InputRegs.Length) == true)
                {
                    for (int i = 0; i < RegisterMap_InputRegs.Length; i++)
                    {
                        RegisterMapping_InputRegs mapping = RegisterMap_InputRegs[i];
                        logMessage = String.Format("[{0,-5:d}]: ", mapping.register);

                        //
                        // Convert the register value to eng. units
                        //
                        double engValue = this.ConvertRawToEng(values[i], mapping.raw, mapping.eng);
                        logMessage += String.Format("Value: {0,-6}  Eng: {1,6:f01} {2,-5} {3}", values[i], engValue, mapping.units, mapping.comment);
                        Logfile.Write(logMessage);
                        Trace.WriteLine(logMessage);
                    }
                }
                Trace.WriteLine(String.Empty);

                success = true;
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
                Trace.WriteLine(ex.Message);
                this.lastError = ex.Message;
            }

            logMessage = STRLOG_Success + success.ToString();

            Logfile.WriteCompleted(this.logLevel, STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return(success);
        }
Exemple #3
0
        //-------------------------------------------------------------------------------------------------//

        public bool GetSyncMainsPhase(ref double degrees, ref string units)
        {
            bool success;

            //
            // Find the register mapping
            //
            int index = this.FindRegisterMapping(ModbusRegs_InputRegs_RO.UBusBarUGenPhaseL1);
            RegisterMapping_InputRegs mapping = RegisterMap_InputRegs[index];

            //
            // Read the register
            //
            ushort value = 0;

            if ((success = this.ReadInputRegister(mapping.register, ref value)) == true)
            {
                // Convert the register value to eng. units
                degrees = this.ConvertRawToEng(value, mapping.raw, mapping.eng);
                units   = mapping.units;
            }

            return(success);
        }
Exemple #4
0
        //-------------------------------------------------------------------------------------------------//

        public bool GetSyncFrequency(ref double frequency, ref string units)
        {
            bool success;

            //
            // Find the register mapping
            //
            int index = this.FindRegisterMapping(ModbusRegs_InputRegs_RO.GenVoltageFreqL1);
            RegisterMapping_InputRegs mapping = RegisterMap_InputRegs[index];

            //
            // Read the register
            //
            ushort value = 0;

            if ((success = this.ReadInputRegister(mapping.register, ref value)) == true)
            {
                // Convert the register value to eng. units
                frequency = this.ConvertRawToEng(value, mapping.raw, mapping.eng);
                units     = mapping.units;
            }

            return(success);
        }
Exemple #5
0
        //-------------------------------------------------------------------------------------------------//

        public bool GetMainsVoltage(ref double voltage, ref string units)
        {
            bool success;

            //
            // Find the register mapping
            //
            int index = this.FindRegisterMapping(ModbusRegs_InputRegs_RO.BusbarVoltageL1L2);
            RegisterMapping_InputRegs mapping = RegisterMap_InputRegs[index];

            //
            // Read the register
            //
            ushort value = 0;

            if ((success = this.ReadInputRegister(mapping.register, ref value)) == true)
            {
                // Convert the register value to eng. units
                voltage = this.ConvertRawToEng(value, mapping.raw, mapping.eng);
                units   = mapping.units;
            }

            return(success);
        }