Example #1
0
        private void fnReadInput()
        {
            if (modeXml)
            {
                var str = _xml.ReadCell("input");

                for (var i = 0; i < MAX_NUM_INPUT; i++)
                {
                    pInPut[i].status = str[i] == '1';
                }
            }
            else
            {
                var txt = new cla_TXT();

                var pBuffer = txt.Read_txt(@"c:\input.txt");

                for (var i = 0; i < MAX_NUM_INPUT; i++)
                {
                    pInPut[i].status = pBuffer[i] == '1';
                }
            }
        }
Example #2
0
        void fnFlowCtrlThread()
        {
            var cClearStack = ' ';

            var iTokenStartPos = 0;

            var iStackDepth = 0;

            var iParseProgOffset = 0;

            var iTempBufferLength = 0;

            var iRet = 0;

            var bProgEnd = false;

            var sCOMMAND = new string[5];

            var pTempBuffer = "";

            var pPLC_OBJ = new cla_stPLCcs.stPLC_OBJ[MAX_LADDER_DEPTH];

            for (var i = 0; i < MAX_LADDER_DEPTH; i++)
            {
                pPLC_OBJ[i] = new cla_stPLCcs.stPLC_OBJ();
            }

            var txt = new cla_TXT();

            thePLCCore.fnRESETAll();

            thePLCCore.fnWriteOutput();

            pMEMBUF = txt.Read_txt(sLadderFilePath);   //读取LD X000OUT Y000END 进入pMEMBUF

            while (thePLCCore.bRUN)
            {
                iStackDepth = 0;

                iParseProgOffset = 0;

                cClearStack = '0';
                /* 弄 Input 篈弄癘拘砰い */
                fnReadInput();
                do
                {
                    FnReadM();

                    iTokenStartPos = iParseProgOffset;
                    /* 眔 Ladder 祘Α琿 such as LD X000だ琿よΑ琌 0x0d,0x0a 醚才腹 */
                    bProgEnd = thePLCCore.GetProgToken(ref iParseProgOffset);

                    if (bProgEnd)
                    {
                        var strTemp1 = pMEMBUF.Substring(iTokenStartPos, (pMEMBUF.Length - iTokenStartPos));

                        var strTemp2 = strTemp1.Split('\r');

                        pTempBuffer = strTemp2[0];

                        iParseProgOffset += 1;

                        iTempBufferLength = pTempBuffer.Length;

                        /* 盢 LD X000 ち澄Θ aa[0] = LD,aa[1] = X000 */

                        sCOMMAND = pTempBuffer.Split(' ');
                        /* 亩 Ladder Prog Command */
                        // LD
                        if ((sCOMMAND[0][0] == 'L') && (sCOMMAND[0][1] == 'D') && (sCOMMAND[0].Length == 2))
                        {
                            if (cClearStack == 0x01)
                            {
                                iStackDepth--;

                                cClearStack = Convert.ToChar(0x00);
                            }
                            iRet = thePLCCore.fnLDAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);
                            iStackDepth++;
                        }// LDI
                        else if ((sCOMMAND[0][0] == 'L') && (sCOMMAND[0][1] == 'D') && (sCOMMAND[0][2] == 'I'))
                        {
                            iRet = thePLCCore.fnLDNotAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);

                            iStackDepth++;
                        }// CMP
                        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                        else if ((sCOMMAND[0][0] == 'C') && (sCOMMAND[0][1] == 'M') && (sCOMMAND[0][2] == 'P'))
                        {
                            iRet = thePLCCore.fnCMPAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);
                            if (iStackDepth > 0)
                            {
                                cClearStack = Convert.ToChar(0x01);
                            }
                        }// DMOV
                        else if ((sCOMMAND[0][0] == 'D') && (sCOMMAND[0][1] == 'M') && (sCOMMAND[0][2] == 'O') && (sCOMMAND[0][3] == 'V'))
                        {
                            thePLCCore.fnMOVAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);
                            if (iStackDepth > 0)
                            {
                                cClearStack = Convert.ToChar(0x01);
                            }
                        }// LDP
                        else if ((sCOMMAND[0][0] == 'L') && (sCOMMAND[0][1] == 'D') && (sCOMMAND[0][2] == 'P'))
                        {
                            if (cClearStack == 0x01)
                            {
                                iStackDepth--;

                                cClearStack = Convert.ToChar(0x00);
                            }
                            thePLCCore.fnLDPAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);

                            iStackDepth++;
                        }// DSUB
                        else if ((sCOMMAND[0][0] == 'D') && (sCOMMAND[0][1] == 'S') && (sCOMMAND[0][2] == 'U') && (sCOMMAND[0][3] == 'B'))
                        {
                            thePLCCore.fnDSUBAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);

                            if (iStackDepth > 0)
                            {
                                cClearStack = Convert.ToChar(0x01);
                            }
                        }                                                            // DIVR
                        else if ((sCOMMAND[0][0] == 'D') && (sCOMMAND[0][1] == 'I') && (sCOMMAND[0][2] == 'V') && (sCOMMAND[0][3] == 'R'))
                        {
                            thePLCCore.fnDIVRAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);

                            if (iStackDepth > 0)
                            {
                                cClearStack = Convert.ToChar(0x01);
                            }
                        }// DADD
                        else if ((sCOMMAND[0][0] == 'D') && (sCOMMAND[0][1] == 'A') && (sCOMMAND[0][2] == 'D') && (sCOMMAND[0][3] == 'D'))
                        {
                            thePLCCore.fnDADDAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);

                            if (iStackDepth > 0)
                            {
                                cClearStack = Convert.ToChar(0x01);
                            }
                        }// DMUL
                        else if ((sCOMMAND[0][0] == 'D') && (sCOMMAND[0][1] == 'M') && (sCOMMAND[0][2] == 'U') && (sCOMMAND[0][3] == 'L'))
                        {
                            thePLCCore.fnDMULAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);

                            if (iStackDepth > 0)
                            {
                                cClearStack = Convert.ToChar(0x01);
                            }
                        }
                        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                        // AND
                        else if ((sCOMMAND[0][0] == 'A') && (sCOMMAND[0][1] == 'N') && (sCOMMAND[0][2] == 'D'))
                        {
                            iRet = thePLCCore.fnANDAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);
                        } // ANI
                        else if ((sCOMMAND[0][0] == 'A') && (sCOMMAND[0][1] == 'N') && (sCOMMAND[0][2] == 'I'))
                        {
                            iRet = thePLCCore.fnANDNotAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);
                        } // OR
                        else if ((sCOMMAND[0][0] == 'O') && (sCOMMAND[0][1] == 'R') && (sCOMMAND[0].Length == 2))
                        {
                            iRet = thePLCCore.fnORAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);
                        } // ORI
                        else if ((sCOMMAND[0][0] == 'O') && (sCOMMAND[0][1] == 'R') && (sCOMMAND[0][2] == 'I'))
                        {
                            iRet = thePLCCore.fnORNotAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);
                        } // ANB
                        else if ((sCOMMAND[0][0] == 'A') && (sCOMMAND[0][1] == 'N') && (sCOMMAND[0][2] == 'B'))
                        {
                            iRet = thePLCCore.fnANBAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);

                            iStackDepth--;
                        } // ORB
                        else if ((sCOMMAND[0][0] == 'O') && (sCOMMAND[0][1] == 'R') && (sCOMMAND[0][2] == 'B'))
                        {
                            iRet = thePLCCore.fnORBAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);

                            iStackDepth--;
                        } // SET
                        else if ((sCOMMAND[0][0] == 'S') && (sCOMMAND[0][1] == 'E') && (sCOMMAND[0][2] == 'T'))
                        {
                            iRet = thePLCCore.fnSETAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);

                            if (iStackDepth > 0)
                            {
                                cClearStack = Convert.ToChar(0x01);
                            }
                        } // RST
                        else if ((sCOMMAND[0][0] == 'R') && (sCOMMAND[0][1] == 'S') && (sCOMMAND[0][2] == 'T'))
                        {
                            thePLCCore.fnRSTAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);

                            if (iStackDepth > 0)
                            {
                                cClearStack = Convert.ToChar(0x01);
                            }
                        } // OUT
                        else if ((sCOMMAND[0][0] == 'O') && (sCOMMAND[0][1] == 'U') && (sCOMMAND[0][2] == 'T'))
                        {
                            thePLCCore.fnOUTAndCompute(sCOMMAND, pPLC_OBJ, ref iStackDepth);

                            if (iStackDepth > 0)
                            {
                                cClearStack = Convert.ToChar(0x01);
                            }
                        }
                        else if ((sCOMMAND[0][0] == 'E') && (sCOMMAND[0][1] == 'N') && (sCOMMAND[0][2] == 'D'))
                        {
                            ;
                        }
                        else
                        {
                            ;
                        }

                        FnWriteM();
                    }
                } while (bProgEnd);

                thePLCCore.fnWriteOutput();

                Thread.Sleep(60);
            }

            thePLCCore.fnRESETAll();

            thePLCCore.fnWriteOutput();
        }