Issues with system.device.addDevice script

Hey all,

I'm hoping this will be a simple fix, but I'm using the following script with a list of device names and IP addresses:

> deviceType = "ModbusTcp"
> 
> for i in range(len(trackers)):
> 	deviceName = str(trackers[i])
> 	deviceProps = {'Enabled': 1, 'HostName': str(ips[i]), 'Port':"502"}
> 	
> 	system.device.addDevice(deviceType, deviceName, deviceProps)

I checked the manual and I pulled a list of devices from my gateway and copied the deviceType/driver string exactly from the other modbus tcp devices in case I fat fingered something but no luck.

The error returned is a bunch of java stuff but the gist seems to be this:

com.inductiveautomation.ignition.client.gateway_interface.GatewayException: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Device driver 'MODBUSTCP' doesn't exist

Which makes no sense, but maybe the driver name is different from how I'm typing it or something. Appreciate any ideas, thanks folks.

Try specifying the parameter names. There's some legacy baggage on this function that makes it complicated.

So something like this:

deviceType = "ModbusTcp"
 
for i in range(len(trackers)):
 	deviceName = str(trackers[i])
 	deviceProps = {'Enabled': 1, 'HostName': str(ips[i]), 'Port':"502"}
 	
 	system.device.addDevice(deviceType=deviceType, deviceName=deviceName, deviceProps=deviceProps)

Also, you can write your code a bit cleaner using the zip function:

deviceType = "ModbusTcp"
 
for deviceName, hostName in zip(trackers, ips):
 	deviceProps = {'Enabled': True, 'HostName': hostName, 'Port': "502"}
 	
 	system.device.addDevice(deviceType=deviceType, deviceName=deviceName, deviceProps=deviceProps)
1 Like

Weird, that did it though. Definitely should have tried that but the error threw me down a rabbit hole that led nowhere productive. Thanks again.

Fancy. I'm very much a self-taught noob when it comes to all the Ignition functionality so I appreciate the tip :slight_smile: