Beispiel #1
0
        /// <summary>
        /// Sends a pload command and returns the current and voltage values
        /// </summary>
        /// <param name="tc">Telnet connection to the EMber</param>
        /// <param name="board_type">What board are we using</param>
        /// <returns>Current/Voltage structure values</returns>
        static CS_Current_Voltage ember_parse_pinfo_registers(TelnetConnection tc)
        {
            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;

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

            traceLog(string.Format("Send cmd: {0}", cmd));
            tc.WriteLine(cmd);
            Thread.Sleep(500);
            string datain = tc.Read();

            Trace.WriteLine(datain);
            string msg;

            if (datain.Length > 0)
            {
                //traceLog(string.Format("Data received: {0}", datain)); // It gets log with "p_ember_isachan_OutputDataReceived"

                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_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_reference / 0.6;
            }
            else
            {
                msg = string.Format("No data recieved from telnet");
                throw new Exception(msg);
            }

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

            return(current_voltage);
        }
Beispiel #2
0
        static int Main(string[] args)
        {
            int rc = 0;

            Stream outResultsFile = File.Create("output.txt");
            var    textListener   = new TextWriterTraceListener(outResultsFile);

            Trace.Listeners.Add(textListener);
            string datafile_name = "power_data.txt";

            try
            {
                if (File.Exists(datafile_name))
                {
                    File.Delete(datafile_name);
                }

                kill_em3xx_load();

                openEmberISAChannels();

                TelnetConnection telnet_connection = new TelnetConnection("localhost", 4900);

                CS_Current_Voltage cv  = ember_parse_pinfo_registers(telnet_connection);
                string             msg = string.Format("Cirrus I = {0:F8}, V = {1:F8}, P = {2:F8}", cv.Current, cv.Voltage, cv.Current * cv.Voltage);
                traceLog(msg);

                msg = string.Format("{0:F8},{1:F8},{2:F8}", cv.Voltage, cv.Current, cv.Current * cv.Voltage);
                Console.WriteLine(msg);

                System.IO.StreamWriter file = new System.IO.StreamWriter(datafile_name);
                file.Write(msg);
                file.Close();

                closeEmberISAChannels();
            }
            catch (Exception ex)
            {
                rc = -1;
                traceLog(ex.Message);
                Console.WriteLine(ex.Message);
            }

            Trace.Flush();
            Trace.Close();

            return(rc);
        }
Beispiel #3
0
        /// <summary>
        /// Sends a pload command and returns the current and voltage values
        /// </summary>
        /// <param name="tc">Telnet connection to the EMber</param>
        /// <param name="board_type">What board are we using</param>
        /// <returns>Current/Voltage structure values</returns>
        static CS_Current_Voltage ember_parse_pinfo_registers(TelnetConnection tc)
        {
            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;

            string cmd = string.Format("cu {0}_pload", _cmd_prefix);
            traceLog(string.Format("Send cmd: {0}", cmd));
            tc.WriteLine(cmd);
            Thread.Sleep(500);
            string datain = tc.Read();
            Trace.WriteLine(datain);
            string msg;
            if (datain.Length > 0)
            {
                //traceLog(string.Format("Data received: {0}", datain)); // It gets log with "p_ember_isachan_OutputDataReceived"

                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_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_reference / 0.6;

            }
            else
            {
                msg = string.Format("No data recieved from telnet");
                throw new Exception(msg);
            }

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