I try to read a file in Node Red every second. The file is written from a program every 0.2 seconds.
Now the file sometimes changes the length of the array:
This is in a way impossible cause the program writes always a new line into the txt file.
I now suspect that this happens when the program writes the file and node red has opened it for reading.
Has anyone had experience with something like this and can help me?
normally you would something like the tail node to just monitor things being added to a file.
writing it so often and reading it is generally a bad idea for the reasons you are finding.
But some operating systems cope better than others.
the tail node it self works well, but with the tail node I am just able to read the new line?
For my application I need the hole file because I show it in a grid
sorry, my PLC write every 0.2s some different data in a new line into a file. I want to show the data on the dashboard.
I have now tried different ways of doing this.
The one that I think works best is when I look at the file with a tail node to get the last line that was added.
This works fine, but I can't encode the utf le 16 string to display numbers correctly.
So, the PLC does not write a file, a PC connected to the PLC and that PC reads PLC data then writes the file.
What program is writing this file? Wincc? Custom application? Node-red?
As it is a relatively new PLC and there are several nodes available, why don't you simply request the values from the PLC instead of messing around with files?
Its a custom application. The file is used for some other stuff, so I don t want to change the why this is running (cause this runs since a while). I don't want to change this communication. I am looking for a simple solution how I can access the data with node red without further changes or further communication to the PLC.
As I said, the tail node works very well, except for the fact that I get the data UTF-LE16 encoded and therefore cannot change the string to a number.