2.9.3 INI_VARS issue
- Aciera
- Offline
- Administrator
Less
More
- Posts: 4081
- Thank you received: 1763
06 Jan 2025 19:55 - 06 Jan 2025 20:57 #318255
by Aciera
Appologies, I just realized that I was testing in current master so I changed to 2.9.3 and there does seem to be something strange going on.
1. If I test with [RS274NGC]INI_VARS = 1 then I can indeed reproduce these issues
2. If I test without [RS274NGC]INI_VARS = 1 (default value is 1) then I can read and write(!) #<_ini[TOOLSETTER]z_tool> (I don't get the error when trying to write)
[edit]
Note this is actually unrelated to the version but to the upper/lower case variable name in the ini file, see below
Replied by Aciera on topic 2.9.3 INI_VARS issue
1. If I test with [RS274NGC]INI_VARS = 1 then I can indeed reproduce these issues
2. If I test without [RS274NGC]INI_VARS = 1 (default value is 1) then I can read and write(!) #<_ini[TOOLSETTER]z_tool> (I don't get the error when trying to write)
[edit]
Note this is actually unrelated to the version but to the upper/lower case variable name in the ini file, see below
Last edit: 06 Jan 2025 20:57 by Aciera.
Please Log in or Create an account to join the conversation.
- shipmodeller
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 55
- Thank you received: 3
06 Jan 2025 20:00 #318256
by shipmodeller
Replied by shipmodeller on topic 2.9.3 INI_VARS issue
I followed your Debug patterns in attachment
Please Log in or Create an account to join the conversation.
- shipmodeller
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 55
- Thank you received: 3
06 Jan 2025 20:01 #318257
by shipmodeller
Replied by shipmodeller on topic 2.9.3 INI_VARS issue
Ok, thanks for verifying the issues I was having...
Please Log in or Create an account to join the conversation.
- Aciera
- Offline
- Administrator
Less
More
- Posts: 4081
- Thank you received: 1763
06 Jan 2025 20:24 #318258
by Aciera
Replied by Aciera on topic 2.9.3 INI_VARS issue
So it seems to me that it does not like the lowercase entry in the ini file:
If I change this to
I get the expected behavior.
z_tool = -1
If I change this to
Z_TOOL = -1
I get the expected behavior.
Please Log in or Create an account to join the conversation.
- Aciera
- Offline
- Administrator
Less
More
- Posts: 4081
- Thank you received: 1763
06 Jan 2025 20:53 #318261
by Aciera
Replied by Aciera on topic 2.9.3 INI_VARS issue
Just went back to current master and I can confirm that the problem is the lowercase variable (or key) name 'z_tool'.
1. A lowercase variable (key) name in the ini file is ignored (eg 'z_tool = 1').
2. If you then want to read the lowercase variable (eg #<_ini[TOOLSETTER]z_tool>) the value is not found because it was never created
3. if you assign a value (eg: #<_ini[TOOLSETTER]z_tool> = 1.2) you actually create a global named parameter
So the key is to ALWAYS use uppercase variables (keys) in the ini file (which should probably be noted somewhere in the documentation)
1. A lowercase variable (key) name in the ini file is ignored (eg 'z_tool = 1').
2. If you then want to read the lowercase variable (eg #<_ini[TOOLSETTER]z_tool>) the value is not found because it was never created
3. if you assign a value (eg: #<_ini[TOOLSETTER]z_tool> = 1.2) you actually create a global named parameter
So the key is to ALWAYS use uppercase variables (keys) in the ini file (which should probably be noted somewhere in the documentation)
The following user(s) said Thank You: shipmodeller
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
Less
More
- Posts: 23182
- Thank you received: 4869
07 Jan 2025 12:12 - 07 Jan 2025 12:12 #318294
by andypugh
Replied by andypugh on topic 2.9.3 INI_VARS issue
Lower-case INI file variables are OK in most circumstances.
For example adding this into the Touchy GUI init code (I just happened to have that one in the editor, not a special choice)
And inserting this in the corresponding INI file
Gives this result
So lower case INI variables work in the general case.
But it seems that they do _not_ work in the case of G-code INI-file access.
This is probably because all G-code is lowercased before being sent to the interpreter. And then the bit of the interpreted that reads #<_ini....> variables explicitly uppercases them.
github.com/LinuxCNC/linuxcnc/blob/master..._namedparams.cc#L222
So, the actual situation is that if you want to read an INI variable from G code it must be capitalised, because case info is lost during the process of interpreting the G-code, and the interpeter assumes capitals.
To answer a question from the original posts, you can create a set of global parameters with particular values in the STARTUP_GCODES (would need to be a custom code or subroutine call, though).
But reading from the INI is probably best, accepting the limitations discussed here.
For example adding this into the Touchy GUI init code (I just happened to have that one in the editor, not a special choice)
print("The value of [TEST]testywesty is %s" % self.ini.find("TEST", "testywesty"))
print("The value of [TEST]CAPITAL is %s" % self.ini.find("TEST", "CAPITAL"))
print("The value of [TEST]IDONTEXIST is %s" % self.ini.find("TEST", "IDONTEXIST"))
And inserting this in the corresponding INI file
[TEST]
testywesty = 12.3
CAPITAL = 4.56
Gives this result
The value of [TEST]testywesty is 12.3
The value of [TEST]CAPITAL is 4.56
The value of [TEST]IDONTEXIST is None
So lower case INI variables work in the general case.
But it seems that they do _not_ work in the case of G-code INI-file access.
This is probably because all G-code is lowercased before being sent to the interpreter. And then the bit of the interpreted that reads #<_ini....> variables explicitly uppercases them.
github.com/LinuxCNC/linuxcnc/blob/master..._namedparams.cc#L222
So, the actual situation is that if you want to read an INI variable from G code it must be capitalised, because case info is lost during the process of interpreting the G-code, and the interpeter assumes capitals.
To answer a question from the original posts, you can create a set of global parameters with particular values in the STARTUP_GCODES (would need to be a custom code or subroutine call, though).
But reading from the INI is probably best, accepting the limitations discussed here.
Last edit: 07 Jan 2025 12:12 by andypugh.
The following user(s) said Thank You: Aciera
Please Log in or Create an account to join the conversation.
Time to create page: 0.073 seconds