private void cmdSelectStep7UDT_Click(object sender, EventArgs e)
        {
            S7DataBlock myDB = DotNetSiemensPLCToolBoxLibrary.Projectfiles.SelectProjectPart.SelectUDT();

            if (myDB != null)
            {
                var myLst = S7DataRow.GetChildrowsAsList(((S7DataRow)myDB.GetArrayExpandedStructure(new S7DataBlockExpandOptions()
                {
                    ExpandCharArrays = false
                })));

                dtaSendTabelle.Rows.Clear();
                dtaEmpfangstelegrammAufgeschluesselt.Rows.Clear();

                foreach (var itm in myLst)
                {
                    if (itm.DataType != S7DataRowType.STRUCT && itm.DataType != S7DataRowType.UDT)
                    {
                        dtaSendTabelle.Rows.Add(new object[] { itm.StructuredName, itm.ByteLength });
                        dtaEmpfangstelegrammAufgeschluesselt.Rows.Add(new object[] { itm.StructuredName, itm.ByteLength });
                    }
                }
            }
        }
        private void Button_Click_2(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);
            }

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

                List <S7DataRow> myLst = null;
                if (chkExpandArrays.IsChecked.Value)
                {
                    myLst =
                        S7DataRow.GetChildrowsAsList(myDB.GetArrayExpandedStructure(new S7DataBlockExpandOptions()));
                }
                // ) myDB.GetRowsAsArrayExpandedList(ne);
                else
                {
                    myLst = S7DataRow.GetChildrowsAsList(myDB.Structure); // myDB.GetRowsAsList();
                }
                int cnt = 0;

                try
                {
                    foreach (S7DataRow plcDataRow in myLst)
                    {
                        string tagName = txtTagsPrefix.Text +
                                         plcDataRow.StructuredName.Replace(".", "_").Replace("[", "_").Replace("]", "").
                                         Replace(" ", "").Replace(",", "_");
                        try
                        {
                            switch (plcDataRow.DataType)
                            {
                            case S7DataRowType.BOOL:
                                HMIGOObject.CreateTag(tagName, HMIGENOBJECTSLib.HMIGO_TAG_TYPE.TAG_BINARY_TAG,
                                                      txtConnectionName.Text,
                                                      "DB" + myDB.BlockNumber + ",D" +
                                                      plcDataRow.BlockAddress.ToString(),
                                                      "TAGS_DB" + myDB.BlockNumber);
                                break;

                            case S7DataRowType.INT:
                                HMIGOObject.CreateTag(tagName,
                                                      HMIGENOBJECTSLib.HMIGO_TAG_TYPE.TAG_SIGNED_16BIT_VALUE,
                                                      txtConnectionName.Text,
                                                      "DB" + myDB.BlockNumber + ",DW" +
                                                      plcDataRow.BlockAddress.ByteAddress.ToString(),
                                                      "TAGS_DB" + myDB.BlockNumber);
                                break;

                            case S7DataRowType.DINT:
                                HMIGOObject.CreateTag(tagName,
                                                      HMIGENOBJECTSLib.HMIGO_TAG_TYPE.TAG_SIGNED_32BIT_VALUE,
                                                      txtConnectionName.Text,
                                                      "DB" + myDB.BlockNumber + ",DD" +
                                                      plcDataRow.BlockAddress.ByteAddress.ToString(),
                                                      "TAGS_DB" + myDB.BlockNumber);
                                break;

                            case S7DataRowType.WORD:
                                HMIGOObject.CreateTag(tagName,
                                                      HMIGENOBJECTSLib.HMIGO_TAG_TYPE.TAG_UNSIGNED_16BIT_VALUE,
                                                      txtConnectionName.Text,
                                                      "DB" + myDB.BlockNumber + ",DW" +
                                                      plcDataRow.BlockAddress.ByteAddress.ToString(),
                                                      "TAGS_DB" + myDB.BlockNumber);
                                break;

                            case S7DataRowType.DWORD:
                                HMIGOObject.CreateTag(tagName,
                                                      HMIGENOBJECTSLib.HMIGO_TAG_TYPE.TAG_UNSIGNED_32BIT_VALUE,
                                                      txtConnectionName.Text,
                                                      "DB" + myDB.BlockNumber + ",DD" +
                                                      plcDataRow.BlockAddress.ByteAddress.ToString(),
                                                      "TAGS_DB" + myDB.BlockNumber);
                                break;

                            case S7DataRowType.BYTE:
                                HMIGOObject.CreateTag(tagName,
                                                      HMIGENOBJECTSLib.HMIGO_TAG_TYPE.TAG_UNSIGNED_8BIT_VALUE,
                                                      txtConnectionName.Text,
                                                      "DB" + myDB.BlockNumber + ",DBB" +
                                                      plcDataRow.BlockAddress.ByteAddress.ToString(),
                                                      "TAGS_DB" + myDB.BlockNumber);
                                break;

                            case S7DataRowType.REAL:
                                HMIGOObject.CreateTag(tagName,
                                                      HMIGENOBJECTSLib.HMIGO_TAG_TYPE.
                                                      TAG_FLOATINGPOINT_NUMBER_32BIT_IEEE_754,
                                                      txtConnectionName.Text,
                                                      "DB" + myDB.BlockNumber + ",DD" +
                                                      plcDataRow.BlockAddress.ByteAddress.ToString(),
                                                      "TAGS_DB" + myDB.BlockNumber);
                                break;
                            }
                        }
                        catch (System.Runtime.InteropServices.COMException ex)
                        {
                            if (ex.ErrorCode != -2147196408)
                            {
                                throw ex;
                            }
                            //Tag existiert schoin
                        }
                    }
                }
                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);
                    }
                    return;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message);
                    return;
                }
            }
        }
예제 #3
0
        private void cmdCreateWinCCFlexibleTags_Click(object sender, EventArgs e)
        {
            S7DataBlock myDB = (S7DataBlock)((BlocksOfflineFolder)blkFld).GetBlock((S7ProjectBlockInfo)lstListBox.SelectedItem);

            List <S7DataRow> myLst = null;

            if (chkExpandArrays.Checked)
            {
                myLst = S7DataRow.GetChildrowsAsList(myDB.GetArrayExpandedStructure(new S7DataBlockExpandOptions())); // ) myDB.GetRowsAsArrayExpandedList(ne);
            }
            else
            {
                myLst = S7DataRow.GetChildrowsAsList(myDB.Structure); // myDB.GetRowsAsList();
            }
            string tags = "";


            foreach (S7DataRow plcDataRow in myLst) // myDB.GetRowsAsList())
            {
                string tagName = txtTagsPrefix.Text + plcDataRow.StructuredName.Replace(".", "_").Replace("[", "_").Replace("]", "").Replace(" ", "").Replace(",", "_");

                switch (plcDataRow.DataType)
                {
                case S7DataRowType.BOOL:
                    tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBX " + plcDataRow.BlockAddress.ByteAddress.ToString() + "." + plcDataRow.BlockAddress.BitAddress.ToString() + ";Bool;;" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    break;

                case S7DataRowType.INT:
                    tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBW " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";Int;;" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    break;

                case S7DataRowType.DINT:
                    tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBD " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";DInt;;" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    break;

                case S7DataRowType.WORD:
                    tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBW " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";Word;;" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    break;

                case S7DataRowType.DWORD:
                    tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBD " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";DWord;;" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    break;

                case S7DataRowType.BYTE:
                    tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBB " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";Byte;;" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    break;

                case S7DataRowType.REAL:
                    tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBD " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";Real;;" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    break;

                case S7DataRowType.CHAR:
                    if (plcDataRow.IsArray)
                    {
                        tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBB " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";StringChar;" + plcDataRow.GetArrayLines().ToString() + ";" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    }
                    else
                    {
                        tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBB " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";Char;;" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    }
                    break;

                case S7DataRowType.COUNTER:
                    tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBW " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";Counter;;" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    break;

                case S7DataRowType.DATE:
                    tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBD " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";Date;;" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    break;

                case S7DataRowType.DATE_AND_TIME:
                    tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBB " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";Date and Time;;" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    break;

                case S7DataRowType.S5TIME:
                    tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBW " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";Timer;;" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    break;

                case S7DataRowType.STRING:
                    tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBB " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";String;" + plcDataRow.StringSize.ToString() + ";" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    break;

                case S7DataRowType.TIME:
                    tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBD " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";Time;;" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    break;

                case S7DataRowType.TIME_OF_DAY:
                    tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBD " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";Time of Day;;" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    break;

                case S7DataRowType.TIMER:
                    tags += tagName + ";" + txtConnectionName.Text + ";DB " + myDB.BlockNumber + " DBW " + plcDataRow.BlockAddress.ByteAddress.ToString() + ";Timer;;" + "1" + ";2;1 s;;;;;0;10;0;100;0;;0;\r\n";
                    break;
                }
            }

            FolderBrowserDialog fldDlg = null;

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

                swr = new System.IO.StreamWriter(fldDlg.SelectedPath + "\\Tags.csv");
                swr.Write(tags.Replace(";", "\t"));
                swr.Close();
            }
        }