How to: Initialize Device Settings from File
Host=192.168.1.1
SlaveId=9// Reading file content as a string array
var lines = MosFiles.readLines('C:\\files\\startup.ini');
var host, slaveId;
for (var i = 0; i < lines.length; i++)
{
var ln = lines[i];
// Splitting a string from the file using the '=' separator
var split = ln.split('=');
// Getting host and SlaveId values
if (split[0] == 'Host')
host = split[1];
else if (split[0] == 'SlaveId')
slaveId = split[1];
}
try
{
MosUtils.setDeviceProperty('', 'MyModbusDevice', 'Host', host);
MosUtils.setDeviceProperty('', 'MyModbusDevice', 'SlaveId', slaveId);
}
finally
{
// Making sure to commit the change in properties
MosUtils.commitChanges();
}
return MosUtils.doNothing;Last updated