WayneA
USA
Asked
— Edited
Good Evening,
I am attempting to write servo information to a file (C:\SERVO\INFO.txt The process and order that I am using is:
$filename = ("C:\SERVO\INFO.txt")
:start
$servo1 = ""
FileReadReset($filename) #opens file for reading
sleep(50)
FileDelete($filename) #deletes the file becauase I want a new one every time
sleep(50)
FileWrite($filename, "") #creates an empty file
sleep(50)
FileReadClose($filename) #closes the file because I am done with it for now
Afterwards I have my script to get the value of my servo at D1. Store it in variable $servo1. Now I am ready to write to the file again.
FileReadReset($filename) #opens file for reading
sleep(50)
FileWrite($filename, $servo1)
This is when I get the error mentioned. Thoughts?
Thanks,.
I just noticed that in your code.. the first part is ReadReset() and then FIleDelete(). So, you're opening the file to read and then deleting it.
Also, the second bit of code is opening the file for reading, then writing to it.
There is no need to write an empty string to the file and create it.
The :start is not needed
FYI $servo1 is never set, so it will always write an empty string
I modified the code to check if the file exists before deleting it
I added the FileReadClose() before deleting if you are actually reading the file somewhere else in code. There is no need to close the file if you're never reading it - and that line can be removed.
Here is all your code needs...
Thank You!