コード例 #1
0
ファイル: Helper.cs プロジェクト: pwndubey77/s7-diff-merge
        public static int GetPLCBlockTypeForBlockList(DataTypes.PLCBlockType myTP)
        {
            switch (myTP)
            {
            case DataTypes.PLCBlockType.OB:
                return('8');

            case DataTypes.PLCBlockType.DB:
                return('A');

            case DataTypes.PLCBlockType.SDB:
                return('B');

            case DataTypes.PLCBlockType.FC:
                return('C');

            case DataTypes.PLCBlockType.SFC:
                return('D');

            case DataTypes.PLCBlockType.FB:
                return('E');

            case DataTypes.PLCBlockType.SFB:
                return('F');
            }
            throw new Exception("Unkown PLCBlockType");
        }
コード例 #2
0
        public PLCBlockName(string blockName)
        {
            string tmp   = blockName.ToUpper().Trim().Replace(" ", "");
            string block = "";
            int    nr    = 0;

            //SDB's are the only block types with 3 letter digits
            if (tmp.StartsWith("SDB"))
            {
                block = tmp.Substring(0, 3);
                nr    = Int32.Parse(tmp.Substring(3));
            }
            else
            {
                block = tmp.Substring(0, 2);
                nr    = Int32.Parse(tmp.Substring(2));
            }
            DataTypes.PLCBlockType blk = DataTypes.PLCBlockType.AllBlocks; //Preset with default (in this case invalid) block type

            switch (block)
            {
            case "FC":
                blk = DataTypes.PLCBlockType.FC;
                break;

            case "FB":
                blk = DataTypes.PLCBlockType.FB;
                break;

            case "DB":
                blk = DataTypes.PLCBlockType.DB;
                break;

            case "OB":
                blk = DataTypes.PLCBlockType.OB;
                break;

            case "SDB":
                blk = DataTypes.PLCBlockType.SDB;
                break;
            }
            if (blk == PLCBlockType.AllBlocks)
            {
                throw new NotSupportedException("Unsupported Block type!");
            }
            if (nr < 0)
            {
                throw new NotSupportedException("Unsupported Block number!");
            }
            if (nr > 99999)
            {
                throw new NotSupportedException("Unsupported Block number!");             //Maximum number for requests to S7 plcs is usually 5 digits
            }
            BlockNumber = nr;
            BlockType   = blk;
        }
コード例 #3
0
        //
        internal static S7DataRow GetInterface(byte[] interfaceBytes, byte[] actualvalueBytes, ref List <String> ParaList, DataTypes.PLCBlockType blkTP, bool isInstanceDB, S7Block myBlk)
        {
            S7DataRow parameterRoot   = new S7DataRow("ROOTNODE", S7DataRowType.STRUCT, myBlk);
            S7DataRow parameterIN     = new S7DataRow("IN", S7DataRowType.STRUCT, myBlk);
            S7DataRow parameterOUT    = new S7DataRow("OUT", S7DataRowType.STRUCT, myBlk);
            S7DataRow parameterINOUT  = new S7DataRow("IN_OUT", S7DataRowType.STRUCT, myBlk);
            S7DataRow parameterSTAT   = new S7DataRow("STATIC", S7DataRowType.STRUCT, myBlk);
            S7DataRow parameterTEMP   = new S7DataRow("TEMP", S7DataRowType.STRUCT, myBlk);
            S7DataRow parameterRETVAL = new S7DataRow("RET_VAL", S7DataRowType.STRUCT, myBlk);


            parameterRoot.Add(parameterIN);
            parameterRoot.Add(parameterOUT);
            parameterRoot.Add(parameterINOUT);
            if (blkTP == DataTypes.PLCBlockType.FB || (blkTP == DataTypes.PLCBlockType.DB && isInstanceDB))
            {
                parameterRoot.Add(parameterSTAT);
            }
            if (blkTP != DataTypes.PLCBlockType.DB)
            {
                parameterRoot.Add(parameterTEMP);
            }
            parameterRoot.Add(parameterRETVAL);
            parameterRoot.ReadOnly = true;

            if (blkTP == DataTypes.PLCBlockType.DB && !isInstanceDB)
            {
                parameterRoot = parameterSTAT;
            }

            int INp     = 0;
            int OUTp    = 0;
            int IN_OUTp = 0;
            int STATp   = 0;
            int TEMPp   = 0;
            int StackNr = 1;


            int pos    = 7;
            int Valpos = 0;

            S7DataRow akParameter = parameterRoot;

            ParaList.Clear();

            while (pos <= (interfaceBytes.Length - 2)) // && pos < BD.Length - 2)  //pos<BD.Length-2 was added so SDBs can be converted!! but is this needed?
            {
                object startVal;
                if (Helper.IsWithStartVal(interfaceBytes[pos + 1]))
                {
                    if (interfaceBytes[pos] != 0x10) //Datentyp == Array...
                    {
                        startVal = GetVarTypeVal(interfaceBytes[pos], actualvalueBytes, ref Valpos);
                    }
                    else
                    {
                        Valpos   = Valpos + 6;
                        startVal = GetVarTypeVal(interfaceBytes[pos + 3 + (interfaceBytes[pos + 2] * 4)], actualvalueBytes, ref Valpos);
                    }
                }
                else
                {
                    startVal = null;
                }
                switch (interfaceBytes[pos + 1])
                {
                case 0x01:
                case 0x09:
                {
                    GetVarTypeEN(parameterIN, startVal, interfaceBytes[pos], false, false, "IN" + Convert.ToString(INp), interfaceBytes, actualvalueBytes, ref pos, ref ParaList, ref StackNr, "IN", ref INp, ref Valpos, myBlk);
                }
                break;

                case 0x02:
                case 0x0A:
                {
                    GetVarTypeEN(parameterOUT, startVal, interfaceBytes[pos], false, false, "OUT" + Convert.ToString(OUTp), interfaceBytes, actualvalueBytes, ref pos, ref ParaList, ref StackNr, "OUT", ref OUTp, ref Valpos, myBlk);
                }
                break;

                case 0x03:
                case 0x0b:
                {
                    GetVarTypeEN(parameterINOUT, startVal, interfaceBytes[pos], false, false, "IN_OUT" + Convert.ToString(IN_OUTp), interfaceBytes, actualvalueBytes, ref pos, ref ParaList, ref StackNr, "IN_OUT", ref IN_OUTp, ref Valpos, myBlk);
                }
                break;

                case 0x04:
                case 0x0C:
                {
                    GetVarTypeEN(parameterSTAT, startVal, interfaceBytes[pos], false, false, "STAT" + Convert.ToString(STATp), interfaceBytes, actualvalueBytes, ref pos, ref ParaList, ref StackNr, "STAT", ref STATp, ref Valpos, myBlk);
                }
                break;

                case 0x05:
                {
                    GetVarTypeEN(parameterTEMP, startVal, interfaceBytes[pos], false, false, "TEMP" + Convert.ToString(TEMPp), interfaceBytes, actualvalueBytes, ref pos, ref ParaList, ref StackNr, "TEMP", ref TEMPp, ref Valpos, myBlk);
                }
                break;

                case 0x06:
                {
                    int tmp = 0;
                    GetVarTypeEN(parameterRETVAL, startVal, interfaceBytes[pos], false, false, "RET_VAL", interfaceBytes, actualvalueBytes, ref pos, ref ParaList, ref StackNr, "RET_VAL", ref tmp, ref Valpos, myBlk);
                }
                break;

                    /*default:
                     * RETURNIntf = RETURNIntf + Convert.ToString(pos) + " UNKNOWN: " +
                     *       Convert.ToString(BD[pos + 1]) + " " + Convert.ToString(BD[pos]) + startVal +
                     *       "\r\n";
                     * break;*/
                }
                pos += 2;
            }
            return(parameterRoot);
        }