Example #1
0
        static void Main(string[] args)
        {
            //  Random rand = new Random();


            dmxControl = new DmxDriver(0);
            dmxControl.OpenPort();
            CommandParser commandParser = new CommandParser();

            //if port is closed, try to open every second
            while (!dmxControl.device.IsOpen)
            {
                dmxControl.OpenPort();
                Thread.Sleep(TimeSpan.FromSeconds(1));
            }

            //  Pulse();

            while (true)
            {
                commandParser.Parse(Console.ReadLine(), dmxControl);
            }
        }
Example #2
0
        public void Parse(string input, DmxDriver dmxControl)
        {
            string[] args = input.Split(' ');
            //to do, remove blanks
            //move all write commands to case write. cant currently write custom groups
            //make command to display range
            switch (args[0].ToLower())
            {
            case "write":
                if (args.Length > 1)
                {
                    switch (args[1].ToLower())
                    {
                    case "1":        // channel, NEED TO GET INT
                        if (!FullCommand(args, 3))
                        {
                            break;
                        }
                        Write(args, dmxControl); break;

                    case "range":
                        if (!FullCommand(args, 3))
                        {
                            break;
                        }
                        WriteRange(args[2], dmxControl); break;

                    case "all":
                        if (!FullCommand(args, 3))
                        {
                            break;
                        }
                        WriteAll(args[2], dmxControl); break;

                    default: Console.WriteLine("Invalid Input"); break;
                    }
                }
                else
                {
                    Console.WriteLine("Invalid Input");
                }
                break;

            case "set":
                if (args.Length > 1)
                {
                    switch (args[1].ToLower())
                    {
                    case "range": SetRange(args); break;

                    case "group": SetChannel(args); break;

                    default: Console.WriteLine("Invalid Input"); break;
                    }
                }
                else
                {
                    Console.WriteLine("Invalid Input");
                }
                break;

            case "mode":
                if (!FullCommand(args, 2))
                {
                    break;
                }
                if (args[1].ToLower() == "inclusive" || args[1].ToLower() == "i")
                {
                    mode = "Inclusive";
                }
                else if (args[1].ToLower() == "exclusive" || args[1].ToLower() == "e")
                {
                    mode = "Exclusive";
                }
                break;

            case "range": Console.WriteLine("Range: " + rangeStart + "-" + rangeEnd); break;

            case "groups": ShowChannels(); break;

            case "clear": Console.Clear(); break;

            case "device": dmxControl.PrintDeviceData(); break;

            case "help":
            case "?":
            case "/h": HelpCommand(); break;

            case "quit": Environment.Exit(0); break;

            case "open":
                dmxControl.OpenPort();
                Console.WriteLine("Port Opened");
                break;

            case "close":
                dmxControl.ClosePort();
                Console.WriteLine("Port Closed");
                return;

            case "startcode":
                if (args.Length > 1)
                {
                    int parsedCode = 0;
                    if (int.TryParse(args[1], out parsedCode))
                    {
                        dmxControl.StartCode = (byte)parsedCode;
                    }
                    else
                    {
                        Console.WriteLine("Invalid Input");
                    }
                }
                else
                {
                    Console.WriteLine("Current Start Code: " + dmxControl.StartCode);
                }
                break;

            default: Console.WriteLine("Invalid Input"); return;
            }
            //UpdateData();
        }