Ejemplo n.º 1
0
        protected override void HandleNewConnection(TcpConnection newConnection)
        {
            if (newConnection == null)
            {
                throw new ArgumentNullException("newConnection");
            }

            TelnetConnection TypedConnection = new TelnetConnection();

            if (TypedConnection.Open(newConnection.GetSocket()))
            {
                ClientThread NewClientThread = new ClientThread(TypedConnection, _ConnectionType);
                NewClientThread.Start();
            }
            else
            {
                // TODOX Duplicated code.  Maybe add method to base class and call it?
                RMLog.Info("No carrier detected (probably a portscanner)");
                TypedConnection.Close();
            }
        }
Ejemplo n.º 2
0
        private static void RebootController()
        {
            Console.WriteLine(" IP:   " + strIP);
            Console.WriteLine(" Port: " + strPort);
            Console.WriteLine("");

            TelnetConnection tc = new TelnetConnection();

            // try to connect
            if (tc.Connect(strIP, strPort))
            {
                // clear input buffer
                tc.Read();

                Console.WriteLine("TX: reboot");
                // send to server
                tc.WriteLine("reboot\r");


                Timer tTimeOut = new Timer(TimeOut, null, 30000, 0);

                string strInput = "";

                while (tc.IsConnected & (bolTimedOut == false))
                {
                    strInput = tc.Read();

                    if (string.IsNullOrWhiteSpace(strInput) == false)
                    {
                        // reset timeout
                        tTimeOut.Change(30000, 0);

                        strInput = strInput.Replace("\n", "");

                        // split messages
                        string[] arrInput = Regex.Split(strInput, "\r");

                        for (int i = 0; i < arrInput.Length - 1; i++)
                        {
                            // display server output
                            Console.WriteLine("RX: " + arrInput[i]);

                            if (arrInput[i].StartsWith("bye"))
                            {
                                tc.Close();
                                Console.WriteLine("controller is rebooting now");
                            }
                        }
                    }
                }

                if (bolTimedOut)
                {
                    Console.WriteLine("Error TimeOut: controller is not responding");
                    bolWait = true;
                }
            }
            else
            {
                // wait to show error
                bolWait = true;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Called when tasks completes
 /// </summary>
 /// <param name="task"></param>
 void monitor_completed(Task task)
 {
     _telnet_connection.Close();
     controlSetPropertyValue(button1, "Start");
 }
Ejemplo n.º 4
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();
            }