Any ideas on how I can search for an Ip address (on a client window) among all of my OPC devices connected? Any built-in script functions that would allow me to design a window that searches all of the ip addresses from all of my OPC devices and give the result as the Device name?
I have Ignition 7.9.6
I don’t exactly remember when getDeviceHostName was implemented but I have it on 7.9.9
def findDevice(hostIn):
data = system.device.listDevices()
deviceList = data.getColumnAsList(data.getColumnIndex("Name"))
hostList = [system.device.getDeviceHostname(device) for device in deviceList]
try:
index = hostList.index(hostIn)
return deviceList[index]
except ValueError:
return 'host not found'
host = '192.168.140.241'
print findDevice(host)
If this is something you’ll be doing a lot, I’d recommend using a gateway timer script to collate everything into a dataset memory tag every so often, then use a lookup exression in the client.
# Gateway Timer Script
data = system.device.listDevices()
deviceList = data.getColumnAsList(data.getColumnIndex('Name'))
hostList = [system.device.getDeviceHostname(device) for device in deviceList]
dataOut = system.dataset.addColumn(data, hostList, 'Hostname', str)
system.tag.write('[default]path/to/dataset/tag', dataOut)
Expression example:
lookup({path/to/dataset/tag}, hostnameToLookUp, 'Host not found', 'Hostname', 'Name')
1 Like
I’ll give it a try. I really appreciate your help. Thank you very much.