Esempio n. 1
0
    // read deisred modules from config file
    public Magellan(int verbosity)
    {
        var d       = new Discover.Discover();
        var modules = d.GetSubClasses("SPH.SerialPortHandler");

        List <MagellanConfigPair> conf = ReadConfig();

        sph = new List <SerialPortHandler>();
        foreach (var pair in conf)
        {
            try {
                if (modules.Any(m => m.Name == pair.module))
                {
                    var type = d.GetType("SPH." + pair.module);
                    Console.WriteLine(pair.module + ":" + pair.port);
                    SerialPortHandler s = (SerialPortHandler)Activator.CreateInstance(type, new Object[] { pair.port });
                    s.SetParent(this);
                    s.SetVerbose(verbosity);
                    sph.Add(s);
                }
                else
                {
                    throw new Exception("unknown module: " + pair.module);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex);
                Console.WriteLine("Warning: could not initialize " + pair.port);
                Console.WriteLine("Ensure the device is connected and you have permission to access it.");
            }
        }
        MonitorSerialPorts();
        UdpListen();

        factorRabbits();
    }
Esempio n. 2
0
    // read deisred modules from config file
    public Magellan(int verbosity)
    {
        var d = new Discover.Discover();
        var modules = d.GetSubClasses("SPH.SerialPortHandler");

        List<MagellanConfigPair> conf = ReadConfig();
        sph = new List<SerialPortHandler>();
        foreach (var pair in conf) {
            try {
                if (modules.Any(m => m.Name == pair.module)) {
                    var type = d.GetType("SPH." + pair.module);
                    Console.WriteLine(pair.module + ":" + pair.port);
                    SerialPortHandler s = (SerialPortHandler)Activator.CreateInstance(type, new Object[]{ pair.port });
                    s.SetParent(this);
                    s.SetVerbose(verbosity);
                    sph.Add(s);
                } else {
                    throw new Exception("unknown module: " + pair.module);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex);
                Console.WriteLine("Warning: could not initialize "+pair.port);
                Console.WriteLine("Ensure the device is connected and you have permission to access it.");
            }
        }
        MonitorSerialPorts();
        UdpListen();

        factorRabbits();
    }
Esempio n. 3
0
    // read deisred modules from config file
    public Magellan(int verbosity)
    {
        var d = new Discover.Discover();
        var modules = d.GetSubClasses("SPH.SerialPortHandler");

        List<MagellanConfigPair> conf = ReadConfig();
        sph = new List<SerialPortHandler>();
	foreach (var pair in conf) {
            try {
		if (modules.Any(m => m.Name == pair.module)) {
		    var type = d.GetType("SPH." + pair.module);
		    Console.WriteLine(pair.module + ":" + pair.port);
		    SerialPortHandler s = (SerialPortHandler)Activator.CreateInstance(type, new Object[]{ pair.port });
                    s.SetParent(this);
                    s.SetVerbose(verbosity);
		    sph.Add(s);
		} else {
                    throw new Exception("unknown module: " + pair.module);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex);
                Console.WriteLine("Warning: could not initialize "+pair.port);
                Console.WriteLine("Ensure the device is connected and you have permission to access it.");
            }
        }
        FinishInit();

        #if CORE_RABBIT
        rabbit_factory = new ConnectionFactory();
        rabbit_factory.HostName = "localhost";
        rabbit_con = rabbit_factory.CreateConnection();
        rabbit_channel = rabbit_con.CreateModel();
        rabbit_channel.QueueDeclare("core-pos", false, false, false, null);
        #endif
    }
Esempio n. 4
0
    // read deisred modules from config file
    public Magellan(int verbosity)
    {
        var d           = new Discover.Discover();
        var modules     = d.GetSubClasses("SPH.SerialPortHandler");
        var my_location = this.GetMyPath();
        var sep         = Path.DirectorySeparatorChar;

        Magellan.log_path = my_location + sep + ".." + sep + ".." + sep + ".." + sep + "log" + sep + "debug_lane.log";

        List <MagellanConfigPair> conf = ReadConfig();

        sph = new List <SerialPortHandler>();
        foreach (var pair in conf)
        {
            try {
                if (modules.Any(m => m.Name == pair.module))
                {
                    var type = d.GetType("SPH." + pair.module);
                    Console.WriteLine(pair.module + ":" + pair.port);
                    SerialPortHandler s = (SerialPortHandler)Activator.CreateInstance(type, new Object[] { pair.port });
                    s.SetParent(this);
                    s.SetVerbose(verbosity);
                    s.SetConfig("disableRBA", this.disableRBA ? "true" : "false");
                    s.SetConfig("disableButtons", this.disableButtons ? "true" : "false");
                    s.SetConfig("logXML", this.logXML ? "true" : "false");
                    if (pair.settings != null)
                    {
                        s.SetConfig(pair.settings);
                    }
                    sph.Add(s);
                }
                else
                {
                    throw new Exception("unknown module: " + pair.module);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex);
                Console.WriteLine("Warning: could not initialize " + pair.port);
                Console.WriteLine("Ensure the device is connected and you have permission to access it.");
            }
        }
        MonitorSerialPorts();
        UdpListen();

        //factorRabbits();
    }
Esempio n. 5
0
    static public int Main(string[] args)
    {
        int verbosity = 0;

        for (int i = 0; i < args.Length; i++)
        {
            if (args[i] == "-v")
            {
                verbosity = 1;
                if (i + 1 < args.Length)
                {
                    try { verbosity = Int32.Parse(args[i + 1]); }
                    catch {}
                }
            }
            else if (args[i] == "-m")
            {
                // Reference a class in SPH to force SPH.dll to load
                var load    = new List <SerialPortHandler>();
                var d       = new Discover.Discover();
                var modules = d.GetSubClasses("SPH.SerialPortHandler").Where(t => !t.IsAbstract).ToList();
                modules.Sort((a, b) => a.ToString().CompareTo(b.ToString()));
                Console.WriteLine("Available modules:");
                foreach (var m in modules)
                {
                    Console.WriteLine("  " + m);
                }
                return(0);
            }
        }
        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(LastRites);
        Console.WriteLine("Wait forever");
        new Magellan(verbosity);
        Console.WriteLine("started");
        Thread.Sleep(Timeout.Infinite);
        Console.WriteLine("exiting?");

        return(0);
    }