Exemple #1
0
        static void asm(string[] args)
        {
            string f = null, o = null;
            bool d = false;
            string port = "COM6", baud="9600";
            char parity='E';
            int address=2;

            var p = new OptionSet() {
               	                        { "f|file=",  v => f = v },
               	                        { "o|output=",  v => o = v },
               	                        { "c|comport=",  v => port = v },
               	                        { "b|baud=",  v => baud = v },
               	                        { "p|parity=",  v => parity = v[0] },
               	                        { "a|address=",  v => address = int.Parse(v) },
               	                        { "d|download",  v => d = (v != null) },
                        };
            List<string> extra = p.Parse(args);
            if (f == null)
                UsageAndExit();

            using (TextReader streamReader =
                new StreamReader(f))
            {
                var source = streamReader.ReadToEnd();

                byte[] dest = null;
                var compiler = new Compiler();
                compiler.AssemblyBlock(
                    eBLOCK200_BLOCKTYPES.eBLOCK200_BLOCKTYPE_OB,
                    1,
                    STLCompiler.eBLOCK200_OB_VERSIONS.eBLOCK200_OB_VERSION_2ND_GEN_6,
                    false,
                    true,
                    true,
                    source,
                    out dest);

                if (o != null)
                {
                    using (BinaryWriter binWriter = new BinaryWriter(
                        File.Open(o, FileMode.Create)))
                    {
                        binWriter.Write(dest);
                    }
                }

                if (d)
                    DownloadProgramBlock(port, baud, parity, address, dest);
            }
        }
Exemple #2
0
        public bool Decompile(byte[] block, out string readSourceCode)
        {
            readSourceCode = string.Empty;
            try
            {
                var compiler = new Compiler();
                compiler.DisassemblyBlock(block, out readSourceCode);
            }
            catch (System.Exception)
            {
                return false;
            }

            return true;
        }
Exemple #3
0
        public bool Complie(string sourceCode, out byte[] block)
        {
            block = null;
            try
            {
                var compiler = new Compiler();
                compiler.AssemblyBlock(
                    eBLOCK200_BLOCKTYPES.eBLOCK200_BLOCKTYPE_OB,
                    1,
                    STLCompiler.eBLOCK200_OB_VERSIONS.eBLOCK200_OB_VERSION_2ND_GEN_6,
                    false,
                    true,
                    true,
                    sourceCode,
                    out block);
            }
            catch (System.Exception )
            {
                return false;
            }

            return true;
        }
Exemple #4
0
        static void disasm(string[] args)
        {
            string f = null, o = null;
            bool u = false;
            string port = "COM6", baud = "9600";
            char parity = 'E';
            int address = 2;
            var p = new OptionSet() {
               	                        { "f|file=",  v => f = v },
               	                        { "o|output=",  v => o = v },
               	                        { "c|comport=",  v => port = v },
               	                        { "b|baud=",  v => baud = v },
               	                        { "p|parity=",  v => parity = v[0] },
               	                        { "a|address=",  v => address = int.Parse(v) },
               	                        { "u|upload",  v => u = (v != null) },
                        };
            List<string> extra = p.Parse(args);
            if (!u && f == null)
                p.WriteOptionDescriptions(Console.Out);

            byte[] block = null;
            if (!u)
            {
                using (var binReader = new BinaryReader(
                    File.Open(f, FileMode.Open)))
                {
                    block = binReader.ReadBytes((int)binReader.BaseStream.Length);
                }
            }
            else
            {
                UploadProgramBlock(port, baud, parity, address, out block);
            }
            var compiler = new Compiler();
            string awlContent;

            compiler.DisassemblyBlock(block, out awlContent);

            using (var streamWriter =
                new StreamWriter(o, false))
            {
                streamWriter.Write(awlContent);
            }
        }