You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
240 lines
7.9 KiB
Plaintext
240 lines
7.9 KiB
Plaintext
'Ändert die Adressen im Systemmanager
|
|
'Dazu werden die im Systemmanager eingetragenen Geräte mit den gefundenen Geräten abgeglichen.
|
|
'Eingetragene Geräte, die nicht gefunden wurden werden auf "Disabled" gesetzt
|
|
Option Explicit
|
|
Dim wshshell,fso,i,Fnct
|
|
Dim strPath,strSystemFolder,strWinFolder,strTempFolder
|
|
'----------------------------- Objekte erzeugen --------------------------------
|
|
i = 0
|
|
On Error Resume Next
|
|
Do
|
|
err.Clear
|
|
i = i+1
|
|
Set wshshell = CreateObject("WScript.Shell")
|
|
Set fso = CreateObject("Scripting.FileSystemObject")
|
|
Set Fnct = CreateObject("Install.Functions")
|
|
WScript.Sleep 1000
|
|
Loop Until Err.Number = 0 OR i > 30
|
|
|
|
If Err.Number <> 0 Then
|
|
WScript.Quit
|
|
End If
|
|
|
|
On Error Goto 0
|
|
|
|
'--------------------------- Standardpfade -------------------------------------
|
|
strPath = GetCurrentPath()
|
|
strSystemFolder = fso.GetSpecialFolder(1) & "\"
|
|
strWinFolder = fso.GetSpecialFolder(0) & "\"
|
|
strTempFolder = fso.GetSpecialFolder(2) & "\"
|
|
|
|
|
|
'------------------------------ Main -------------------------------------------
|
|
'Konstanten für den Systemmanager
|
|
const TREEITEMTYPE_DEVICE = 2
|
|
const IODEVICETYPE_CP5412A2 = 7
|
|
const IODEVICETYPE_FC3100 = 38
|
|
const IODEVICETYPE_FC3100_SLAVE = 60
|
|
const IODEVICETYPE_ETHERNET = 45
|
|
const IODEVICETYPE_ENETRTMP = 66
|
|
const IODEVICETYPE_EL6731 = 86
|
|
const IODEVICETYPE_EL6731SLV = 97
|
|
const IODEVICETYPE_ETHERCAT = 94
|
|
const IODEVICETYPE_FC7500 = 48
|
|
const IODEVICETYPE_ETHERCATPROT = 111
|
|
const IODEVICETYPE_ETHERNETNVPROT = 112
|
|
const IODEVICETYPE_ETHERNETPNMPROT = 113
|
|
|
|
Dim Arguments 'Kommandozeilenparameter
|
|
Set Arguments = wscript.Arguments
|
|
|
|
'SystemManagerFile
|
|
Dim WsmFileName
|
|
Dim tsm
|
|
|
|
WsmFileName = Arguments(0)
|
|
'WsmFileName = "c:\Focke\M252\25215966.wsm"
|
|
Set tsm = CreateObject("TCatSysManager.TcSysManager")
|
|
|
|
|
|
'Wsm Konfiguration
|
|
Dim SysManagerItems
|
|
|
|
Call tsm.OpenConfiguration(WsmFileName)
|
|
Set SysManagerItems = tsm.LookupTreeItem("TIID") 'Start
|
|
|
|
|
|
'Gefundene Geräte
|
|
Dim xml
|
|
Dim FoundDevices
|
|
|
|
Set xml = CreateObject("Msxml.DOMDocument")
|
|
Call xml.loadXml(SysManagerItems.ProduceXml)
|
|
Set FoundDevices = xml.selectNodes("TreeItem/DeviceGrpDef/FoundDevices/Device")
|
|
|
|
Dim bDeviceDone(20) 'bool
|
|
For i = 0 To 19
|
|
bDeviceDone(i) = true
|
|
Next
|
|
|
|
'Adressen ändern
|
|
Call SetAllAddresses()
|
|
'Wurde etwas ausgelassen? => nicht gefunden
|
|
For i = 0 To 19
|
|
'Wenn ja dann Device auf Disable setzen
|
|
If Not bDeviceDone(i) Then
|
|
Dim Child
|
|
SysManagerItems.Child(i+1).Disabled = 1
|
|
'Child.Disabled = 1
|
|
End If
|
|
Next
|
|
|
|
call tsm.SaveConfiguration(WsmFileName)
|
|
|
|
'------------------------------- Funktionen ------------------------------------
|
|
Function GetCurrentPath()
|
|
Dim l_strScriptName
|
|
Dim l_strTemp
|
|
|
|
l_strScriptName = WScript.ScriptFullName
|
|
l_strTemp = WScript.ScriptName
|
|
GetCurrentPath = Left(l_strScriptName, Len(l_strScriptName) - Len(l_strTemp))
|
|
End Function
|
|
|
|
Function ExpandPath(p_strEnvironment,p_strDefault)
|
|
Dim l_strTemp
|
|
l_strTemp = wshshell.ExpandEnvironmentStrings(p_strEnvironment)
|
|
If l_strTemp = p_strEnvironment Then
|
|
l_strTemp = p_strDefault
|
|
End If
|
|
ExpandPath = l_strTemp
|
|
End Function
|
|
|
|
'Adresse eines Devices einstellen, Namen vergeben und in der Liste abhaken
|
|
Function SetAddressInfo(p_AddressInfo,p_DeviceType,p_strDeviceText)
|
|
Dim nCurrentDevice
|
|
Dim bResult
|
|
bResult = false
|
|
nCurrentDevice = 0
|
|
Dim SysManagerDevice
|
|
For Each SysManagerDevice In SysManagerItems ' Für alle Devices in der Datei
|
|
DIM l_CurrentSysManagerDevice
|
|
Set l_CurrentSysManagerDevice = SysManagerDevice
|
|
|
|
' ... Zwischenergebisse
|
|
Dim bIsDevice 'Ist es ein Device
|
|
Dim bIsCorrectType 'Stimmt der Typ überein
|
|
Dim bIsNotDone 'Noch nicht abgehakt
|
|
Dim bIsEthernet 'Ethernet Port muss etwas anders behandelte werden
|
|
Dim bIsEtherCATDevice ' Auch EtherCAT Devices brauchen eine Sonderbehandlung
|
|
bIsDevice = l_CurrentSysManagerDevice.ItemType = TREEITEMTYPE_DEVICE
|
|
bIsCorrectType = l_CurrentSysManagerDevice.ItemSubType = p_DeviceType
|
|
bIsNotDone = Not bDeviceDone(nCurrentDevice)
|
|
bIsEthernet = ((p_DeviceType = IODEVICETYPE_ETHERNET) Or (p_DeviceType = IODEVICETYPE_ENETRTMP)) And Not IsEtherCAT(p_DeviceType)
|
|
bIsEtherCATDevice = (p_DeviceType = IODEVICETYPE_EL6731SLV) Or (p_DeviceType = IODEVICETYPE_EL6731)Or (p_DeviceType = IODEVICETYPE_ETHERCAT)Or (p_DeviceType = IODEVICETYPE_ETHERCATPROT)
|
|
' ... Vergleichen und ggf. Adresse zuweisen
|
|
'if bIsNotDone Then MsgBox "IsDevice:" & bIsDevice & vbCrLf & "CorrectType:" & bIsCorrectType & vbCrLf & "DeviceType:" & p_DeviceType & vbCrLf & "Current DeviceType:" & l_CurrentSysManagerDevice.ItemSubType & vbCrLf & "Current Device Name:" & p_strDeviceText
|
|
|
|
If (bIsDevice And bIsCorrectType) And bIsNotDone Then
|
|
l_CurrentSysManagerDevice.Name = p_strDeviceText
|
|
If Not bIsEthernet And Not bIsEtherCATDevice Then
|
|
l_CurrentSysManagerDevice.ConsumeXml(p_AddressInfo.xml)
|
|
End If
|
|
bDeviceDone(nCurrentDevice) = true
|
|
bResult = true
|
|
Exit For
|
|
End If
|
|
nCurrentDevice = nCurrentDevice+1
|
|
Next 'SysManagerDevice
|
|
SetAddressInfo = bResult
|
|
End Function
|
|
|
|
Function IsEtherCAT(p_DeviceType)
|
|
Dim k
|
|
Dim AllEtherCATS(4)
|
|
AllEtherCATs(0) = IODEVICETYPE_ETHERCAT
|
|
AllEtherCATs(1) = IODEVICETYPE_ETHERCATPROT
|
|
AllEtherCATs(2) = IODEVICETYPE_ETHERNETNVPROT
|
|
AllEtherCATs(3) = IODEVICETYPE_ETHERNETPNMPROT
|
|
IsEtherCAT = false
|
|
For k = 0 To 3
|
|
If p_DeviceType = AllEtherCATs(k) Then IsEtherCAT = True
|
|
Next
|
|
End Function
|
|
|
|
'------------------------------- Subs ------------------------------------
|
|
'Adressen anpassen
|
|
Sub SetAllAddresses
|
|
Dim IdxCurrentFC3100Master
|
|
Dim IdxCurrentFC3100Slave
|
|
Dim IdxCurrentCP9030
|
|
IdxCurrentFC3100Master = 1
|
|
IdxCurrentFC3100Slave = 1
|
|
IdxCurrentCP9030 = 1
|
|
|
|
Dim nCurrentDevice
|
|
Dim SysManagerDevice
|
|
For Each SysManagerDevice In SysManagerItems ' Für alle Devices in der Datei
|
|
bDeviceDone(nCurrentDevice) = false
|
|
nCurrentDevice = nCurrentDevice+1
|
|
Next
|
|
|
|
'Fuer alle gefundenen Geraete
|
|
Dim AInfo
|
|
For i = 0 To FoundDevices.length -1
|
|
Set ainfo = FoundDevices(i).selectSingleNode("AddressInfo")
|
|
Dim strProfibusMasterDevice
|
|
Dim strProfibusSlaveDevice
|
|
Dim strCP9030Device
|
|
|
|
Select Case FoundDevices(i).selectSingleNode("ItemSubType").nodeTypedValue
|
|
Case CStr(IODEVICETYPE_CP5412A2)
|
|
Call SetAddressInfo(ainfo,IODEVICETYPE_CP5412A2,"Profibus Master (CP5412)")
|
|
|
|
Case CStr(IODEVICETYPE_FC3100)
|
|
strProfibusMasterDevice = "Profibus Master" & IdxCurrentFC3100Master & " (FC3100)"
|
|
strProfibusSlaveDevice = "Profibus Slave" & IdxCurrentFC3100Slave & " (FC3100)"
|
|
If SetAddressInfo(ainfo,IODEVICETYPE_FC3100,strProfibusMasterDevice) Then
|
|
IdxCurrentFC3100Master = IdxCurrentFC3100Master + 1
|
|
Elseif SetAddressInfo(ainfo,IODEVICETYPE_FC3100_SLAVE,strProfibusSlaveDevice) Then
|
|
IdxCurrentFC3100Slave = IdxCurrentFC3100Slave + 1
|
|
End If
|
|
|
|
Case CStr(31)
|
|
strCP9030Device = "Beckhoff Link" & IdxCurrentCP9030 & "(CP9030)"
|
|
Call SetAddressInfo(ainfo,31,strCP9030Device)
|
|
IdxCurrentCP9030 = IdxCurrentCP9030 + 1
|
|
|
|
Case CStr(IODEVICETYPE_FC7500)
|
|
Call SetAddressInfo(ainfo,IODEVICETYPE_FC7500,"Sercos")
|
|
' Case CStr(IODEVICETYPE_ETHERCATPROT)
|
|
' Call SetAddressInfo(0,IODEVICETYPE_ETHERCATPROT,"EtherCAT" & i)
|
|
' Case CStr(IODEVICETYPE_ETHERCAT)
|
|
' Call SetAddressInfo(0,IODEVICETYPE_ETHERCAT,"EtherCAT" & i)
|
|
' Case CStr(IODEVICETYPE_EL6731)
|
|
' MsgBox "IODEVICETYPE_EL6731"
|
|
' Call SetAddressInfo(0,IODEVICETYPE_EL6731,"EtherCAT" & i)
|
|
' Case CStr(IODEVICETYPE_ETHERNET)
|
|
' Call SetAddressInfo(0,IODEVICETYPE_ETHERNET,"EtherCAT" & i)
|
|
End Select
|
|
|
|
Next'Für alle gefundenen Geräte
|
|
|
|
' ... der wird nicht gefunden
|
|
For i = 1 To 4
|
|
Call SetAddressInfo(0,IODEVICETYPE_ETHERCAT,"EtherCAT" & i)
|
|
Next
|
|
For i = 1 To 4
|
|
Call SetAddressInfo(0,IODEVICETYPE_ETHERCATPROT,"EtherCAT" & i)
|
|
Next
|
|
For i = 1 To 4
|
|
Call SetAddressInfo(0,IODEVICETYPE_EL6731,"Profibus Master" & i & " (EL6731)")
|
|
Next
|
|
For i = 1 To 4
|
|
Call SetAddressInfo(0,IODEVICETYPE_EL6731SLV,"Profibus Slave" & i & " (EL6731)")
|
|
Next
|
|
For i = 1 To 4
|
|
Call SetAddressInfo(0,IODEVICETYPE_ETHERNET,"Ethernet" & i)
|
|
Next
|
|
End Sub
|