Page 1 of 2
How to reset a User-String-Variable #300 - #399?
Posted: Thu May 09, 2019 3:42 pm
by swissi
As the title says, I'm struggling to find a way to reset user-string-variables #300 - #399. These variables keep their value until you quit CNC12, so good practice would be to reset them when you no longer need them.
I tried the usual way #300 = "" to assign a zero-length string but CNC12 does not like that and gives an error "501 Invalid character".
The only way I found is to set the variable to #300 = " " but that assigns a single blank to the variable and messes up my output strings if the variable is not getting filled and should output a zero length string.
Does anybody know how to reset these variables without closing CNC12 and restart it?
-swissi
Re: How to reset a User-String-Variable #300 - #399?
Posted: Thu May 09, 2019 3:52 pm
by AcornJosh
I assume your are trying to modify your PLC? Could you please post a report and explain what you are trying to do?
Re: How to reset a User-String-Variable #300 - #399?
Posted: Thu May 09, 2019 4:51 pm
by swissi
Not trying to modify the PLC. Just trying to reset a user-string-variable back to zero-length.
Here's an example:
Code: Select all
;------------------------------------------------------------------------------
; Filename: test.cnc
; VARIABLES USED
; #301 - String Variable 1
; #302 - String Variable 2
; #303 - String Variable 3
#101 = 0 ; How many seconds a message should be displayed. 0 is indefinitely and needs to be confirmed with Cycle Start
;------------------------------------------------------------------------------
#301 = "ABCDE"
#302 = "FGHIJ"
#303 = "KLMNO"
M225 #101 "#)The combined string is: %s%s%s\n\n Press Cycle Start to continue\n" #301 #302 #303
#302 = " "
M225 #101 "#)The combined string is: %s%s%s\n\n Press Cycle Start to continue\n" #301 #302 #303
M99 ; Return to calling job/macro
The first message displays as expected:
and the second message has that space between string 1 and string 3.
So the question is: How to I reset variable #302 back to zero-length so it doesn't print a space between string 1 and string 3?
-swissi
Re: How to reset a User-String-Variable #300 - #399?
Posted: Sat May 11, 2019 9:39 pm
by DannyB
Does setting them to zero (the number) work?
Re: How to reset a User-String-Variable #300 - #399?
Posted: Sat May 11, 2019 10:54 pm
by wellington_tregear
swissi wrote: ↑Thu May 09, 2019 4:51 pm
Not trying to modify the PLC. Just trying to reset a user-string-variable back to zero-length.
Here's an example:
Code: Select all
;------------------------------------------------------------------------------
; Filename: test.cnc
; VARIABLES USED
; #301 - String Variable 1
; #302 - String Variable 2
; #303 - String Variable 3
#101 = 0 ; How many seconds a message should be displayed. 0 is indefinitely and needs to be confirmed with Cycle Start
;------------------------------------------------------------------------------
#301 = "ABCDE"
#302 = "FGHIJ"
#303 = "KLMNO"
M225 #101 "#)The combined string is: %s%s%s\n\n Press Cycle Start to continue\n" #301 #302 #303
#302 = " "
M225 #101 "#)The combined string is: %s%s%s\n\n Press Cycle Start to continue\n" #301 #302 #303
M99 ; Return to calling job/macro
The first message displays as expected:
Cap1.JPG
and the second message has that space between string 1 and string 3.
Cap2.JPG
So the question is: How to I reset variable #302 back to zero-length so it doesn't print a space between string 1 and string 3?
-swissi
Just don't call #302. Omit it until you want it. See the second to last line.
Code: Select all
;------------------------------------------------------------------------------
; Filename: test.cnc
; VARIABLES USED
; #301 - String Variable 1
; #302 - String Variable 2
; #303 - String Variable 3
#101 = 0 ; How many seconds a message should be displayed. 0 is indefinitely and needs to be confirmed with Cycle Start
;------------------------------------------------------------------------------
#301 = "ABCDE"
#302 = "FGHIJ"
#303 = "KLMNO"
M225 #101 "#)The combined string is: %s%s%s\n\n Press Cycle Start to continue\n" #301 #302 #303
#302 = " "
M225 #101 "#)The combined string is: %s%s\n\n Press Cycle Start to continue\n" #301 #303
M99 ; Return to calling job/macro
Re: How to reset a User-String-Variable #300 - #399?
Posted: Sun May 12, 2019 8:30 am
by tblough
My guess is they are using a null (\0) as the end of string character. You could try $0, but the manual specifically states only ASCII codes 65-90 are allowed.
The only other thing I could think of is to reserve one string variable that you never use and assign that to clear your variable.
Code: Select all
;------------------------------------------------------------------------------
; Filename: test.cnc
; VARIABLES USED
; #301 - String Variable 1
; #302 - String Variable 2
; #303 - String Variable 3
; #399 - Reserved String Variable (do not use)
#101 = 0 ; How many seconds a message should be displayed. 0 is indefinitely and needs to be confirmed with Cycle Start
;------------------------------------------------------------------------------
#301 = "ABCDE"
#302 = "FGHIJ"
#303 = "KLMNO"
M225 #101 "#)The combined string is: %s%s%s\n\n Press Cycle Start to continue\n" #301 #302 #303
#302 = #399
M225 #101 "#)The combined string is: %s%s%s\n\n Press Cycle Start to continue\n" #301 #302 #303
M99 ; Return to calling job/macro
Re: How to reset a User-String-Variable #300 - #399?
Posted: Sun May 12, 2019 11:55 am
by swissi
Thanks guys for all the suggestions but none of them seems to work. Even assigning one string variable to another generates a "501 Invalid character" error.
I hope nobody will argue that resetting a variable is an essential and basic function in any programming language. Especially so when the variables are global and will only be reset when the program is exited.
So my guess is that the fact that CNC12 generates an error when trying to set a string variable = "" was an oversight of the programmer who wrote the "check string for legal character" function.
Centroid can you please fix that?
-swissi
Re: How to reset a User-String-Variable #300 - #399?
Posted: Sun May 12, 2019 1:22 pm
by Muzzer
That's damned annoying. I think this arises partly because macro variables are initially "null" ie they don't even have a zero or any other value when initialised. So if you can't ascribe a null value to them without power cycling, there is no way around it. I guess you would need to be able to set the variables to ASCII value 0 which is the null character.
Re: How to reset a User-String-Variable #300 - #399?
Posted: Tue May 14, 2019 11:04 am
by cnckeith
Muzzer wrote: ↑Sun May 12, 2019 1:22 pm
That's damned annoying. I think this arises partly because macro variables are initially "null" ie they don't even have a zero or any other value when initialised. So if you can't ascribe a null value to them without power cycling, there is no way around it. I guess you would need to be able to set the variables to ASCII value 0 which is the null character.
please tell me the goal of project? we are trying to understand your application for this..thanks..
Re: How to reset a User-String-Variable #300 - #399?
Posted: Tue May 14, 2019 11:23 am
by tblough
Keith,
It looks like swissi is just trying to apply good programming practice to his macro files. Since string variables are global and only cleared on restart of the machine, he wants to clear them after he is done using them so that the next macro to use the variable (if it happens before the machine is restarted) does not potentially get bad data. Unlike the numerical variables, there currently is not a way to set a string variable to it's initial "empty" state.