Yes, that's absolutely an intended use case. Basically all the one-off configuration manipulation functions (in system.device, system.db, etc) can now be expressed in the system.config API, albeit more verbosely:
For instance, here's a (contrived) example of adding a Modbus device with some overrides, plus an address mapping:
def modbus(hostname, port=502, timeout=2000):
return {
"profile": {
"browsePath": "",
"type": "ModbusTcp"
},
"settings": {
"advanced": {
"maxRetryCount": 1,
"reconnectAfterConsecutiveTimeouts": True,
"reverseWordOrder": False,
"zeroBasedAddressing": False
},
"connectivity": {
"communicationTimeout": timeout,
"hostname": hostname,
"localAddress": "",
"port": port
},
"readRequests": {
"readMultipleCoilsAllowed": True,
"readMultipleDiscreteInputsAllowed": True,
"readMultipleRegistersRequestAllowed": True
},
"requestOptimization": {
"concurrentRequests": 1,
"maxCoilsPerRequest": 2000,
"maxDiscreteInputsPerRequest": 2000,
"maxHoldingRegistersPerRequest": 125,
"maxHoldingRegistersPerWriteRequest": 123,
"maxInputRegistersPerRequest": 125,
"spanGaps": True
},
"stringHandling": {
"readRawStrings": False,
"reverseByteOrder": False,
"rightJustifyStrings": False
},
"writeRequests": {
"forceMultipleRegisterWritesEnabled": False,
"writeMultipleCoilsRequestAllowed": True,
"writeMultipleRegistersRequestAllowed": True
}
}
}
def createModbus():
return system.config.create(
moduleId="com.inductiveautomation.opcua",
typeId="device",
name="MyTestDevice",
config=modbus("1.1.1.1"),
files={
"address-map.txt": system.file.readFileAsBytes("/Users/pgriffith/Downloads/modbus-config.csv")
},
description="A device created in a script",
enabled=False,
actor="joe.schmoe",
)
For now, you always have to specify all the configuration - there's no merging with defaults.
