WinCC Unified: export multiple logged tags as a daily .CSV report

DerHecht4.0
DerHecht4.0
11.1 هزار بار بازدید - 3 سال پیش - In this Video I show
In this Video I show you how you create with JavaScript and the method "CreateLoggedTagSet" a daily report of multiple logged tags from the last 24h.
You can easy change the script more logged values of differnt time range like the last week add to the end date "*7".

00:00 Intro
00:30 Solution
00:47 how does it work
02:34 add an additional tag

Video for single export:
WinCC Unified V16: export logged tags as a daily .CSV report  (last 24 hours)
WinCC Unified V16: export logged tags...

//Asynchronous JavaScript code
let timeStamp = new Date().toLocaleDateString().replace(/[/]/g, "_");
let path = "C:\\Users\\Public\\Export_" + timeStamp +".csv";
let delimiter =",";
let start = new Date(); //now
let end = new Date(start.getTime() - 1000 * 60 * 60 * 24);//last 24h
let CSVData = "Time Stamp:"  + delimiter +"Tag name:" + delimiter +"Value:" + "\n"; //header

let logTagSet = HMIRuntime.TagLogging.CreateLoggedTagSet(["Flow:LoggingTag_Flow", "Speed:LoggingTag_Speed", "Velocity:LoggingTag_Velocity"]);
let loggedTagsMatrix = await logTagSet.Read(start, end, 0);

for(let loggedTag of loggedTagsMatrix)
{
 for(let loggedTagValue of loggedTag.Values)
 {
 CSVData += new Date(loggedTagValue.TimeStamp) + delimiter + loggedTag.Name + delimiter + loggedTagValue.Value  + "\n";

 HMIRuntime.FileSystem.WriteFile(path, CSVData, "utf8").then(
 function() {
 HMIRuntime.Trace("Write file finished successfully");
 }).catch(function(errorCode) {
 HMIRuntime.Trace("Write failed errorcode=" + errorCode);

#DerHecht #WinCC #Unified #TIAPortal #JavaScript
3 سال پیش در تاریخ 1400/08/26 منتشر شده است.
11,179 بـار بازدید شده
... بیشتر