Beispiel #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);
        }
Beispiel #2
0
        //-------------------------------------------------------------------------------------------------//

        private int FindRegisterMapping(ModbusRegs_InputRegs_RO register)
        {
            int index = -1;

            for (int i = 0; i < RegisterMap_InputRegs.Length; i++)
            {
                if ((int)register == RegisterMap_InputRegs[i].register)
                {
                    index = i;
                    break;
                }
            }

            return(index);
        }
        //=================================================================================================//
        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;
        }
        //-------------------------------------------------------------------------------------------------//
        private int FindRegisterMapping(ModbusRegs_InputRegs_RO register)
        {
            int index = -1;

            for (int i = 0; i < RegisterMap_InputRegs.Length; i++)
            {
                if ((int)register == RegisterMap_InputRegs[i].register)
                {
                    index = i;
                    break;
                }
            }

            return index;
        }