コード例 #1
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// start the PLC Loop from begin
        /// </summary>
        public void startPLC()
        {
            if (m_CurPLCState != ePLCState.STOP)
            {
                return;
            }

            m_CurPLCState = ePLCState.RUN;
        }
コード例 #2
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// resume paused PLC from paused command
        /// </summary>
        public void resumePLC()
        {
            if (m_CurPLCState != ePLCState.PAUSE)
            {
                return;
            }

            m_CurPLCState = ePLCState.RUN;

            m_PLCCPU.pause();
        }
コード例 #3
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// pause the PLC Loop in the current command
        /// </summary>
        public void pausePLC()
        {
            if (m_CurPLCState != ePLCState.RUN)
            {
                return;
            }

            m_CurPLCState = ePLCState.PAUSE;

            m_PLCCPU.pause();
        }
コード例 #4
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// stop the PLC Loop and reset all to begin
        /// </summary>
        public void stopPLC()
        {
            if (m_CurPLCState != ePLCState.RUN)
            {
                return;
            }

            m_CurPLCState = ePLCState.STOP;

            m_PLCCPU.pause();
            m_PLCCPU.reset();
        }
コード例 #5
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// erase PLC Program from Program-Memory
        /// </summary>
        public void erasePLC()
        {
            if (m_CurPLCState != ePLCState.STOP)
            {
                return;
            }

            m_CurPLCState = ePLCState.INIT;

            Array.Clear(m_byaInstrMemory, 0, m_byaInstrMemory.Length);
            Array.Clear(m_byaStackMemory, 0, m_byaStackMemory.Length);
        }
コード例 #6
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// runs the PLC Program (CPU is in run)
        /// </summary>
        public void runPLC()
        {
            if (m_CurPLCState != ePLCState.RUN)
            {
                return;
            }

            m_PLCCPU.run();

            if (m_PLCCPU.RunError)
            {
                m_CurPLCState = ePLCState.ERROR;
            }
        }
コード例 #7
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// init PLC memory
        /// </summary>
        public void initPLC()
        {
            if (m_CurPLCState == ePLCState.NONE)
            {
                m_byaInputMemory  = new byte[MAX_PLC_MEMORY];
                m_byaOutputMemory = new byte[MAX_PLC_MEMORY];
                m_byaMarkerMemory = new byte[MAX_PLC_MEMORY];

                m_byaStackMemory = new byte[MAX_STACK_MEMORY];

                Console.SetWindowSize(150, 50);

                m_CurPLCState = ePLCState.INIT;
                m_CurAppState = eAppState.MENU;
            }
        }
コード例 #8
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// reset PLC variables (IN/OUT/MARKER to 0) in the Variable-Memory 3x4096 byte
        /// </summary>
        public void resetPLC()
        {
            if (m_CurPLCState != ePLCState.PAUSE && m_CurPLCState != ePLCState.ERROR)
            {
                return;
            }

            m_CurPLCState = ePLCState.STOP;

            m_PLCCPU.pause();
            Array.Clear(m_byaInputMemory, 0, m_byaInputMemory.Length);
            Array.Clear(m_byaOutputMemory, 0, m_byaOutputMemory.Length);
            Array.Clear(m_byaMarkerMemory, 0, m_byaMarkerMemory.Length);
            m_PLCCPU.reset();
            m_PLCCPU.RunError = false;
        }
コード例 #9
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        // load a Project file and read in all data
        private bool loadPLCProgram(ref byte[] instrMem, out string msg)
        {
            // to get rid of the Enter-key in the console buffer
            while (Console.ReadLine().Length > 0)
                ;

            msg = "SUCCESS: Object file loaded!";
            FileInfo fi = null;
            List<byte> instrList = null;
            bool fileOK = false, readOK = false;
            while (!fileOK && !readOK)
            {
                Console.Clear();
                Console.WriteLine("PLC PROJECT FILE or Enter leave:");
                string file = Console.ReadLine();

                if (file.Length <= 0)
                {
                    return false;
                }

                fi = new FileInfo(@"..\..\..\PLC_PROJ\PROJ_ONE\" + file + ".cop");
                if (!fi.Exists || fi.Length < 23)    // 23 for the moment normal lenght data + zero's for the strings
                {
                    Console.WriteLine("File not found or to small:\n" + fi.FullName + "\nPlease check file and try again!\nPRESS ANY KEY TO PROCCED");
                    Console.ReadKey();
                    continue;
                }

                fileOK = true;
                string path = fi.DirectoryName;

                if (readProjHeader(fi.FullName, ref msg))
                {
                    return true;
                }

                if (readProjEntry(fi.FullName, ref msg))
                {
                    return true;
                }

                int size = 0;
                foreach (BlockInfo bi in m_BlockOverview.Values)
                    size += (int)bi.Size;

                instrList = new List<byte>(size);

                // read Block data
                for (int i = 0; i < m_BlockOverview.Count; i++)
                {
                    if (readBlocks(i, path, m_BlockOverview[i].Name, ref msg, ref instrList))
                    {
                        return true;
                    }
                }
            }

            instrMem = instrList.ToArray();

            msg = "SUCCESS:\nProject file: " + fi.Name + " loaded!\n" + 
                "SIZE: " + instrList.Count() + " | INSTR: " + (instrList.Count / INSTR_SIZE);

            m_CurPLCState = ePLCState.STOP;

            return false;
        }
コード例 #10
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// stop the PLC Loop and reset all to begin
        /// </summary>
        public void stopPLC()
        {
            if (m_CurPLCState != ePLCState.RUN)
                return;

            m_CurPLCState = ePLCState.STOP;

            m_PLCCPU.pause();
            m_PLCCPU.reset();
        }
コード例 #11
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// resume paused PLC from paused command
        /// </summary>
        public void resumePLC()
        {
            if (m_CurPLCState != ePLCState.PAUSE)
                return;

            m_CurPLCState = ePLCState.RUN;

            m_PLCCPU.pause();
        }
コード例 #12
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// reset PLC variables (IN/OUT/MARKER to 0) in the Variable-Memory 3x4096 byte
        /// </summary>
        public void resetPLC()
        {
            if (m_CurPLCState != ePLCState.PAUSE && m_CurPLCState != ePLCState.ERROR)
                return;

            m_CurPLCState = ePLCState.STOP;

            m_PLCCPU.pause();
            Array.Clear(m_byaInputMemory, 0, m_byaInputMemory.Length);
            Array.Clear(m_byaOutputMemory, 0, m_byaOutputMemory.Length);
            Array.Clear(m_byaMarkerMemory, 0, m_byaMarkerMemory.Length);
            m_PLCCPU.reset();
            m_PLCCPU.RunError = false;
        }
コード例 #13
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// pause the PLC Loop in the current command
        /// </summary>
        public void pausePLC()
        {
            if (m_CurPLCState != ePLCState.RUN)
                return;

            m_CurPLCState = ePLCState.PAUSE;

            m_PLCCPU.pause();
        }
コード例 #14
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// erase PLC Program from Program-Memory
        /// </summary>
        public void erasePLC()
        {
            if (m_CurPLCState != ePLCState.STOP)
                return;

            m_CurPLCState = ePLCState.INIT;

            Array.Clear(m_byaInstrMemory, 0, m_byaInstrMemory.Length);
            Array.Clear(m_byaStackMemory, 0, m_byaStackMemory.Length);
        }
コード例 #15
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// start the PLC Loop from begin
        /// </summary>
        public void startPLC()
        {
            if (m_CurPLCState != ePLCState.STOP)
                return;

            m_CurPLCState = ePLCState.RUN;
        }
コード例 #16
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        public bool runPLCMenu()
        {
            initPLC();

            int iChoice   = 0;
            int minChoice = 0;
            int maxChoice = Enum.GetNames(typeof(eAbleTo)).Count() - 1;

            bool[] isAbleTo = new bool[maxChoice + 1];
            for (int i = 0; i < isAbleTo.Length; i++)
            {
                isAbleTo[i] = true;
            }

            string[] sMenuEntrys =
            {
                "LOAD   PLC-PROGRAM",
                "RUN    PLC-PROGRAM",
                "STOP   PLC-PROGRAM",
                "PAUSE  PLC-PROGRAM",
                "RESUME PLC-PROGRAM",
                "RESET  PLC-PROGRAM",
                "ERASE  PLC-PROGRAM",
                "LOAD   PLC-VISU",
                "SHOW   PLC-DATA",
                "SHOW   PLC-BLOCKS",
                "INFO",
                "EXIT         [ESC]",
            };

            Keyboard.instance.registerKey(Keys.Escape);
            Keyboard.instance.registerKey(Keys.Enter);
            Keyboard.instance.registerKey(Keys.Up);
            Keyboard.instance.registerKey(Keys.Down);
            Keyboard.instance.registerKey(Keys.LShiftKey);

            foreach (Keys k in m_InputKeys)
            {
                Keyboard.instance.registerKey(k);
            }

            bool bRun = true;

            while (bRun)
            {
                Keyboard.instance.update();

                if (m_CurAppState != m_OldAppState)
                {
                    Console.Clear();
                }

                if (m_CurPLCState != m_OldPLCState)
                {
                    Console.Clear();
                }

                m_OldAppState = m_CurAppState;
                m_OldPLCState = m_CurPLCState;

                if (m_CurAppState == eAppState.MENU)
                {
                    AbleTo(ref isAbleTo);

                    Choice(ref iChoice, isAbleTo, minChoice, maxChoice);

                    DrawMenu(iChoice, isAbleTo, maxChoice, sMenuEntrys);
                }
                else if (m_CurAppState == eAppState.VISU)
                {
                    showVisu();
                }

                ProcessChoice(iChoice, ref bRun);

                runPLC();

                showPLCState();


                System.Threading.Thread.Sleep(100);
            }

            return(false);
        }
コード例 #17
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        public bool runPLCMenu()
        {
            initPLC();

            int iChoice = 0;
            int minChoice = 0;
            int maxChoice = Enum.GetNames(typeof(eAbleTo)).Count() - 1;
            bool[] isAbleTo = new bool[maxChoice + 1];
            for (int i = 0; i < isAbleTo.Length; i++ )
                isAbleTo[i] = true;

            string[] sMenuEntrys = {
                                       "LOAD   PLC-PROGRAM",
                                       "RUN    PLC-PROGRAM",
                                       "STOP   PLC-PROGRAM",
                                       "PAUSE  PLC-PROGRAM",
                                       "RESUME PLC-PROGRAM",
                                       "RESET  PLC-PROGRAM",
                                       "ERASE  PLC-PROGRAM",
                                       "LOAD   PLC-VISU",
                                       "SHOW   PLC-DATA",
                                       "SHOW   PLC-BLOCKS",
                                       "INFO",
                                       "EXIT         [ESC]",
                                   };

            Keyboard.instance.registerKey(Keys.Escape);
            Keyboard.instance.registerKey(Keys.Enter);
            Keyboard.instance.registerKey(Keys.Up);
            Keyboard.instance.registerKey(Keys.Down);
            Keyboard.instance.registerKey(Keys.LShiftKey);

            foreach (Keys k in m_InputKeys)
                Keyboard.instance.registerKey(k);

            bool bRun = true;
            while (bRun)
            {
                Keyboard.instance.update();

                if (m_CurAppState != m_OldAppState)
                    Console.Clear();

                if (m_CurPLCState != m_OldPLCState)
                    Console.Clear();

                m_OldAppState = m_CurAppState;
                m_OldPLCState = m_CurPLCState;

                if (m_CurAppState == eAppState.MENU)
                {
                    AbleTo(ref isAbleTo);

                    Choice(ref iChoice, isAbleTo, minChoice, maxChoice);

                    DrawMenu(iChoice, isAbleTo, maxChoice, sMenuEntrys);
                }
                else if (m_CurAppState == eAppState.VISU)
                {
                    showVisu();
                }

                ProcessChoice(iChoice, ref bRun);
                
                runPLC();

                showPLCState();


                System.Threading.Thread.Sleep(100);
            }

            return false;
        }
コード例 #18
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// runs the PLC Program (CPU is in run)
        /// </summary>
        public void runPLC()
        {
            if (m_CurPLCState != ePLCState.RUN)
                return;

            m_PLCCPU.run();

            if (m_PLCCPU.RunError)
            {
                m_CurPLCState = ePLCState.ERROR;
            }
        }
コード例 #19
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        // load a Project file and read in all data
        private bool loadPLCProgram(ref byte[] instrMem, out string msg)
        {
            // to get rid of the Enter-key in the console buffer
            while (Console.ReadLine().Length > 0)
            {
                ;
            }

            msg = "SUCCESS: Object file loaded!";
            FileInfo    fi = null;
            List <byte> instrList = null;
            bool        fileOK = false, readOK = false;

            while (!fileOK && !readOK)
            {
                Console.Clear();
                Console.WriteLine("PLC PROJECT FILE or Enter leave:");
                string file = Console.ReadLine();

                if (file.Length <= 0)
                {
                    return(false);
                }

                fi = new FileInfo(@"..\..\..\PLC_PROJ\PROJ_ONE\" + file + ".cop");
                if (!fi.Exists || fi.Length < 23)    // 23 for the moment normal lenght data + zero's for the strings
                {
                    Console.WriteLine("File not found or to small:\n" + fi.FullName + "\nPlease check file and try again!\nPRESS ANY KEY TO PROCCED");
                    Console.ReadKey();
                    continue;
                }

                fileOK = true;
                string path = fi.DirectoryName;

                if (readProjHeader(fi.FullName, ref msg))
                {
                    return(true);
                }

                if (readProjEntry(fi.FullName, ref msg))
                {
                    return(true);
                }

                int size = 0;
                foreach (BlockInfo bi in m_BlockOverview.Values)
                {
                    size += (int)bi.Size;
                }

                instrList = new List <byte>(size);

                // read Block data
                for (int i = 0; i < m_BlockOverview.Count; i++)
                {
                    if (readBlocks(i, path, m_BlockOverview[i].Name, ref msg, ref instrList))
                    {
                        return(true);
                    }
                }
            }

            instrMem = instrList.ToArray();

            msg = "SUCCESS:\nProject file: " + fi.Name + " loaded!\n" +
                  "SIZE: " + instrList.Count() + " | INSTR: " + (instrList.Count / INSTR_SIZE);

            m_CurPLCState = ePLCState.STOP;

            return(false);
        }
コード例 #20
0
ファイル: PLCManager.cs プロジェクト: Chefkoch85/CKT_PLC
        /// <summary>
        /// init PLC memory
        /// </summary>
        public void initPLC()
        {
            if (m_CurPLCState == ePLCState.NONE)
            {
                m_byaInputMemory = new byte[MAX_PLC_MEMORY];
                m_byaOutputMemory = new byte[MAX_PLC_MEMORY];
                m_byaMarkerMemory = new byte[MAX_PLC_MEMORY];

                m_byaStackMemory = new byte[MAX_STACK_MEMORY];

                Console.SetWindowSize(150, 50);

                m_CurPLCState = ePLCState.INIT;
                m_CurAppState = eAppState.MENU;    
            }
        }