> For the complete documentation index, see [llms.txt](https://docs.monokot.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.monokot.io/scripts/programming-examples/how-to-initialize-device-settings-from-file.md).

# How to: Initialize Device Settings from File

The guide demonstrates how to read parameter values from a text file using an expression and apply them to a device.

{% hint style="warning" %}
Please note that calling functions from *MosFiles*, *MosUtils* objects will immediately put the script module into demo mode if it is not licensed
{% endhint %}

Before starting, create a file on your disk named *startup.ini* with the following content:

```
Host=192.168.1.1
SlaveId=9
```

Open Monokot Server Administrator, create a Modbus TCP device named *MyModbusDevice*, double-click Scripts on the *Server Explorer* pane. Click *New Expression* and set the name *Initializer* for the expression that appears. Insert the following code into the expression code editor:

```javascript
// 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;
```

Press *Ctrl + Enter* to apply the change in the code editor.&#x20;

In order for the changes to take effect on the server, click the Sync button. Since no trigger is specified for the expression, it will be executed once at the time of creation. After the expression is executed, the *Host* and *SlaveId* properties of *MyModbusDevice* will be 192.168.1.1 and 9 respectively. To verify this, select *MyModbusDevice* in the Device Manager and click the *Sync* button to receive changes from the server.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.monokot.io/scripts/programming-examples/how-to-initialize-device-settings-from-file.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
