Example #1
0
        void Reconnect()
        {
            connection.Close();
            connection = null;

            EV3Directory.Visibility  = Visibility.Hidden;
            BrickNotFound.Visibility = Visibility.Visible;

            ev3path      = "/home/root/lms2012/prjs/";
            EV3Path.Text = ev3path;

            // find connected brick
            try
            {
                connection = ConnectionFinder.CreateConnection(true, false);
                ReadEV3Directory(true);
                ReadEV3DeviceName();
            }
            catch (Exception)
            {
                System.Environment.Exit(1);
            }

            EV3Directory.Visibility  = Visibility.Visible;
            BrickNotFound.Visibility = Visibility.Hidden;

            AdjustDisabledStates();
        }
Example #2
0
        // startup
        public MainWindow()
        {
            // find connected brick
            try
            {
                connection = ConnectionFinder.CreateConnection(true, true);
            }
            catch (Exception)
            {
                System.Environment.Exit(1);
            }


            // load peristent settings
            ExplorerSettings settings = new ExplorerSettings();

            settings.Load();

            // create the compiler and assembler instances
            assembler = new Assembler();
            compiler  = new Compiler();

            // initialize common data
            ev3path = "/home/root/lms2012/prjs/";
            try
            {
                pcdirectory = new DirectoryInfo(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal));
            } catch (Exception)
            {
                pcdirectory = null;
            }
            if (settings.localDirectory.Length > 0)
            {
                try
                {
                    pcdirectory = settings.localDirectory.Equals("Computer") ? null : new DirectoryInfo(settings.localDirectory);
                }
                catch (Exception) { }
            }

            // set up all UI controls
            InitializeComponent();
            this.Width                      = settings.windowWidth;
            this.Height                     = settings.windowHeight;
            this.leftColumn.Width           = new GridLength((double)settings.splitterPosition, GridUnitType.Pixel);
            this.OnlyShowPrograms.IsChecked = settings.onlyShowPrograms;

            // retrieve initial data from brick
            EV3Path.Text = ev3path;
            ReadEV3Directory(true);
            ReadEV3DeviceName();

            PCPath.Text = pcdirectory == null ? "Computer" : pcdirectory.FullName;
            RefreshPCList(true);
        }
        static void Main(string[] args)
        {
            foreach (String a in args)
            {
                Console.WriteLine("{0}", a);
            }

            if (args[0].Equals("asmLms"))
            {
                if (args.Length != 3)
                {
                    Console.WriteLine("Error 0: No all params [see help]");
                    return;
                }
                Assembler asm = new Assembler();
                //FileStream fs = new FileStream(f, FileMode.Open, FileAccess.Read);
                FileStream fs   = new FileStream(args[1], FileMode.Open, FileAccess.Read);
                FileStream fout = new FileStream(args[2], FileMode.Create, FileAccess.Write);

                List <String> errors = new List <String>();
                asm.Assemble(fs, fout, errors);
                if (errors.Count != 0)
                {
                    Console.WriteLine("error in assembler for lms2012");
                    foreach (String a  in errors)
                    {
                        Console.WriteLine(a);
                    }
                }
            }
            else if (args[0].Equals("disasmRbf"))
            {
                if (args.Length != 3)
                {
                    Console.WriteLine("Error 0: No all params [see help]");
                    return;
                }

                Assembler  asm  = new Assembler();
                FileStream from = new FileStream(args[1], FileMode.Open, FileAccess.Read);

                asm.Disassemble(from, Console.Out);
            }
            else if (args[0].Contains("download"))
            {
                if (args.Length != 3)
                {
                    Console.WriteLine("Error 0: No all params [see help]");
                    return;
                }
                EV3Connection connection = ConnectionFinder.CreateConnection(true, true);
                Console.WriteLine("Connection {0}", connection.IsOpen());
                byte[] data = null;
                try
                {
                    data = connection.ReadEV3File(args[1]);
                } catch (Exception e)
                {
                    Console.WriteLine("{0}", e.ToString());
                }

                FileStream fileStream = new FileStream(args[2], FileMode.Create, FileAccess.Write);
                fileStream.Write(data, 0, data.Length);
            }
            else if (args[0].Contains("upload"))
            {
                if (args.Length != 3)
                {
                    Console.WriteLine("Error 0: No all params [see help]");
                    return;
                }
                EV3Connection connection = ConnectionFinder.CreateConnection(true, true);
                FileStream    from       = new FileStream(args[2], FileMode.Open, FileAccess.Read);
                byte[]        data       = new byte[from.Length];

                from.Read(data, 0, (int)from.Length);

                connection.CreateEV3File(args[1], data);
                connection.Close();
            }
            else if (args.Contains("execute"))
            {
                if (args.Length != 2)
                {
                    Console.WriteLine("Error 0: No all params [see help]");
                    return;
                }
                EV3Connection connection = ConnectionFinder.CreateConnection(true, true);
                Console.WriteLine("Trying to start: " + args[1]);

                ByteCodeBuffer c = new ByteCodeBuffer();
                // load and start it
                c.OP(0xC0);       // opFILE
                c.CONST(0x08);    // CMD: LOAD_IMAGE = 0x08
                c.CONST(1);       // slot 1 = user program slot
                c.STRING(args[1]);
                c.GLOBVAR(0);
                c.GLOBVAR(4);
                c.OP(0x03);       // opPROGRAM_START
                c.CONST(1);       // slot 1 = user program slot
                c.GLOBVAR(0);
                c.GLOBVAR(4);
                c.CONST(0);

                connection.DirectCommand(c, 10, 0);
            }

            Console.ReadKey();
        }