Change Value on file

Hello,
I have the specifc file .dat (especific program).
I am creating a dashboard.
I can read and change values with the "change" fuction,
image

But now I need just read the especific variable on file, for an exemple, show the value on dashboard.

I do not know do this, because when I read the file I see just a big string, and I do not know search the specific variable and your value.

Please help

I believe that this .dat file is really a MS Access database -- is this a custom program that is reading/writing that file?

If you try to open the file directly (not through that program) then you have to know the format of the data, and you run the risk of corrupting the file so it's no longer usable by the program -- It's safest to only use the program to read/write the data.

That being said, the format does appear to be a newline separated (mostly) text file, so nothing stops you from parsing the text into lines, or using a regex to search for the value you need...

Hello, thank for your fast answer.
Below the file in the native program.
3

But the node red do not identify this mode, then I think in search the "name", I do not know if is the best way.
I need read and use the "value" on node red.

Ps. this file is just to read and do not have problem on main program.

My approach would be to split the file into separate lines, and then split those lines into variables, using a Javascript function like this:

var obj = {};
var exp = /^GLOBAL (INT|BOOL|STRING) (\w+)=(.*$)/gm;

while (grp = exp.exec(dat)) {
    var [grp, typ, key, val] = grp;
    obj[key] = typ == 'INT' ? +val : typ == 'BOOL' ? val == 'TRUE' : val;
}

msg.payload = obj;
return msg;

This results in a payload that contains ALL the global variables, so you can choose which ones to use in your downstream flows:

{
  "VELOCIDADE": 10,
  "COD_PROD": 1,
  "PARKING": true,
  "MACHINE_A": true
}

Incidentally, this same transformation can be accomplished by using a change node, with this JSONata expression:

payload.$split('\n').$match(/^GLOBAL (INT|BOOL|STRING) (\w+)=(.*$)/) {
    groups[1]:  groups[0] = 'INT' ? $number(groups[2]) :
                groups[0] = 'BOOL' ? $boolean(groups[2]) :
                groups[2]
}

which I actually find a bit cleaner to read, but hey that's just me...

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.