public static S7DataRow GetDataRowWithAddress(S7DataRow startRow, ByteBitAddress address, bool dontLookInTemp = false)
        {
            IList <IDataRow> col = startRow.Children;

            if (dontLookInTemp)
            {
                col = startRow.Children.Where(itm => itm.Name != "TEMP").ToList();
            }

            for (int n = 0; n < col.Count; n++)
            {
                var s7DataRow = col[n];
                if (n == col.Count - 1 || address < ((S7DataRow)col[n + 1]).BlockAddress)
                {
                    if (((S7DataRow)s7DataRow).BlockAddress == address && (s7DataRow.Children == null || s7DataRow.Children.Count == 0))
                    {
                        return((S7DataRow)s7DataRow);
                    }
                    var tmp = GetDataRowWithAddress(((S7DataRow)s7DataRow), address);
                    if (tmp != null)
                    {
                        return(tmp);
                    }
                }
            }
            return(null);
        }
Example #2
0
 public static ByteBitAddress GetNextBitAddress(ByteBitAddress tmp)
 {
     if (tmp.BitAddress > 7)
     {
         throw new Exception("Unpossible ByteBitAddress specified");
     }
     if (tmp.BitAddress == 7)
     {
         return(new ByteBitAddress(tmp.ByteAddress + 1, 0));
     }
     else
     {
         return(new ByteBitAddress(tmp.ByteAddress, tmp.BitAddress + 1));
     }
 }
Example #3
0
 public static S7DataRow GetDataRowWithAddress(S7DataRow startRow, ByteBitAddress address)
 {
     for (int n = 0; n < startRow.Children.Count; n++)
     //foreach (var s7DataRow in startRow.Children)
     {
         var s7DataRow = startRow.Children[n];
         if (n == startRow.Children.Count - 1 || address < startRow.Children[n + 1].BlockAddress)
         {
             if (s7DataRow.BlockAddress == address && (s7DataRow.Children == null || s7DataRow.Children.Count == 0))
             {
                 return(s7DataRow);
             }
             var tmp = GetDataRowWithAddress(s7DataRow, address);
             if (tmp != null)
             {
                 return(tmp);
             }
         }
     }
     return(null);
 }
Example #4
0
        /// <summary>
        /// This function is used, when a Member is added or Removed, or the Type is changed so the the Addresses are recalculated!
        /// </summary>
        internal override void ClearBlockAddress()
        {
            if (_BlockAddress != null || _parentOldAddress != null)
            {
                _BlockAddress     = null;
                _parentOldAddress = null;
                //_structureLength = null;

                if (Children != null)
                {
                    foreach (S7DataRow plcDataRow in Children)
                    {
                        plcDataRow.ClearBlockAddress();
                    }
                }
                if (Parent != null)
                {
                    ((S7DataRow)Parent).ClearBlockAddress();
                }
            }
        }
        public static DataBlockRow GetDataRowWithAddress(DataBlockRow startRow, ByteBitAddress address, bool dontLookInTemp = false)
        {
            IList <IDataRow> col = startRow.Children;

            if (dontLookInTemp)
            {
                col = startRow.Children.Where(itm => itm.Name != "TEMP").ToList();
            }

            for (int n = 0; n < col.Count; n++)
            {
                var s7DataRow = col[n];
                if (n == col.Count - 1 || address < ((DataBlockRow)col[n + 1]).BlockAddress)
                {
                    if (((DataBlockRow)s7DataRow).BlockAddress == address && (s7DataRow.Children == null || s7DataRow.Children.Count == 0))
                    {
                        return((DataBlockRow)s7DataRow);
                    }
                    //fix for finding the absoluteaddress of a string
                    var stringDataRow = (TiaAndSTep7DataBlockRow)s7DataRow;
                    if (stringDataRow.DataType == S7DataRowType.STRING)
                    {
                        int firstByte = stringDataRow.BlockAddress.ByteAddress;
                        int lastByte  = firstByte + stringDataRow.ByteLength;
                        //If is a string the calling logic has determine which character is bein accessed
                        if (address.ByteAddress >= (firstByte) && address.ByteAddress <= lastByte)
                        {
                            return(stringDataRow);
                        }
                    }
                    var tmp = GetDataRowWithAddress(((DataBlockRow)s7DataRow), address);
                    if (tmp != null)
                    {
                        return(tmp);
                    }
                }
            }
            return(null);
        }
 internal abstract ByteBitAddress FillBlockAddresses(ByteBitAddress startAddr);
        public static DataBlockRow GetDataRowWithAddress(IEnumerable<DataBlockRow> startRows, ByteBitAddress address)
        {
            foreach (var s7DataRow in startRows)
            {
                var row = GetDataRowWithAddress(s7DataRow, address);
                if (row != null)
                    return row;
            }

            return null;
        }
        public static DataBlockRow GetDataRowWithAddress(DataBlockRow startRow, ByteBitAddress address, bool dontLookInTemp = false)
        {
            IList<IDataRow> col = startRow.Children;
            if (dontLookInTemp)
                col = startRow.Children.Where(itm => itm.Name != "TEMP").ToList();

            for (int n = 0; n < col.Count; n++)
            {
                var s7DataRow = col[n];
                if (n == col.Count - 1 || address < ((DataBlockRow)col[n + 1]).BlockAddress)
                {
                    if (((DataBlockRow)s7DataRow).BlockAddress == address && (s7DataRow.Children == null || s7DataRow.Children.Count == 0))
                        return ((DataBlockRow)s7DataRow);
                    //fix for finding the absoluteaddress of a string
                    var stringDataRow = (TiaAndSTep7DataBlockRow)s7DataRow;
                    if (stringDataRow.DataType == S7DataRowType.STRING)
                    {
                        int firstByte = stringDataRow.BlockAddress.ByteAddress;
                        int lastByte = firstByte + stringDataRow.ByteLength;
                        //If is a string the calling logic has determine which character is bein accessed
                        if (address.ByteAddress >= (firstByte) && address.ByteAddress <= lastByte)
                            return stringDataRow;
                    }
                    var tmp = GetDataRowWithAddress(((DataBlockRow)s7DataRow), address);
                    if (tmp != null)
                        return tmp;
                }
            }
            return null;
        }
 internal abstract ByteBitAddress FillBlockAddresses(ByteBitAddress startAddr);
        /// </summary>
        internal override void ClearBlockAddress()
        {
            if (_BlockAddress != null || _parentOldAddress != null)
            {
                _BlockAddress = null;
                _parentOldAddress = null;
                //_structureLength = null;

                if (Children != null)
                    foreach (TIADataRow plcDataRow in Children)
                    {
                        plcDataRow.ClearBlockAddress();
                    }
                if (Parent != null)
                    ((TIADataRow)Parent).ClearBlockAddress();
            }
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            HMIGENOBJECTSLib.HMIGO HMIGOObject = null;
            try
            {
                HMIGOObject = new HMIGENOBJECTSLib.HMIGO();
            }
            catch (Exception ex)
            {
                MessageBox.Show("The WinCC Object could not be created!\n\n Error:" + ex.Message);
            }

            try
            {
                foreach (var projectBlockInfo in ConvertBlocks)
                {
                    S7DataBlock myDB = (S7DataBlock)projectBlockInfo.GetBlock();


                    int cnt = 0;

                    if (myDB.Structure != null && myDB.Structure.Children != null)
                    {
                        cnt = myDB.Structure.Children[myDB.Structure.Children.Count - 1].NextBlockAddress.ByteAddress;
                    }

                    string varname = "STOERUNGEN_DB" + myDB.BlockNumber;

                    for (int n = 0; n < cnt / 2; n++)
                    {
                        try
                        {
                            HMIGOObject.CreateTag(varname + "_" + (n + 1).ToString(),
                                                  HMIGENOBJECTSLib.HMIGO_TAG_TYPE.TAG_UNSIGNED_16BIT_VALUE,
                                                  txtConnectionName.Text,
                                                  "DB" + myDB.BlockNumber + ",DD" + (n * 2).ToString(), "Stoerungen");
                        }
                        catch (COMException ex)
                        {
                            if (ex.ErrorCode != -2147196408)
                            {
                                throw ex;
                            }
                        }
                    }

                    string errors = "";

                    int errNr = Convert.ToInt32(txtStartErrorNumber.Text);

                    foreach (S7DataRow plcDataRow in S7DataRow.GetChildrowsAsList(myDB.Structure))
                    // myDB.GetRowsAsList())
                    {
                        if (plcDataRow.DataType == S7DataRowType.BOOL)
                        {
                            ByteBitAddress akAddr = plcDataRow.BlockAddress;
                            int            varnr  = (akAddr.ByteAddress / 2) + 1;

                            int bitnr = akAddr.BitAddress;
                            if (akAddr.ByteAddress % 2 == 0)
                            {
                                bitnr += 8;
                            }

                            string stoeTxt   = "";
                            string stoeOrt   = "";
                            string stoeTxtEn = "";

                            stoeTxt = plcDataRow.Comment;
                            if (stoeTxt.Contains(";"))
                            {
                                stoeTxt = stoeTxt.Split(';')[1];
                                stoeOrt = stoeTxt.Split(';')[0];
                            }

                            if (chkFixedErrorNumber.IsChecked.Value)
                            {
                                errNr = Convert.ToInt32(txtStartErrorNumber.Text) + akAddr.ByteAddress * 8 +
                                        akAddr.BitAddress;
                            }

                            try
                            {
                                HMIGOObject.CreateSingleAlarm(errNr,
                                                              HMIGENOBJECTSLib.HMIGO_SINGLE_ALARM_CLASS_ID.
                                                              SINGLE_ALARM_ERROR, 1, stoeTxt,
                                                              varname + "_" + varnr.ToString(), bitnr);
                                HMIGOObject.SingleAlarmInfoText = stoeTxt;
                                HMIGOObject.SingleAlarmText2ID  = stoeOrt;
                                HMIGOObject.CommitSingleAlarm();
                            }
                            catch (System.Runtime.InteropServices.COMException ex)
                            {
                                if (ex.ErrorCode != -2147467259)
                                {
                                    throw ex;
                                }
                            }

                            //errors += "\"D\"\t\"" + errNr.ToString() + "\"\t\"Alarms\"\t\"" + varname + "\"\t\"" + bitnr.ToString() + "\"\t\t\t\t\t\t\"0\"\t\"de-DE=" + stoeTxt + "\"\t\"en-US=" + stoeTxtEn + "\"\t\"de-DE=\"" + "\r\n";
                            if (!chkFixedErrorNumber.IsChecked.Value)
                            {
                                errNr++;
                            }
                        }
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                if (ex.ErrorCode == -2147195889)
                {
                    MessageBox.Show("Error: The Connection Name you specified does not exist!");
                }
                else
                {
                    MessageBox.Show("Error: " + ex.Message);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }
Example #12
0
        internal ByteBitAddress FillBlockAddresses(ByteBitAddress startAddr)
        {
            if (isRootBlock && this.Name == "TEMP")
            {
                _BlockAddress = new ByteBitAddress(0, 0);
                startAddr     = new ByteBitAddress(0, 0);
            }

            ByteBitAddress akAddr = new ByteBitAddress(startAddr);

            if (Parent != null && startAddr == null)
            {
                Parent.FillBlockAddresses(null);
            }
            else
            {
                //Create a function wich fills in the Block address for all Subitems...
                if (Children != null || _datatype != S7DataRowType.STRUCT)
                {
                    if (akAddr.BitAddress != 0)
                    {
                        akAddr.ByteAddress++;
                    }
                    if (akAddr.ByteAddress % 2 != 0)
                    {
                        akAddr.ByteAddress++;
                    }

                    bool lastRowWasArrayOrStruct = false;

                    //int structlen = 0;
                    foreach (S7DataRow plcDataRow in Children)
                    {
                        if (akAddr.BitAddress != 0 && (plcDataRow._datatype != S7DataRowType.BOOL || plcDataRow.IsArray || plcDataRow.WasFirstInArray || (lastRowWasArrayOrStruct && !plcDataRow.WasArray && !plcDataRow.WasFirstInArray)))
                        {
                            akAddr.BitAddress = 0;
                            akAddr.ByteAddress++;
                        }
                        if (akAddr.ByteAddress % 2 != 0 && ((plcDataRow._datatype != S7DataRowType.BOOL && plcDataRow._datatype != S7DataRowType.BYTE && plcDataRow._datatype != S7DataRowType.CHAR) || plcDataRow.IsArray || plcDataRow.WasFirstInArray || (lastRowWasArrayOrStruct && !plcDataRow.WasArray && !plcDataRow.WasFirstInArray)))
                        {
                            if (!(this.PlcBlock is Step5.S5DataBlock))
                            {
                                akAddr.ByteAddress++;
                            }
                        }
                        if (plcDataRow.Children != null && plcDataRow.Children.Count > 0)
                        {
                            plcDataRow._BlockAddress = new ByteBitAddress(akAddr);

                            plcDataRow.FillBlockAddresses(akAddr);
                            akAddr.ByteAddress += plcDataRow.ByteLength;
                            //if (!plcDataRow.IsArray)
                            //    akAddr = plcDataRow.FillBlockAddresses(akAddr);
                            //else
                            //    akAddr = plcDataRow.FillBlockAddresses(akAddr);
                            if (akAddr.BitAddress != 0)
                            {
                                akAddr.BitAddress = 0;
                                akAddr.ByteAddress++;
                            }
                            if (akAddr.ByteAddress % 2 != 0)
                            {
                                akAddr.ByteAddress++;
                            }

                            plcDataRow._NextBlockAddress = new ByteBitAddress(akAddr);
                        }
                        else
                        {
                            plcDataRow._BlockAddress = new ByteBitAddress(akAddr);
                            if (plcDataRow._datatype == S7DataRowType.BOOL && !plcDataRow.IsArray)
                            {
                                akAddr = Helper.GetNextBitAddress(akAddr);
                            }
                            else
                            {
                                akAddr.BitAddress   = 0;
                                akAddr.ByteAddress += plcDataRow.ByteLength;
                            }
                            plcDataRow._NextBlockAddress = new ByteBitAddress(akAddr);
                        }
                        //structlen += plcDataRow.ByteLength;

                        lastRowWasArrayOrStruct = plcDataRow.WasArray;
                    }
                    //this. = structlen;
                }
            }
            return(akAddr);
        }
        public DataBlockRow GetDataRowWithAddress(ByteBitAddress address)
        {
            var allRw = this.GetArrayExpandedStructure();

            return(TiaAndSTep7DataBlockRow.GetDataRowWithAddress((TiaAndSTep7DataBlockRow)allRw, address));
        }
Example #14
0
 public AddressClass(ByteBitAddress address)
     : base(address)
 {
 }
 public S7DataRow GetDataRowWithAddress(ByteBitAddress address)
 {
     var allRw = this.GetArrayExpandedStructure();
     return S7DataRow.GetDataRowWithAddress((S7DataRow)allRw, address);
 }
Example #16
0
        internal override ByteBitAddress FillBlockAddresses(ByteBitAddress startAddr)
        {
            if (isRootBlock && this.Name == "TEMP")
            {
                _BlockAddress = new ByteBitAddress(0, 0);
                startAddr     = new ByteBitAddress(0, 0);
            }

            ByteBitAddress akAddr = new ByteBitAddress(startAddr);

            if (Parent != null && startAddr == null)
            {
                ((S7DataRow)Parent).FillBlockAddresses(null);
            }
            else
            {
                //Create a function wich fills in the Block address for all Subitems...
                if (Children != null || _datatype != S7DataRowType.STRUCT)
                {
                    if (akAddr.BitAddress != 0)
                    {
                        akAddr.ByteAddress++;
                    }
                    if (akAddr.ByteAddress % 2 != 0)
                    {
                        akAddr.ByteAddress++;
                    }

                    bool lastRowWasArrayOrStruct = false;

                    //int structlen = 0;
                    foreach (S7DataRow plcDataRow in Children)
                    {
                        if (akAddr.BitAddress != 0 && plcDataRow._datatype == S7DataRowType.BOOL && plcDataRow.WasArray && !plcDataRow.WasFirstInArray && plcDataRow.WasNextHigherIndex)
                        {
                            akAddr.BitAddress = 0;
                            akAddr.ByteAddress++;
                        }
                        else if (akAddr.BitAddress != 0 && (plcDataRow._datatype != S7DataRowType.BOOL || plcDataRow.IsArray || plcDataRow.WasFirstInArray || (lastRowWasArrayOrStruct && !plcDataRow.WasArray && !plcDataRow.WasFirstInArray)))
                        {
                            akAddr.BitAddress = 0;
                            akAddr.ByteAddress++;
                        }


                        if (akAddr.ByteAddress % 2 != 0 && ((plcDataRow._datatype != S7DataRowType.BOOL && plcDataRow._datatype != S7DataRowType.BYTE && plcDataRow._datatype != S7DataRowType.CHAR) || plcDataRow.IsArray || plcDataRow.WasFirstInArray || (lastRowWasArrayOrStruct && !plcDataRow.WasArray && !plcDataRow.WasFirstInArray)))
                        {
                            if (!(this.PlcBlock is Step5.S5DataBlock))
                            {
                                akAddr.ByteAddress++;
                            }
                        }


                        if (plcDataRow.Children != null && plcDataRow.Children.Count > 0)
                        {
                            plcDataRow._BlockAddress = new ByteBitAddress(akAddr);

                            var useAddr = akAddr;
                            if (plcDataRow.Parent != null && ((S7DataRow)plcDataRow.Parent).isInOut)
                            {
                                useAddr = new ByteBitAddress(0, 0);
                            }
                            plcDataRow.FillBlockAddresses(useAddr);

                            //Struct or UDT are Handeled as Pointer in IN_OUT so only Increase about 6 Byte
                            //if (plcDataRow.Parent != null && ((S7DataRow) plcDataRow.Parent).isInOut)
                            akAddr.ByteAddress += plcDataRow.ByteLength;
                            //if (!plcDataRow.IsArray)
                            //    akAddr = plcDataRow.FillBlockAddresses(akAddr);
                            //else
                            //    akAddr = plcDataRow.FillBlockAddresses(akAddr);
                            if (akAddr.BitAddress != 0)
                            {
                                akAddr.BitAddress = 0;
                                akAddr.ByteAddress++;
                            }
                            if (akAddr.ByteAddress % 2 != 0)
                            {
                                akAddr.ByteAddress++;
                            }

                            plcDataRow._NextBlockAddress = new ByteBitAddress(akAddr);
                        }
                        else
                        {
                            plcDataRow._BlockAddress = new ByteBitAddress(akAddr);
                            if (plcDataRow._datatype == S7DataRowType.BOOL && !plcDataRow.IsArray)
                            {
                                akAddr = Helper.GetNextBitAddress(akAddr);
                            }
                            else
                            {
                                akAddr.BitAddress   = 0;
                                akAddr.ByteAddress += plcDataRow.ByteLength;
                            }
                            plcDataRow._NextBlockAddress = new ByteBitAddress(akAddr);
                        }

                        //structlen += plcDataRow.ByteLength;

                        lastRowWasArrayOrStruct = plcDataRow.WasArray;
                    }
                    //this. = structlen;
                }
            }
            return(akAddr);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string errors = "";
            string tags   = "";

            foreach (var projectBlockInfo in ConvertBlocks)
            {
                S7DataBlock myDB = (S7DataBlock)projectBlockInfo.GetBlock();

                int cnt = 0;

                if (myDB.Structure != null && myDB.Structure.Children != null)
                {
                    cnt = myDB.Structure.Children[myDB.Structure.Children.Count - 1].NextBlockAddress.ByteAddress;
                }

                string varname = "STOERUNGEN_DB" + myDB.BlockNumber;

                tags += varname + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBW 0;Int;;" +
                        ((cnt - 2) / 2).ToString() + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";

                int errNr = Convert.ToInt32(txtStartErrorNumber.Text);

                foreach (S7DataRow plcDataRow in S7DataRow.GetChildrowsAsList(myDB.Structure))
                // myDB.GetRowsAsList())
                {
                    if (plcDataRow.DataType == S7DataRowType.BOOL)
                    {
                        ByteBitAddress akAddr = plcDataRow.BlockAddress;

                        int bitnr = (akAddr.ByteAddress / 2) * 16 + akAddr.BitAddress; //akAddr.BitAddress;
                        if (akAddr.ByteAddress % 2 == 0)
                        {
                            bitnr += 8;
                        }

                        string stoeTxt   = "";
                        string stoeTxtEn = "";

                        stoeTxt = plcDataRow.Comment;
                        if (stoeTxt.Contains(";"))
                        {
                            stoeTxt = "Störort: " + stoeTxt.Split(';')[0] + ", " + stoeTxt.Split(';')[1];
                        }

                        if (chkFixedErrorNumber.IsChecked.Value)
                        {
                            errNr = Convert.ToInt32(txtStartErrorNumber.Text) + akAddr.ByteAddress * 8 + akAddr.BitAddress;
                        }
                        errors += "\"D\"\t\"" + errNr.ToString() + "\"\t\"Alarms\"\t\"" + varname + "\"\t\"" +
                                  bitnr.ToString() + "\"\t\t\t\t\t\t\"0\"\t\"de-DE=" + stoeTxt + "\"\t\"en-US=" +
                                  stoeTxtEn + "\"\t\"de-DE=\"" + "\r\n";
                        if (!chkFixedErrorNumber.IsChecked.Value)
                        {
                            errNr++;
                        }
                    }
                }
            }

            FolderBrowserDialog fldDlg = null;

            fldDlg             = new FolderBrowserDialog();
            fldDlg.Description = "Destination Diretory for Alarms.csv and Tags.csv!";
            if (fldDlg.ShowDialog() == DialogResult.OK)
            {
                System.IO.StreamWriter swr;

                swr = new System.IO.StreamWriter(fldDlg.SelectedPath + "\\Alarms.csv");
                swr.Write(errors);
                swr.Close();

                swr = new System.IO.StreamWriter(fldDlg.SelectedPath + "\\Tags.csv");
                swr.Write(tags.Replace(";", "\t"));
                swr.Close();
            }
        }
        public static S7DataRow GetDataRowWithAddress(S7DataRow startRow, ByteBitAddress address, bool dontLookInTemp = false)
        {
            IList<IDataRow> col = startRow.Children;
            if (dontLookInTemp)
                col = startRow.Children.Where(itm => itm.Name != "TEMP").ToList();

            for (int n = 0; n < col.Count; n++)
            {
                var s7DataRow = col[n];
                if (n == col.Count - 1 || address < ((S7DataRow)col[n + 1]).BlockAddress)
                {
                    if (((S7DataRow)s7DataRow).BlockAddress == address && (s7DataRow.Children == null || s7DataRow.Children.Count == 0))
                        return ((S7DataRow)s7DataRow);
                    var tmp = GetDataRowWithAddress(((S7DataRow)s7DataRow), address);
                    if (tmp != null)
                        return tmp;
                }
            }
            return null;
        }
        internal override ByteBitAddress FillBlockAddresses(ByteBitAddress startAddr)
        {
            if (isRootBlock && this.Name == "TEMP")
            {
                _BlockAddress = new ByteBitAddress(0, 0);
                startAddr = new ByteBitAddress(0, 0);
            }

            ByteBitAddress akAddr = new ByteBitAddress(startAddr);
            if (Parent != null && startAddr == null)
                ((TIADataRow)Parent).FillBlockAddresses(null);
            else
            {
                //Create a function wich fills in the Block address for all Subitems...
                if (Children != null || _datatype != S7DataRowType.STRUCT)
                {
                    if (akAddr.BitAddress != 0)
                        akAddr.ByteAddress++;
                    if (akAddr.ByteAddress % 2 != 0)
                        akAddr.ByteAddress++;

                    bool lastRowWasArrayOrStruct = false;

                    //int structlen = 0;
                    foreach (TIADataRow plcDataRow in Children)
                    {

                        if (akAddr.BitAddress != 0 && plcDataRow._datatype == S7DataRowType.BOOL && plcDataRow.WasArray && !plcDataRow.WasFirstInArray && plcDataRow.WasNextHigherIndex)
                        {
                            akAddr.BitAddress = 0;
                            akAddr.ByteAddress++;
                        }
                        else if (akAddr.BitAddress != 0 && (plcDataRow._datatype != S7DataRowType.BOOL || plcDataRow.IsArray || plcDataRow.WasFirstInArray || (lastRowWasArrayOrStruct && !plcDataRow.WasArray && !plcDataRow.WasFirstInArray)))
                        {
                            akAddr.BitAddress = 0;
                            akAddr.ByteAddress++;
                        }


                        if (akAddr.ByteAddress % 2 != 0 && ((plcDataRow._datatype != S7DataRowType.BOOL && plcDataRow._datatype != S7DataRowType.BYTE && plcDataRow._datatype != S7DataRowType.CHAR) || plcDataRow.IsArray || plcDataRow.WasFirstInArray || (lastRowWasArrayOrStruct && !plcDataRow.WasArray && !plcDataRow.WasFirstInArray)))
                            if (!(this.PlcBlock is Step5.S5DataBlock))
                            {
                                akAddr.ByteAddress++;
                            }


                        if (plcDataRow.Children != null && plcDataRow.Children.Count > 0)
                        {
                            plcDataRow._BlockAddress = new ByteBitAddress(akAddr);

                            var useAddr = akAddr;
                            if (plcDataRow.Parent != null && ((TIADataRow)plcDataRow.Parent).isInOut)
                                useAddr = new ByteBitAddress(0, 0);
                            plcDataRow.FillBlockAddresses(useAddr);

                            //Struct or UDT are Handeled as Pointer in IN_OUT so only Increase about 6 Byte
                            //if (plcDataRow.Parent != null && ((S7DataRow) plcDataRow.Parent).isInOut)
                            akAddr.ByteAddress += plcDataRow.ByteLength;
                            //if (!plcDataRow.IsArray)
                            //    akAddr = plcDataRow.FillBlockAddresses(akAddr);
                            //else
                            //    akAddr = plcDataRow.FillBlockAddresses(akAddr);
                            if (akAddr.BitAddress != 0)
                            {
                                akAddr.BitAddress = 0;
                                akAddr.ByteAddress++;
                            }
                            if (akAddr.ByteAddress % 2 != 0)
                                akAddr.ByteAddress++;

                            plcDataRow._NextBlockAddress = new ByteBitAddress(akAddr);
                        }
                        else
                        {
                            plcDataRow._BlockAddress = new ByteBitAddress(akAddr);
                            if (plcDataRow._datatype == S7DataRowType.BOOL && !plcDataRow.IsArray)
                                akAddr = Helper.GetNextBitAddress(akAddr);
                            else
                            {
                                akAddr.BitAddress = 0;
                                akAddr.ByteAddress += plcDataRow.ByteLength;
                            }
                            plcDataRow._NextBlockAddress = new ByteBitAddress(akAddr);
                        }

                        //structlen += plcDataRow.ByteLength;

                        lastRowWasArrayOrStruct = plcDataRow.WasArray;
                    }
                    //this. = structlen;
                }
            }
            return akAddr;
        }
 public DataBlockRow GetDataRowWithAddress(ByteBitAddress address)
 {
     var allRw = this.GetArrayExpandedStructure();
     return TiaAndSTep7DataBlockRow.GetDataRowWithAddress((TiaAndSTep7DataBlockRow)allRw, address);
 }
        public static DataBlockRow GetDataRowWithAddress(IEnumerable <DataBlockRow> startRows, ByteBitAddress address)
        {
            foreach (var s7DataRow in startRows)
            {
                var row = GetDataRowWithAddress(s7DataRow, address);
                if (row != null)
                {
                    return(row);
                }
            }

            return(null);
        }
Example #22
0
        public S7DataRow GetDataRowWithAddress(ByteBitAddress address)
        {
            var allRw = this.GetArrayExpandedStructure();

            return(S7DataRow.GetDataRowWithAddress((S7DataRow)allRw, address));
        }
        public static void ReplaceStaticAccess(S7FunctionBlock myFct, S7ProgrammFolder myFld, S7ConvertingOptions myOpt)
        {
            if (myOpt.ReplaceDIAccessesWithSymbolNames && myFct.BlockType == PLCBlockType.FB)
            {
                List <FunctionBlockRow> retVal   = new List <FunctionBlockRow>();
                List <FunctionBlockRow> tempList = new List <FunctionBlockRow>();

                bool LargeAccess = false;
                int  add_adresse = 0;

                foreach (var functionBlockRow in myFct.AWLCode)
                {
                    if (functionBlockRow.Command == "TAR2")
                    {
                        tempList.Add(functionBlockRow);
                        LargeAccess = true;
                    }
                    else if (functionBlockRow.Command == "+AR2" && LargeAccess)
                    {
                        tempList.Add(functionBlockRow);
                        add_adresse += Convert.ToInt32(Convert.ToDouble(((S7FunctionBlockRow)functionBlockRow).Parameter.Substring(2), new NumberFormatInfo()
                        {
                            NumberDecimalSeparator = "."
                        }));
                    }
                    else if (((S7FunctionBlockRow)functionBlockRow).Parameter.Contains("[AR2,P#") && ((S7FunctionBlockRow)functionBlockRow).Parameter.Substring(0, 2) == "DI" && !LargeAccess)
                    {
                        string         para   = ((S7FunctionBlockRow)functionBlockRow).Parameter;
                        ByteBitAddress adr    = new ByteBitAddress(para.Substring(10, para.Length - 11));
                        var            parRow = S7DataRow.GetDataRowWithAddress(myFct.Parameter, adr, true);
                        if (parRow != null)
                        {
                            byte[] tmp = ((S7FunctionBlockRow)functionBlockRow).MC7;
                            ((S7FunctionBlockRow)functionBlockRow).Parameter = "#" + parRow.StructuredName.Substring(parRow.StructuredName.IndexOf('.') + 1);
                            ((S7FunctionBlockRow)functionBlockRow).MC7       = tmp;
                        }
                        retVal.Add(functionBlockRow);
                    }
                    else if (((S7FunctionBlockRow)functionBlockRow).Parameter.Contains("[AR2,P#") && ((S7FunctionBlockRow)functionBlockRow).Parameter.Substring(0, 2) == "DI" && LargeAccess)
                    {
                        /*
                         * string para = ((S7FunctionBlockRow)functionBlockRow).Parameter;
                         * ByteBitAddress adr = new ByteBitAddress(para.Substring(10, para.Length - 11));
                         * adr.ByteAddress += add_adresse;
                         * var parRow = S7DataRow.GetDataRowWithAddress(myFct.Parameter, adr);
                         * if (parRow != null)
                         * {
                         *  byte[] tmp = ((S7FunctionBlockRow)functionBlockRow).MC7;
                         *  ((S7FunctionBlockRow)functionBlockRow).Parameter = "#" + parRow.StructuredName;
                         *  ((S7FunctionBlockRow)functionBlockRow).MC7 = tmp;
                         * }
                         * retVal.Add(functionBlockRow);
                         */
                        LargeAccess = false;
                    }
                    else if (functionBlockRow.Command == "LAR2")
                    {
                    }
                    else
                    {
                        LargeAccess = false;
                        retVal.AddRange(tempList);
                        tempList.Clear();
                        retVal.Add(functionBlockRow);
                    }
                }

                myFct.AWLCode = retVal;
            }
        }
Example #24
0
 public static S7DataRow GetDataRowWithAddress(S7DataRow startRow, ByteBitAddress address)
 {
     for (int n = 0; n < startRow.Children.Count;n++)
         //foreach (var s7DataRow in startRow.Children)
         {
             var s7DataRow = startRow.Children[n];
             if (n == startRow.Children.Count - 1 || address < startRow.Children[n + 1].BlockAddress)
             {
                 if (s7DataRow.BlockAddress == address && (s7DataRow.Children == null || s7DataRow.Children.Count == 0))
                     return s7DataRow;
                 var tmp = GetDataRowWithAddress(s7DataRow, address);
                 if (tmp != null)
                     return tmp;
             }
         }
     return null;
 }