Importing text file to RAPID
hello
i am trying to write and read a txt file into my rapid program, can somebody help me in that it shows no errors but i dont know where it is saved or how it is read by rapid
this is my code:
ROC write_to_file()
VAR iodev file;
!Open "HOME:/file.doc", infile\Read;
!reg1 := ReadNum(infile);
VAR num number:= 8;
Open "Desktop:/SAJJ.TXT", file \Read;
Write file, "The number is :"\Num:=number;
Close file;
ENDPROC
PROC read_from_file()
VAR iodev file;
VAR num number;
VAR string text;
Open "Desktop:/SAJJ.TXT", file \Read;
TPWrite ReadStr(file);
Rewind file;
text := ReadStr(file\Delim:=":");
number := ReadNum(file);
Close file;
TPWrite text \Num:=number;
ENDPROC
Post edited by Niklas Skoglund on
0
Comments
-
Not sure about "Desktop:/" as a location... Maybe try "C:\FILENAME\" to save it to your computer's C drive running a virtual controller and switch to "HOME:" on a real controller.
0 -
i don't have Home , because am doing it now on simulation only does it work ?0
-
this line has the error '' C:\FILENAME\SAJJ.TXT", file \Read; "Unexpected unknown token.0
-
it gives an error for '' : '' and for the dot in '' SAJJ.TXT'' and for the comma between the file name and the word filei put the errors in red maybe it is easierC:\FILENAME\SAJJ.TXT", file \Read;and these are the error :Syntax error(136): Unexpected ':' 10/9/2013 9:22:58 AM GeneralUnexpected unknown token(150): Unexpected unknown token. 10/9/2013 9:22:58 AM GeneralSyntax error(137): Expected ',' but found '.' 10/9/2013 9:22:58 AM Generalsyntax errors. 10/9/2013 9:22:58 AM RAPID0
-
Do you have your text file located in a folder called 'FILENAME' on your C drive? because that is what your code suggests. also I think you want to do a \write instead of a \read. \read means you're opening your file for readingtryOpen " C:\" \file:= "SAJJ.TXT'" , file \Write;0
-
Your code suggests you have the text file in a folder called FILENAME is that true? you are also using \read when you try to write
Open "C:\" \file:= "SAJJ.TXT" , file \Write;0 -
i modified the command'Open "C:\SAJJ.TXT", file \Write;'i got the following error :Not allowed command 10/10/2013 9:42:48 AM Event Logand when i double click on the error explanation it says :20051: Not allowed commandDescriptionThe command is only allowed when the client is in control of the resource (program/motion).ConsequencesThe system remains in the same status, and the requested action will not be performed.Actions1) Check if the client is in control, by checking "Write Access" in RobotStudio.2) Check if the client who ought to be in control really is.0
-
where can i get this write access ?0
-
update : the following program gives no errors but does not write anything to the txt file :PROC write_to_file()VAR iodev file;!Open "HOME:/file.doc", infile\Read;!reg1 := ReadNum(infile);VAR num number:= 8;Open "C:/file" \file:= "SAJJ.TXT'" , file \Write;Write file, "The number is :"\Num:=number;Close file;ENDPROC0
-
VAR string filelocation:="C:\something2write.txt";
VAR string something2write:="blabla123";
VAR iodev file;
PROC pWriteSomething()
Open filelocation, file \Append;
Write file, something2write \NoNewLine;
Close file;
ENDPROC
0 -
Hi , thank you so much for your reply, and regarding the code, i would like to tell you what am doing,i write this code on rapid only targets with a procedure for thier path then the procedure you provided in the previous comment , i attached the file below, then i press the '' apply '' button in RAPID menu , i got the same errors about '' : '' and ''\'' in this lineVAR string filelocation:= "Csomething2write.txt"; but when i change it toVAR string filelocation:= "C:/something2write.txt";i got no errors but nothing is shown in the txt file .please see attached a snapshot for the errors i got in rapid, and for the code0
-
Hummm. Try creating a folder called "temp" on the C: drive and then change "C:/something2write.txt" to "C:/temp/something2write.txt" and see if it works.
0 -
Also, you do have a HOME file eventhough you are running a VC.
The easiest way to find it is to:
1. click on the [Controller] tab in RobotStudio
2. right-click on the Current Station name in the left Controller window
3. choose Open System Folder
Change to: VAR string filelocation:= "HOME:something2write.txt";
and it should show in your HOME folder instead of your C: drive.0 -
Just tried the code below and it worked:
!VAR string filelocation:="C:/temp/something2write.txt";
VAR string filelocation:="HOME:something2write.txt";
VAR string something2write:="blabla123";
VAR iodev file;
PROC pWriteSomething()
Open filelocation, file \Append;
Write file, something2write \NoNewLine;
Close file;
ENDPROC0 -
Hello, i found the Home thanks alot, and thanks for your patience but i created the txt file in the Home, but still not writing, shall i press something more than apply, i tried also to press synchronize to VC and synchronize to station , but still empty0
-
[Apply] saves your changes but doesn't run the program. Do you know if you've been able to run any other code on your virtual controller?
0 -
usually when i make changes in my rapid program, in the beginning i apply changes , then i press [synchronize to station]0
-
but if i have targets and path, i make [ synchronize to VC] then i can use them in the rapid program, that is what i know0
-
Demo of creating a simple station to run some RAPID:
http://screenr.com/mPqH
Demo of writing to a text file using the code above:
http://screenr.com/tPqH0 -
Thank you so much , that was very helpful0
-
Can i ask if you are familiar with API , if you have imported a variable( not a target) from C# to rapid ? i am sorry for asking this much, am new in this, and i get stuck easily0
-
Engineer345 said:Can i ask you please , i have done the read by the same way and it worked well also, i can see the output on the virtual flexPendant, is there another place where the variables are saved?i am trying to get these variables and use them in another module in rapid
0 -
You can see variables on the virtual pendent: click on [ABB] > [Program Data].
Variables are Global by default so you should be able to access them across modules.
0 -
i will try it very soonThank you i appreciate your help that was very useful0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 310 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 785 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings