custom hal component failed to compile, undeclared (first use in this function)

More
13 Dec 2022 01:45 - 13 Dec 2022 01:49 #259288 by smc.collins
working on building a custom hal component for the cinturn turret, and despite the fact that " per the man pages" this appears to be properly declared at the top of the file, I am getting compilation errors that it is in fact not properly declared. I search for about 4hrs tonight looking for a clear cut answer on declaration of functions, variable etc and came back mostly empty handed. The documentation loosely eludes to c or python style declarations, and still everything appears to be correct regarding the contradictory statements that halcompile uses hal like naming and function calls, or c or python ??? which is it ?  particularly when tied to pin/bin in/out variable term.. I see also that halcompile doesn't need to use a header file, which is nice, but do I need to use a C/python/hal ??? style init or function etc to create these instances ??? I have looked at multiple hal comp source files and I don't see the error here. 

Sorry Rod, I thought I attached the right file. damn I really dislike the new windows file manager. 
Attachments:
Last edit: 13 Dec 2022 01:49 by smc.collins.
The following user(s) said Thank You: rodw

Please Log in or Create an account to join the conversation.

More
13 Dec 2022 01:47 #259289 by rodw
It would be helpful if you could share the .comp file :)
 
The following user(s) said Thank You: smc.collins

Please Log in or Create an account to join the conversation.

More
13 Dec 2022 01:50 - 13 Dec 2022 01:53 #259290 by smc.collins

It would be helpful if you could share the .comp file :)

 

 

wiki.linuxcnc.org/uploads/oracchanger.comp

fixed, and based on the code here Rod. 
Last edit: 13 Dec 2022 01:53 by smc.collins.

Please Log in or Create an account to join the conversation.

More
13 Dec 2022 03:06 #259293 by rodw
Great stuff!
My general thoughts on comp files is that they are being called from a timer interrupt (the servo thread) so they should be short and sharp and avoid loops. Let the Servo thread to the looping for you. Often you will see state machines (as you have) controlling the execution. Most features of C are supported. equates and enums, structs etc. You can call  a function as normal. You can #include .H files. There are addidional extensions to create the man page before the code starts via python comments.

I personally think they are Linuxcnc's best kept secret. What other system lets you write custom code that is then treated as if its part of the Linuxcnc core? You can write pages of obfuscated hal or you can write  a few lines of C... :)
The following user(s) said Thank You: smc.collins

Please Log in or Create an account to join the conversation.

More
13 Dec 2022 03:37 - 13 Dec 2022 03:38 #259294 by smc.collins
oh, my code isn't fixed, it's still broken afaict with declaration failures, and I don't really understand why. Unless you are hinting that I need to include my hal file, which, could I suppose act as a header???? little help here would be nice. I think the logic looks correct, but I could be very wrong 
Last edit: 13 Dec 2022 03:38 by smc.collins.

Please Log in or Create an account to join the conversation.

More
13 Dec 2022 09:03 #259306 by rodw
What is the error text and what line number does it refer 
T​​​o?

Please Log in or Create an account to join the conversation.

More
13 Dec 2022 12:40 #259309 by smc.collins
line 69 70, etc, its where lock, locked, etc ate called as true false.

undeclared ( first use in function)

Please Log in or Create an account to join the conversation.

More
13 Dec 2022 20:26 #259357 by rodw
I wonder if its the true and false its complaining about? I think they are defined in stdbool.h so they are not loaded.

try up near the top
#define true 1
#define false 0

or
const int true = 1;
const int false = 0;
The following user(s) said Thank You: smc.collins

Please Log in or Create an account to join the conversation.

More
13 Dec 2022 21:06 - 13 Dec 2022 22:01 #259366 by smc.collins
i was thinking it was a init issue but the documents are murky. I'll give this a try once i get home.

thanks Rodw

I get this error when adding either type of define/declaration. technically this is a bit tied to a pin afaict, but does that make it a pin ? should it be something along the lines of 

bit in 1 = true
bit in 0 = false ?


these are generating the errors below.
#define true 1
#define false 0

or
const int true = 1;
const int false = 0;

Cinturnchanger.comp:4:1: Trying to find one of "$", "pin", "param", "function", "variable", "option", "see_also", "notes", "description", "license", "author", "include", "modparam"
 
Last edit: 13 Dec 2022 22:01 by smc.collins.

Please Log in or Create an account to join the conversation.

More
14 Dec 2022 01:14 - 14 Dec 2022 01:15 #259384 by smc.collins
I've checked all the line ending settings, they are all set fo unix/linux with \n

and I am really confused by the () errors, there's nothing at line 80:15, it's white space


~/linuxcnc$ halcompile --compile Cinturnchanger.comp
Cinturnchanger.comp:0: Warning: File contains DOS-style or Mac-style line endings.
Compiling realtime Cinturnchanger.c
Cinturnchanger.comp: In function ‘_’:
Cinturnchanger.c:80:15: error: expected identifier or ‘(’ before numeric constant
#define true (1)
^
Cinturnchanger.comp:73:11: note: in expansion of macro ‘true’
Cinturnchanger.c:82:16: error: expected identifier or ‘(’ before numeric constant
#define false (0)
^
Cinturnchanger.comp:74:11: note: in expansion of macro ‘false’
Cinturnchanger.comp:80:25: error: ‘turret’ undeclared (first use in this function); did you mean ‘true’?
Cinturnchanger.comp:80:25: note: each undeclared identifier is reported only once for each function it appears in
Cinturnchanger.comp:80:32: error: ‘unlocked’ undeclared (first use in this function); did you mean ‘clock_t’?
Cinturnchanger.comp:81:32: error: ‘locked’ undeclared (first use in this function); did you mean ‘clock_t’?
Cinturnchanger.comp:94:25: error: ‘Strobe’ undeclared (first use in this function); did you mean ‘true’?
Cinturnchanger.comp:94:32: error: ‘Switch’ undeclared (first use in this function)
Cinturnchanger.comp:134:26: error: ‘BCD’ undeclared (first use in this function)
make: *** [/usr/share/linuxcnc/Makefile.modinc:115: Cinturnchanger.o] Error 1
Attachments:
Last edit: 14 Dec 2022 01:15 by smc.collins.

Please Log in or Create an account to join the conversation.

Time to create page: 0.087 seconds
Powered by Kunena Forum