Exemple #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();
            }
Exemple #2
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();
            }