Ejemplo n.º 1
0
            static void Main(string[] args)
            {
                Arguments cmdLine_args = new Arguments(args);
                if (cmdLine_args["board"] != null)
                {

                    Console.WriteLine("Board set to '{0}'", cmdLine_args["board"]);
                }

                BoardTypes board_type = BoardTypes.humpback;

                double voltage_low_limit = 0.0;
                double voltage_reference = 0.0;
                double current_reference = 0.0;

                string cmd_prefix;

                switch (board_type)
                {
                    case BoardTypes.humpback:
                        voltage_low_limit = 200;
                        voltage_reference = 240;
                        current_reference = 15;
                        cmd_prefix = "cs5490";
                        break;
                    case BoardTypes.zebrashark:
                        voltage_low_limit = 80;
                        voltage_reference = 120;
                        current_reference = 15;
                        cmd_prefix = "cs5480";
                        break;
                    default:
                        cmd_prefix = "cs5490";
                        voltage_low_limit = 80;
                        voltage_reference = 120;
                        current_reference = 15;
                        break;
                }

                //create a new telnet connection
                TelnetConnection tc = new TelnetConnection("localhost", 4900);
                string datain = tc.Read();

                string msg = patch(board_type, 0x400000, 0x400000);
                Thread.Sleep(2000);
                datain = tc.Read();

                tc.WriteLine("version");
                Thread.Sleep(500);
                datain = tc.Read();
                updateOutputStatus(datain);

                tc.WriteLine(string.Format("cu {0}_pinfo", cmd_prefix));
                Thread.Sleep(500);
                datain = tc.Read();
                updateOutputStatus(datain);

                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;
                int i = 0;
                int fail_count = 0;
                while (true)
                {
                    //tc.WriteLine("cu cs5480_start_conv");
                    //tc.WriteLine("cu cs5480_start_single_conv");
                    //Thread.Sleep(1000);

                    tc.WriteLine(string.Format("cu {0}_pload", cmd_prefix));
                    Thread.Sleep(500);
                    datain = tc.Read();
                    updateOutputStatus(datain);

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

                        Match match = Regex.Match(datain, rawCurrentPattern);
                        if (match.Groups.Count > 1)
                        {
                            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 > 1)
                            {
                                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;
                            }

                            if (voltage_cs > voltage_low_limit)
                            {
                                i++;
                                msg = string.Format("Cirrus I = {0:F8}, V = {1:F8}, P = {2:F8}", current_cs, voltage_cs, current_cs * voltage_cs);
                                updateOutputStatus(msg);
                            }
                            else
                            {
                                fail_count++;
                            }
                            if (i > 1)
                                break;
                        }
                    }

                    Thread.Sleep(1000);
                }

                /// The meter measurements
                MultiMeter meter = new MultiMeter("COM1");
                meter.OpenComPort();
                meter.SetToRemote();

                meter.SetupForIAC();
                string current_meter_str = meter.Measure();
                current_meter_str = meter.Measure();
                double current_meter = Double.Parse(current_meter_str);

                meter.SetupForVAC();
                string voltage_meter_str = meter.Measure();
                voltage_meter_str = meter.Measure();
                double voltage_meter = Double.Parse(voltage_meter_str);

                meter.CloseSerialPort();

                msg = string.Format("Meter I = {0:F8}, V = {1:F8}, P = {2:F8}", current_meter, voltage_meter, current_meter * voltage_meter);
                updateOutputStatus(msg);

                // Gain calucalation
                double current_gain = current_meter / current_cs;
                //double current_gain = current_meter / current_cs;
                int current_gain_int = (int)(current_gain * 0x400000);
                msg = string.Format("Current Gain = {0:F8} (0x{1:X})", current_gain, current_gain_int);
                updateOutputStatus(msg);

                double voltage_gain = voltage_meter / voltage_cs;
                int voltage_gain_int = (int)(voltage_gain * 0x400000);
                msg = string.Format("Voltage Gain = {0:F8} (0x{1:X})", voltage_gain, voltage_gain_int);
                updateOutputStatus(msg);

                msg = patch(board_type, voltage_gain_int, current_gain_int);
                Thread.Sleep(2000);
                datain = tc.Read();
                updateOutputStatus(datain);

                tc.WriteLine(string.Format("cu {0}_pinfo", cmd_prefix));
                Thread.Sleep(500);
                datain = tc.Read();
                updateOutputStatus(datain);

                i = 0;
                while (true)
                {
                    tc.WriteLine(string.Format("cu {0}_pload", cmd_prefix));
                    Thread.Sleep(500);
                    datain = tc.Read();
                    Debug.WriteLine(datain);

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

                        Match match = Regex.Match(datain, rawCurrentPattern);
                        if (match.Groups.Count > 1)
                        {
                            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 > 1)
                            {
                                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;
                            }

                            if (voltage_cs > voltage_low_limit)
                            {
                                i++;
                                msg = string.Format("Cirrus I = {0:F8}, V = {1:F8}, P = {2:F8}", current_cs, voltage_cs, current_cs * voltage_cs);
                                updateOutputStatus(msg);
                            }
                            if (i > 1)
                                break;
                        }
                    }

                    Thread.Sleep(1000);
                }
                tc.Close();
            }
Ejemplo n.º 2
0
        /// <summary>
        /// The main re-coding function
        /// Reads the calibration tokens, codes and reprograms the same tokens
        /// </summary>
        /// <param name="cancel"></param>
        public void Run(CancellationToken cancel)
        {
            // Check to see if Ember is to be used as USB and open ISA channel if so
            // Also set the box address
            Ember.Interfaces ember_interface = (Ember.Interfaces)Enum.Parse(
                typeof(Ember.Interfaces), Properties.Settings.Default.Ember_Interface);
            _ember.Interface = ember_interface;
            if (_ember.Interface == Ember.Interfaces.USB)
            {
                _ember.Interface_Address = Properties.Settings.Default.Ember_Interface_USB_Address;
                fire_run_status("Open ISA Channels");
                _ember.OpenISAChannels();
            }
            else
            {
                _ember.Interface_Address = Properties.Settings.Default.Ember_Interface_IP_Address;
            }

            TCLI.Tokens caltokens = new TCLI.Tokens(eui: "", ifactor: 0, vfactor: 0, igain: 0, vgain: 0);
            string msg = "";
            bool got_tokens = false;
            string log_file = "";
            string eui = "";
            while (true)
            {
                if (cancel.IsCancellationRequested)
                    break;

                try
                {
                    // Create a new telnet connection
                    fire_run_status("Start telnet");
                    // If interface is USB we use localhost
                    string telnet_address = "localhost";
                    if (_ember.Interface == Ember.Interfaces.IP)
                        telnet_address = _ember.Interface_Address;
                    _telnet_connection = new TelnetConnection(telnet_address, 4900);

                    fire_run_status("Get EUI");
                    eui = TCLI.Get_EUI(_telnet_connection);
                    //DialogResult rc = ShowInputDialog(ref serial_number, inputbox_label: "Serial");
                    //if (rc == DialogResult.Cancel)
                    //    throw new Exception("Serial number not entered");
                    fire_status("EUI = " + eui);

                    fire_run_status("Get UUT Tokens");
                    string cmd_prefix = TCLI.Get_Custom_Command_Prefix(_telnet_connection);
                    caltokens = TCLI.Parse_Pinfo_Tokens(_telnet_connection, cmd_prefix);
                    caltokens.EUI = eui;
                    msg = string.Format("Voltage Factor: {0}, ", caltokens.VoltageFactor);
                    msg += string.Format("Current Factor: {0}, ", caltokens.CurrentFactor);
                    msg += string.Format("VGain Token: 0x{0:X08}, ", caltokens.VoltageGainToken);
                    msg += string.Format("CGain Token: 0x{0:X08}", caltokens.CurrentGainToken);
                    fire_status(msg);

                    string filename = string.Format("tokens_{0}-{1:yyyy-MM-dd_hh-mm-ss-tt}.txt", eui, DateTime.Now);
                    log_file = Path.Combine(_app_data_dir, filename); // Path to the app log file
                    msg = string.Format("::EUI: {0}\r\n::{1}\r\n", eui, msg);
                    File.WriteAllText(log_file, msg);

                    got_tokens = true;

                    break;
                }
                catch (Exception ex)
                {
                    string retry_err_msg = ex.Message;
                    int max_len = 1000;
                    if (retry_err_msg.Length > max_len)
                        retry_err_msg = retry_err_msg.Substring(0, max_len) + "...";
                    DialogResult dlg_rc = MessageBox.Show(retry_err_msg, "Exception reading tokens", MessageBoxButtons.RetryCancel);
                    if (dlg_rc == System.Windows.Forms.DialogResult.Cancel)
                        throw;
                }
                finally
                {
                    _telnet_connection.Close();
                    _ember.CloseISAChannels();
                }
            }
            if (!got_tokens)
            {
                throw new Exception("Tokens not read");
            }

            try
            {
                // Code here
                fire_run_status("Code");
                Coder coder = new Coder(new TimeSpan(0, 2, 0));
                coder.Code(cancel);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                // Repatch the tokens
                fire_run_status("Patch UUT Tokens");
                //caltokens.VoltageGainToken = 0x00405E00;
                //caltokens.CurrentGainToken = 0X002F7EB7;
                //caltokens.VoltageFactor = 240;
                //caltokens.CurrentFactor = 15;

                _ember.VoltageRefereceValue = caltokens.VoltageFactor;
                _ember.CurrentRefereceValue = caltokens.CurrentFactor;
                string cmd_str = _ember.CreateCalibrationPatchBath(vgain: caltokens.VoltageGainToken, igain: caltokens.CurrentGainToken);
                if (File.Exists(log_file))
                {
                    File.AppendAllText(log_file, cmd_str);
                }

                while (true)
                {
                    string[] ember_temp_files = Ember.CleanupTempPatchFile();
                    foreach (string file in ember_temp_files)
                        fire_status(string.Format("Ember temp file found and removed {0}", file));

                    try
                    {
                        string patch_output = _ember.RunCalibrationPatchBatch();
                        break;
                    }
                    catch (Exception ex)
                    {
                        string retry_err_msg = ex.Message;
                        int max_len = 1000;
                        if (retry_err_msg.Length > max_len)
                            retry_err_msg = retry_err_msg.Substring(0, max_len) + "...";
                        DialogResult dlg_rc = MessageBox.Show(retry_err_msg, "Exception patching tokens", MessageBoxButtons.RetryCancel);
                        if (dlg_rc == System.Windows.Forms.DialogResult.Cancel)
                            throw;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sends reset command to 4902 port
        /// </summary>
        /// <param name="Hostname"></param>
        /// <returns></returns>
        public static bool ResetISAANode(string Hostname)
        {
            TelnetConnection reset_telnet = new TelnetConnection(Hostname, ISA3_ADMIN_PORT_NUM);
            Match match = TCLI.Wait_For_Match(reset_telnet, "reset", "Success: Node reset");
            reset_telnet.Close();

            return match.Success;
        }