private void Download_clicked(Object sender, EventArgs e) { List <PCFile> tr = new List <PCFile>(); foreach (DirectoryEntry de in PCDirectory.SelectedItems) { if (de != null && (de is PCFile)) { tr.Add((PCFile)de); } } if (tr.Count > 0) { try { foreach (PCFile pcfile in tr) { FileInfo fi = pcfile.fileinfo; byte[] content = new byte[fi.Length]; FileStream fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read); int pos = 0; while (pos < content.Length) { int didread = fs.Read(content, pos, content.Length - pos); if (didread <= 0) { throw new Exception("Unexpected end of file"); } pos += didread; } fs.Close(); if (!checkFileName(fi.Name)) { return; } connection.CreateEV3File(internalPath(ev3path) + fi.Name, content); } ReadEV3Directory(false); } catch (Exception ex) { Console.WriteLine("Exception: " + ex.Message); Reconnect(); } AdjustDisabledStates(); } }
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(); }