When I write to csv file when file is opened I receive error:
"failed to append to file: Error: EBUSY: resource busy or locked, open 'C:\Users\User\Desktop\xxxx.csv'"
When I close the file I always receive error:
"failed to append to file: Error [ERR_STREAM_WRITE_AFTER_END]: write after end"
And the only way to reset this error is to restart node-red.
This error doesn't appear with .txt files
Is there a way to check if file is opened before writing to it or any other workaround to prevent this error?
[{"id":"c466a6a63246e65b","type":"inject","z":"fa5ad0aa4db28cdf","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":640,"y":360,"wires":[["3ca7695a74dc281a"]]},{"id":"3ca7695a74dc281a","type":"function","z":"fa5ad0aa4db28cdf","name":"filename","func":"// var BATCH_NO = global.get('BATCH_NO');\n// var Assembly_NO = global.get('ASSEMBLY_NO');\n\nvar BATCH_NO = \"CNC1234\";\nvar Assembly_NO = 2;\n\nvar now = new Date();\nvar timestamp = now.getFullYear() + \"-\" + (\"0\" + (now.getMonth() + 1)).slice(-2) + \"-\" + (\"0\" + now.getDate()).slice(-2) + \" \" + (\"0\" + now.getHours()).slice(-2) + \":\" + (\"0\" + now.getMinutes()).slice(-2) + \":\" + (\"0\" + now.getSeconds()).slice(-2);\n\nmsg.filename = \"C:/Users/User/Desktop/\"+BATCH_NO+\".csv\"\n\nmsg.payload = timestamp+\",\"+BATCH_NO+\",\"+Assembly_NO;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":360,"wires":[["f0fdae733f96c3d2"]]},{"id":"f0fdae733f96c3d2","type":"file","z":"fa5ad0aa4db28cdf","name":"","filename":"filename","filenameType":"msg","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":940,"y":360,"wires":[[]]}]