- Help with Siemens Macro Reading and Writing to a file
-
Help with Siemens Macro Reading and Writing to a file
I have a macro that has me stumped. On a Siemens 810D, I can write to a file but I cannot read the data back in. I don't get an error from the read command. Error Boolean = 0 , I just get no data. VALSTR[1] = VALSTR[2] = blank (no data).
Here is a program snippet:
N7 DEF INT FILE_ERROR ; READ WRITE ERROR RETURN
N8 DEF STRING[255] VALSTR[2] ;NUMBER AS A STRING
N10 DEF REAL SLNUM ; NUMBER
N12 DEF BOOL VALIS ;TEST RETURN OF ISNUMBER
N14
N20 READ(FILE_ERROR, "/_N_SPF_DIR/_N_TESTFILE_SPF", 0, 1, VALSTR)
N22 IF FILE_ERROR <>0
N24 MSG(<
N26 M00
N30 ENDIF
N32
N34 VALIS = ISNUMBER (VALSTR[1])
N36 IF VALIS == FALSE
N38 MSG("FILE DATA IS NOT A NUMBER," <
N40 M00
N44 ENDIF
N92 SLNUM = SLNUM + 1
N94
N96 VALSTR[1] = <
N104 WRITE(FILE_ERROR, "/_N_SPF_DIR/_N_TESTFILE_SPF", VALSTR[1])
N106 IF FILE_ERROR <>0
N108 MSG(<
N110 M00
N114 ENDIF
If I change "VALSTR" to VALSTR[1] in the read command I get a variable error. WHY?
Also my write file appends but does not OVER WRITE the existing data. WHY? The Programming Guide 11/2002 Edition, 1.17 WRITE Write file (SW 4.3 and higher) says: "If a file with the same name exists on the hard disk, it is overwritten after the file is closed (in the NC)."
Any guidance would be treasured.
-
-
Member
Re: Help with Siemens Macro Reading and Writing to a file
Because you definiens >> VALSTR[2] but when you write varitable name you must remember abaut syntax:
VALSTR[0] - 1
VALSTR[1] - 2
so when you read file READ(FILE_ERROR, FILE, 0, 1, VALSTR) you write data to VALSTR[0] not for VALSTR[1]
fix program:
PROC _N_RW_TEST_MPF SAVE
N10 DEF INT FILE_ERROR ; READ WRITE ERROR RETURN
N15 DEF STRING[255] VALSTR[2] ;2 LEVEL TABLE STRING
N20 DEF STRING[32] FILE
N25 FILE = "/_N_SPF_DIR/_N_TEST1_SPF"
N30 READ(FILE_ERROR, FILE, 0, 1, VALSTR)
N35 IF FILE_ERROR <> 0
N40 MSG(<
N45 M00
N50 GOTOF _END
N55 ENDIF
N60 IF NOT ISNUMBER(VALSTR[0])
N65 MSG("FILE DATA IS NOT A NUMBER," <
N70 M00
N75 GOTOF _END
N80 ENDIF
N85 VALSTR[0] = <<(NUMBER(VALSTR[0])+1)
N90 WRITE(FILE_ERROR, FILE, VALSTR[0])
N95 IF FILE_ERROR <> 0
N100 MSG(<
N105 M00
N110 GOTOF _END
N115 ELSE
N120 MSG("TESTFILE FILE WRITTEN SUCCESSFUL, TEXT FILE: "<
N125 G94 G4 F5 ;IN 1ST LINE AM USING COMMAND SAVE BECAUSE HERE CHANGE GCODE G94/G95
N130 ENDIF
N135 _END:
N140 MSG()
N145 M30
-
Re: Help with Siemens Macro Reading and Writing to a file
Thanks Partur. It works as needed. That was the missing information. Makes sense, it is just us humans that start counting at "1".
On another note:
What variable register would I use to store this VALSTR value that would not reset when the controller is powered down or reset? It would be further from inquisitive eyes and fingers? Again I have read the manual but do not understand exactly how to define the register and which register would be "safe" to use so I don't write over machine data.
-
Member
Re: Help with Siemens Macro Reading and Writing to a file
In the variable -> GUD (global user data) you have 100 string variable.
_TXT[0]
_TXT[1]
...
...
_TXT[98]
_TXT[99]
You can using this variable to store text string when machine is off.
macro start:
VALSTR = _TXT[0]
...
...
...
macro end:
_TXT[0] = VALSTR
m30
or working only on _TXT[*] string variable without VALSTR.
enjoy!
-
Re: Help with Siemens Macro Reading and Writing to a file
Partur,
Thanks for the quick reply.
It looks easier than I thought. Knowing about the GUD registers will open up a whole list of possibilities. I wonder why the Siemens documents don't do a better job of explaining the subject matter. I will let you know how it works out.
vfsi
- Help with Siemens Macro Reading and Writing to a file
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules