Welcome to Synthiam!

The easiest way to program the most powerful robots. Use technologies by leading industry experts. ARC is a free-to-use robot programming software that makes servo automation, computer vision, autonomous navigation, and artificial intelligence easy.

Get Started
Asked — Edited

Help With This Error - Object Reference Not Set To An Instance Of An Object

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:

Code:


$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.

Code:



FileReadReset($filename) #opens file for reading
sleep(50)
FileWrite($filename, $servo1)



This is when I get the error mentioned. Thoughts?

Thanks,.


ARC Pro

Upgrade to ARC Pro

Experience early access to the latest features and updates. You'll have everything that is needed to unleash your robot's potential.

AI Support Bot
Related Content
Synthiam
PRO
Synthiam
#1  
1) 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.

2) Also, the second bit of code is opening the file for reading, then writing to it.

3) There is no need to write an empty string to the file and create it.

4) The :start is not needed

5) FYI $servo1 is never set, so it will always write an empty string

6) I modified the code to check if the file exists before deleting it

7) 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...

Code:


$filename = ("C:\SERVO\INFO.txt")
$servo1 = ""

if (FileExists($filename))
FileReadClose() # only add this line if you are actually reading from the file somewhere
FileDelete($filename) #deletes the file becauase I want a new one every time
endif


Code:


FileWriteLine($filename, $servo1)