示例#1
0
        /// <summary>
        /// Gets the MFG string
        /// </summary>
        /// <param name="telnet_connection"></param>
        /// <returns></returns>
        public static string Get_MFGString(TelnetConnection telnet_connection)
        {
            string mfgstr  = null;
            string datain  = "";
            string pattern = "MFG String: (\\S+)";

            TCLI.Wait_For_Prompt(telnet_connection);
            telnet_connection.WriteLine("info");
            Thread.Sleep(500);
            datain = telnet_connection.Read();


            if (datain != null && datain.Length > 0)
            {
                Match match = Regex.Match(datain, pattern);
                if (match.Groups.Count != 2)
                {
                    string msg = string.Format("Unable to parse info MFG String.  Output was:{0}", datain);
                    throw new Exception(msg);
                }
                mfgstr = match.Groups[1].Value;
            }
            else
            {
                string msg = string.Format("No data received after \"Info\" command");
                throw new Exception(msg);
            }

            return(mfgstr);
        }
示例#2
0
        /// <summary>
        /// Telnets to the Ember and prints custom commands
        /// Parses command list and tries to find the pload or pinfo comand prefix
        /// It is usually "cs5480_" in the case of SPDI or "cs5490_" in the case of UART comunications
        /// Exception is thrown if not pload command is found after typing "cu"
        /// </summary>
        /// <returns></returns>
        public static string Get_Custom_Command_Prefix(TelnetConnection telnet_connection)
        {
            string cmd_pre = null;

            int    try_count = 0;
            string data      = "";

            TCLI.Wait_For_Prompt(telnet_connection);
            while (true)
            {
                telnet_connection.WriteLine("cu");
                data += telnet_connection.Read();
                if (data.Contains("pload"))
                {
                    break;
                }
                if (try_count++ > 3)
                {
                    break;
                }
            }

            string msg = "";

            if (!data.Contains("pload"))
            {
                msg = string.Format("Unable to find pload command from custom command output list from Ember.  Output was: {0}", data);
                throw new Exception(msg);
            }

            string pattern = @"(cs[0-9]{4})_pload\r\n";
            Match  match   = Regex.Match(data, pattern);

            if (match.Groups.Count != 2)
            {
                msg = string.Format("Unable to parse custom command list for pload.  Output was:{0}", data);
                throw new Exception(msg);
            }

            cmd_pre = match.Groups[1].Value;
            return(cmd_pre);
        }
示例#3
0
        /// <summary>
        /// Gets the EUI
        /// </summary>
        /// <param name="telnet_connection"></param>
        /// <returns></returns>
        public static string Get_EUI(TelnetConnection telnet_connection)
        {
            string eui       = null;
            int    try_count = 0;
            string datain    = "";
            string pattern   = Regex.Escape("node [(>)") + "([0-9,A-F]{16})" + Regex.Escape("]");

            TCLI.Wait_For_Prompt(telnet_connection);
            while (true)
            {
                telnet_connection.WriteLine("info");
                Thread.Sleep(500);
                datain = telnet_connection.Read();
                if (datain != null && datain.Length > 0 && Regex.Match(datain, pattern).Groups.Count == 2)
                {
                    break;
                }
                if (try_count++ > 3)
                {
                    break;
                }
            }


            if (datain != null && datain.Length > 0)
            {
                Match match = Regex.Match(datain, pattern);
                if (match.Groups.Count != 2)
                {
                    string msg = string.Format("Unable to parse info EUI.  Output was:{0}", datain);
                    throw new Exception(msg);
                }
                eui = match.Groups[1].Value;
            }
            else
            {
                string msg = string.Format("No data received after \"Info\" command");
                throw new Exception(msg);
            }

            return(eui);
        }
        private void setCalibrationTokensText(TCLI.Tokens calibration_tokens)
        {
            if (this.InvokeRequired)
            {
                setCalibrationTokensTextCallback d = new setCalibrationTokensTextCallback(setCalibrationTokensText);
                this.Invoke(d, new object[] { calibration_tokens });
            }
            else
            {
                this.labelVFactor.Text = string.Format("Voltage Factor: {0}", calibration_tokens.VoltageFactor);
                this.labelIFactor.Text = string.Format("Current Factor: {0}", calibration_tokens.CurrentFactor);
                this.labelVGain.Text = string.Format("VGain Token: 0x{0:X08}", calibration_tokens.VoltageGainToken);
                this.labelIGain.Text = string.Format("IGain Token: 0x{0:X08}", calibration_tokens.CurrentGainToken);

                string eui = TCLI.Get_EUI(_telnet_connection);
                this.labelEUI.Text = string.Format("EUI: {0}", eui);
            }
        }
示例#5
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);
        }