示例#1
0
        /// <summary>
        /// Sends a pload command and returns the current and voltage values
        /// </summary>
        /// <param name="telnet_connection">Already opened Telnet connection to the Ember</param>
        /// <param name="board_type">What board are we using</param>
        /// <returns>Current/Voltage structure values</returns>
        public static Current_Voltage Parse_Pload_Registers(
            TelnetConnection telnet_connection, string cmd_prefix, double voltage_ac_reference, double current_ac_reference)
        {
            string rawCurrentPattern = "Raw IRMS: ([0-9,A-F]{8})";
            string rawVoltagePattern = "Raw VRMS: ([0-9,A-F]{8})";
            double current_cs        = 0.0;
            double voltage_cs        = 0.0;

            TCLI.Wait_For_Prompt(telnet_connection);

            string cmd = string.Format("cu {0}_pload", cmd_prefix);

            telnet_connection.WriteLine(cmd);
            Thread.Sleep(500);

            string datain = telnet_connection.Read();

            Trace.WriteLine(datain);

            TCLI.Wait_For_Prompt(telnet_connection);

            string msg;

            if (datain != null && datain.Length > 0)
            {
                Match on_off_match = Regex.Match(datain, "Changing OnOff .*");
                if (on_off_match.Success)
                {
                    msg = on_off_match.Value;
                }

                Match match = Regex.Match(datain, rawCurrentPattern);
                if (match.Groups.Count != 2)
                {
                    msg = string.Format("Unable to parse pinfo for current.  Output was:{0}", datain);
                    throw new Exception(msg);
                }

                string current_hexstr = match.Groups[1].Value;
                int    current_int    = Convert.ToInt32(current_hexstr, 16);
                current_cs = RegHex_ToDouble(current_int);
                current_cs = current_cs * current_ac_reference / 0.6;

                voltage_cs = 0.0;
                match      = Regex.Match(datain, rawVoltagePattern);
                if (match.Groups.Count != 2)
                {
                    msg = string.Format("Unable to parse pinfo for voltage.  Output was:{0}", datain);
                    throw new Exception(msg);
                }

                string voltage_hexstr = match.Groups[1].Value;
                int    volatge_int    = Convert.ToInt32(voltage_hexstr, 16);
                voltage_cs = RegHex_ToDouble(volatge_int);
                voltage_cs = voltage_cs * voltage_ac_reference / 0.6;
            }
            else
            {
                msg = string.Format("No data received after \"{0}\" command", cmd);
                throw new Exception(msg);
            }

            Current_Voltage current_voltage = new Current_Voltage(i: current_cs, v: voltage_cs);

            return(current_voltage);
        }
示例#2
0
        /// <summary>
        /// Sends a pload command and returns the current and voltage values
        /// </summary>
        /// <param name="telnet_connection">Already opened Telnet connection to the Ember</param>
        /// <param name="board_type">What board are we using</param>
        /// <returns>Current/Voltage structure values</returns>
        public static Current_Voltage Parse_Pload_Registers(
            TelnetConnection telnet_connection, string cmd_prefix, double voltage_ac_reference, double current_ac_reference)
        {
            string rawCurrentPattern = "Raw IRMS: ([0-9,A-F]{8})";
            string rawVoltagePattern = "Raw VRMS: ([0-9,A-F]{8})";
            double current_cs = 0.0;
            double voltage_cs = 0.0;

            TCLI.Wait_For_Prompt(telnet_connection);

            string cmd = string.Format("cu {0}_pload", cmd_prefix);
            telnet_connection.WriteLine(cmd);
            Thread.Sleep(500);

            string datain = telnet_connection.Read();
            Trace.WriteLine(datain);

            TCLI.Wait_For_Prompt(telnet_connection);

            string msg;

            if (datain != null && datain.Length > 0)
            {
                Match on_off_match = Regex.Match(datain, "Changing OnOff .*");
                if (on_off_match.Success)
                {
                    msg = on_off_match.Value;
                }

                Match match = Regex.Match(datain, rawCurrentPattern);
                if (match.Groups.Count != 2)
                {
                    msg = string.Format("Unable to parse pinfo for current.  Output was:{0}", datain);
                    throw new Exception(msg);
                }

                string current_hexstr = match.Groups[1].Value;
                int current_int = Convert.ToInt32(current_hexstr, 16);
                current_cs = RegHex_ToDouble(current_int);
                current_cs = current_cs * current_ac_reference / 0.6;

                voltage_cs = 0.0;
                match = Regex.Match(datain, rawVoltagePattern);
                if (match.Groups.Count != 2)
                {
                    msg = string.Format("Unable to parse pinfo for voltage.  Output was:{0}", datain);
                    throw new Exception(msg);
                }

                string voltage_hexstr = match.Groups[1].Value;
                int volatge_int = Convert.ToInt32(voltage_hexstr, 16);
                voltage_cs = RegHex_ToDouble(volatge_int);
                voltage_cs = voltage_cs * voltage_ac_reference / 0.6;

            }
            else
            {
                msg = string.Format("No data received after \"{0}\" command", cmd);
                throw new Exception(msg);
            }

            Current_Voltage current_voltage = new Current_Voltage(i: current_cs, v: voltage_cs);
            return current_voltage;
        }