1 - you may want to check the manual for directory loader. it i recall there are some limitations.
2 - that is possible (check mounting of volume). not really worth the effort if you ask me.
3 - several examples (including ones from me) are already shared. basically open file, read from file, close the file. you can try to parse the values immediately in CWRITE or separately using SREAD. both are very similar but SREAD is a bit more flexible and forgiving.
DEF read_txt()
DECL state_t s
DECL modus_t m
DECL int h,read,n
DECL char Buff[256]
; initialize buffer, it cannot be empty
for n=1 to 256
Buff[n]=32 ; 0x20 is a space character
endfor
h=0 ; pick file handle
read=0 ; initialize number of characters read from file
;-------> step 1 - open file <------------
; note: file is stored in C:\KRC\ROBOTER\USERFILE
cwrite($FCT_CALL,S,M,"krl_fopen","PosArray.txt","r",h)
wait for s.ret1==#data_ok ; confirm action
;-------> step 2 - read from file <-------
repeat
cwrite($FCT_CALL,s,m,"krl_fgets",h,Buff[],87,Read,";")
wait for (s.ret1==#data_ok) or (s.msg_no== -4) ; confirm action or end of file
if (s.ret1==#data_ok) and (StrLen(Buff[])>0) then
MsgNotify(Buff[],,,,read) ; display what was read and number of chars
endif
if s.msg_no== -4 then
msgnotify("end of file") ; it is end of file...
endif
until s.msg_no == -4
;-------> step 3 - close file <----------
; do NOT forget to close file (or else...)
cwrite($FCT_CALL,S,M,"krl_fclose",h)
wait for s.ret1==#data_ok
END
Display More
Thank you for your great example, panic mode. I used that piece of code and it is working. However, I want to assign that read values to variables. I added a few line to your example code.
DEF read_test()
DECL state_t s
DECL modus_t m
DECL int h,read,n, split,o
DECL char f1[100], f2[100], f3[100]
; %f (for REAL type)
; %s (for char type)
f1[]="%f %f %f %f %f %f "
f2[]="%f %f %f %f %f %f "
f3[]="%f %f %f %f %f %f "
for n=1 to 256
Buff[n]=32
endfor
h=0
read=0
;-------> step 1 - open file <------------
; note: file is stored in C:\KRC\ROBOTER\USERFILE
cwrite($FCT_CALL,S,M,"krl_fopen","coordata.txt","r",h)
wait for s.ret1==#data_ok
;-------> step 2 - read from file <-------
n=1
repeat
cwrite($FCT_CALL,s,m,"krl_fgets",h,Buff[],100,Read)
wait for (s.ret1==#data_ok) or (s.msg_no== -4)
if s.ret1==#data_ok then
changeseperator(Buff[])
o=0
MsgNotify(Buff[],,,,read)
SWITCH n
CASE 1
sread(Buff[],s,o,f1[],v1,v2,v3,v4,v5,v6)
CASE 2
sread(Buff[],s,o,f2[],v7,v8,v9,v10,v11,v12)
CASE 3
sread(Buff[],s,o,f3[],v13,v14,v15,v16,v17,v18)
DEFAULT
HALT
ENDSWITCH
n=n+1
endif
until s.msg_no == -4
;-------> step 3 - close file <----------
cwrite($FCT_CALL,S,M,"krl_fclose",h)
wait for s.ret1==#data_ok
END
DEF changeseperator(fiBuff[]:OUT)
DECL Char fiBuff[]
DECL INT cloop
for cloop=1 TO StrLen(fiBuff[])
if fiBuff[cloop]=="," then
fiBuff[cloop]=" "
endif
endfor
END
Display More
The number of coordinates that will come to me from outside will be able to change. In other words, 4 coordinate lines can come, 15 coordinate lines can also come.
If you noticed this code that I added, it is possible to process 3 lines of coordinate information. I want to make this code dynamic. In other words, it needs to create as many variables as the number of coordinate lines that will come from the outside and write the value into it.
When I send 2 coordinate lines instead of 3 in the .txt file that the current code is reading, my code stuck line 37 -wait for condition. Since there are already two lines of coordinate information and the reading is over, it shouldn't be stuck there, right?. How can I prevent this? We can accept the maximum coordinate line that will come to me from the outside as 100. Is there any chance you can help me with this problem I described?
Thank you in advance.