In atvise SCADA, the class InputFileStream allows you to open and read text or binary files directly from the server. This is especially useful when you need to import external data (e.g., logs, measurements, or batch records) and map those values into OPC UA nodes for visualization or further processing.
In this example, we demonstrate how to:
- Open a .txt file with InputFileStream.
- Read its content line by line or completely.
- Extract values (e.g., machine, ID, variable, timestamp, data1, data2, data3).
- Assign specific values (such as data1 and timestamp) to a node using Ua.findNode().result.assign().
This approach is simple but powerful: it allows you to integrate external flat-file data sources into your SCADA project without needing an external database or connector. It is ideal for tests, demos, or small batch data imports where a CSV/TXT file contains measurement values.
✅Steps
- For this exmaple the file is under the project directory:
- Help section you can find more information:
- Builder structure:
- Log section:
✅Code Example
// === Read file content === var ifs = new InputFileStream("machineData.txt", "utf8"); ifs.open(); var fileContent = ifs.read(); ifs.close(); // Debug: show raw file content console.log("Raw file content:\n" + fileContent); // === Split lines === // Remove empty lines and split by newlines var lines = fileContent.trim().split(/\r?\n/); // The first line is the header, so take the second line (index 1) if (lines.length > 1) { var firstDataLine = lines[1]; console.log("First data line:", firstDataLine); // Split the line by commas var parts = firstDataLine.split(","); // parts[0] = machine // parts[1] = ID // parts[2] = variable // parts[3] = timestamp // parts[4] = data1 // parts[5] = data2 // parts[6] = data3 var machine = parts[0].trim(); var id = parts[1].trim(); var variable = parts[2].trim(); var timestamp = Number(parts[3].trim()); // convert to number var value1 = Number(parts[4].trim()); // 12.2 in your example console.log("Machine:", machine); console.log("ID:", id); console.log("Variable:", variable); console.log("Timestamp:", timestamp); console.log("Value1:", value1); // === Find the node in vNode === var node1 = Ua.findNode("AGENT.OBJECTS.pump1"); // Assign value with timestamp // 'value' is the value to write, 'timestamp' sets the historical timestamp node1.result.assign({ value: value1, timestamp: timestamp * 1000 // multiply by 1000 if timestamp is in seconds }); console.log("Value assigned to node:", value1, "at", new Date(timestamp * 1000)); } else { console.log("No data lines found in the file."); }
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article