回复:simotion中的脚本

ihui

  • 帖子

    193
  • 精华

    2
  • 被关注

    4

论坛等级:游士

注册时间:2006-07-01

普通 普通 如何晋级?

发布于 2009-02-20 20:32:46

0楼

要是我知道如何上传文件就不比如此费周折。
下面的例子是将scout中的I/O变量导入到excel文件中。

'-----------------------------------------------------------------------------------------------------------------------
' SIEMENS AG
' (c)Copyright 2006, 2007. All Rights Reserved.
'-----------------------------------------------------------------------------------------------------------------------
' Limitation of liability
' The application examples and the associated documentation contained on this CD are made available without cost. The
' customer receives for the software the non-exclusive, non transferable, free right to use the software; this includes
' the right to change the software, to copy it changed or unchanged, and to combine it with the customer's own software.
' Siemens AG has not subjected the software to the normal system test otherwise usual for software.
' Any liability ?irrespective of the legal reason ?in particular because of software errors or the associated
' documentation or damages resulting from consulting is excluded, unless, for example, because of premeditation, gross
' negligence, risk to life, injury or health, acceptance of suitability guarantee, malicious concealment of a fault or
' a violation of significant contractual obligations, would force liability. A reversal of the burden of proof to the
' customer's disadvantage is thus not included.
' German legal right applies. Place of jurisdiction is Erlangen.
'-----------------------------------------------------------------------------------------------------------------------
' Functionality provided by this s cript (short des cription):
' Writes all IO variables from IO symbol browser to an existing Excel file (see IO_Template.xls).
'-----------------------------------------------------------------------------------------------------------------------
' Status: Released (tested)
'-----------------------------------------------------------------------------------------------------------------------
' File name: Export_IO_to_Excel.txt
' System: SIMOTION
' Version: SIMOTION Scout V4.1
'-----------------------------------------------------------------------------------------------------------------------
' s cript to be stored on level ... in project (mark appropriate levels with [x] below)
' [ ] External
' [ ] All levels possible
' [ ] Project level
' [x] Device level
' [ ] Object level (TO/DO)
' [ ] Subobject level
'-----------------------------------------------------------------------------------------------------------------------
' Restrictions, known limitations:
' Works only with SIMOTION devices.
'-----------------------------------------------------------------------------------------------------------------------
' Requirements, prerequisites, external resources used:
' MS Excel 2003.
'-----------------------------------------------------------------------------------------------------------------------
' Change log table (latest change is at the bottom of the list):
' version date changes applied
' V1.0 2007-03-09 first release
'-----------------------------------------------------------------------------------------------------------------------
' == Define all variables explicitly before use if "Option Explicit"
Option Explicit

' == Set error handling preference
On Error Goto 0 ' No error handling, error will abort s cript

' == Define SIMOTION log behavior
APP.LogActive = TRUE ' FALSE - disable log output, TRUE - enable log output
APP.LogMode = 1 ' 0 - print all, 1 - print only PrintToLog statements
' APP.LogFile = ' Path and name of logfile

'-----------------------------------------------------------------------------------------------------------------------
' Main s cript
'-----------------------------------------------------------------------------------------------------------------------
ExportIOsToExcel()
'-----------------------------------------------------------------------------------------------------------------------
' End of main s cript
'-----------------------------------------------------------------------------------------------------------------------

'-----------------------------------------------------------------------------------------------------------------------
' Subroutine name: ExportIOsToExcel
'-----------------------------------------------------------------------------------------------------------------------
' Des cription:
' Opens an Excel worksheet template and writes all IOs (contained in the IO symbolbrowser) to the worksheet.
'-----------------------------------------------------------------------------------------------------------------------
' Parameters: None
'-----------------------------------------------------------------------------------------------------------------------
Private Sub ExportIOsToExcel()
' Define local variables
Dim oExcel ' Excel application
Dim oWorkBook ' Excel workbook
Dim oSheet ' Excel sheet
Dim oIO ' IO object
Dim oIOArrayElement ' IO object, which is element of an array
Dim iIOArrayElement ' IO array loop counter
Dim iRow : iRow = 2 ' Row number in excel sheet, start with row number 2
Dim sName ' IO name
Dim lFieldLength ' IO field length
Dim sSubstStrategy ' IO substitution strategie
Dim iNoComments ' Number of comments of one IO
Dim oComment ' IO comment object
Dim iComment ' Comment loop counter

' Determine Excel file name
APP.Tools.FileBrowser.open(".xls")
If (APP.Tools.FileBrowser.FileName = "") Then WBs cript.Quit

' Open Excel application
On Error Resume Next
Set oExcel = CreateObject("Excel.Application")
If (Err.Number <> 0) Then
MsgBox "Can抰 get access to Excel." & vbCrLf & _
"s cript will be aborted!", _
vbCritical + vbOKOnly + vbSystemModal, _
"s cript Error"
WBs cript.Quit
End If
On Error Goto 0

' Open Excel file
Set oWorkBook = oExcel.WorkBooks.Open(APP.Tools.FileBrowser.FileName)
Set oSheet = oExcel.ActiveSheet

' Clear Excel file (except header)
oSheet.Rows("2:9999").ClearContents

' Loop over all IOs
For Each oIO In IOs
sName = oIO.Name ' Get IO name
oSheet.Cells(iRow, 1).Value = sName
oSheet.Cells(iRow, 2).Value = oIO.Address ' Get IO address
If (oIO.ReadOnly) Then ' Get IO read only property (language independence)
oSheet.Cells(iRow, 3).Value = 1
Else
oSheet.Cells(iRow, 3).Value = 0
End If
oSheet.Cells(iRow, 4).Value = oIO.Type ' Get IO data type
lFieldLength = oIO.FieldLen ' Get array length
oSheet.Cells(iRow, 5).Value = lFieldLength
' Check, if IO isn't a bit
If (oIO.Type <> 1) Then
oSheet.Cells(iRow, 6).Value = oIO.ProcessImageTask ' Get image task
End If
sSubstStrategy = oIO.SubstitutionStrategy ' Get substitution strategy
oSheet.Cells(iRow, 7).Value = sSubstStrategy
' Query substitution value only in case of single IO,that is not a bit and has correct substitution strategy
If ((lFieldLength = 1) And (oIO.Type <> 1) And _
((sSubstStrategy = "CPU_STOP") Or (sSubstStrategy = "SUBS_VALUE"))) Then
oSheet.Cells(iRow, 8).Value = oIO.SubstitutionValue ' Get substitution value
End If
' Query display format only in case of single IO
If (lFieldLength = 1) Then
oSheet.Cells(iRow, 9).Value = oIO.Display ' Get display format
End If
iNoComments = oIO.Comments.Count ' Get number of comments (one for each language)
oSheet.Cells(iRow, 10).Value = iNoComments
If (iNoComments > 0) Then
iComment = 0
' Get all comments and their locale ID
For Each oComment in oIO.Comments
oSheet.Cells(iRow, 11 + 2 * iComment).Value = oComment.Locale
oSheet.Cells(iRow, 12 + 2 * iComment).Value = oComment.Text
iComment = iComment + 1
Next
End If

' Check, if IO is an array
If (lFieldLength <> 1) Then
' Loop over all IO array elements
For iIOArrayElement = 0 to lFieldLength - 1
iRow = iRow + 1 ' Use next row for next IO array element
Set oIOArrayElement = IOs(sName & "[" & iIOArrayElement & "]")
oSheet.Cells(iRow, 1).Value = sName & "[" & iIOArrayElement & "]"
oSheet.Cells(iRow, 2).Value = oIOArrayElement.Address
If (oIO.ReadOnly) Then ' Take read only property from IO array base element
oSheet.Cells(iRow, 3).Value = 1
Else
oSheet.Cells(iRow, 3).Value = 0
End If
oSheet.Cells(iRow, 4).Value = oIOArrayElement.Type
oSheet.Cells(iRow, 5).Value = 1
' Query substitution value only in case of correct substitution strategy
If ((sSubstStrategy = "CPU_STOP") Or (sSubstStrategy = "SUBS_VALUE")) Then
oSheet.Cells(iRow, 8).Value = oIOArrayElement.SubstitutionValue
End If
oSheet.Cells(iRow, 9).Value = oIOArrayElement.Display
iNoComments = oIOArrayElement.Comments.Count ' Get number of comments (one for each language)
oSheet.Cells(iRow, 10).Value = iNoComments
If (iNoComments > 0) Then
iComment = 0
' Get all comments and locale ID
For Each oComment in oIOArrayElement.Comments
oSheet.Cells(iRow, 11 + 2 * iComment).Value = oComment.Locale
oSheet.Cells(iRow, 12 + 2 * iComment).Value = oComment.Text
iComment = iComment + 1
Next
End If
Next
End If

' Use next row for next IO item
iRow = iRow + 1
Next ' oIO

' Save and close the sheet
oWorkBook.Save
oWorkBook.Close

' Release object variables
Set oExcel = Nothing

End Sub ' ExportIOsToExcel()



将上面的脚本复制到txt文件中然后保存。
然后在scout中右键点击设备名称(如D425)选择expert->insert s cript folder. 那么在D425下面就多了一栏s cript。然后右键点击s cript后选择ASCⅡimport... 将刚刚的txt文件导入进来就ok了。
剩下的工作只要点击工具栏中的“Accpet and run”..
评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMOTION

共有2227条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
X 图片
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。