コード例 #1
0
        // GET: Firecracker/Details/5
        public ActionResult Execute(string houseInput, string moduleInput, string moduleAction)
        {
            FirecrackerSerialPort.House houseId;
            Enum.TryParse<FirecrackerSerialPort.House>(houseInput, true, out houseId);

            int moduleNumber;
            int.TryParse(moduleInput, out moduleNumber);

            FirecrackerSerialPort.ModuleState moduleState;
            Enum.TryParse<FirecrackerSerialPort.ModuleState>(moduleAction, true, out moduleState);

            FirecrackerSerialPort fc = new FirecrackerSerialPort("COM3");
            fc.Initialize();
            fc.SendCommand(houseId, moduleNumber, moduleState);
            System.Threading.Thread.Sleep(1000);
            //Console.ReadKey();
            fc.Close();

            return PartialView();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: cjyoung/firecracker
        static void Main(string[] args)
        {
            Console.Write("House ID (A-P): ");
            string houseInput = Console.ReadLine();
            FirecrackerSerialPort.House houseId;

            while (!Enum.TryParse<FirecrackerSerialPort.House>(houseInput, true, out houseId))
            {
                Console.WriteLine("Invalid House ID, try again");
                houseInput = Console.ReadLine();
            }

            Console.Write("Module Number (1-16): ");
            string moduleInput = Console.ReadLine();
            int moduleNumber = 0;

            while (!int.TryParse(moduleInput, out moduleNumber) || moduleNumber > 16 || moduleNumber < 1)
            {
                Console.WriteLine("Invalid Module Number, try again");
                moduleInput = Console.ReadLine();
            }

            Console.Write("On/Off: ");
            string action = Console.ReadLine();
            FirecrackerSerialPort.ModuleState moduleState;
            while (!Enum.TryParse<FirecrackerSerialPort.ModuleState>(action, true, out moduleState))
            {
                Console.WriteLine("\"on\" or \"off\" only, try again");
                action = Console.ReadLine();
            }

            FirecrackerSerialPort fc = new FirecrackerSerialPort("COM3");
            fc.Initialize();
            fc.SendCommand(houseId, moduleNumber, moduleState);
            System.Threading.Thread.Sleep(1000);
            //Console.ReadKey();
            fc.Close();
        }