"function _ nofp;" I'm guessing this calls the "FUNCTION(_)" but what does the underscore do?
The _ is used to indicate that the function does not have a name in HAL.
Often a component will have a read and a write (or some other multiple functions) and then you will see:
addf function.read servo-thread
addf function.make-pulses base-thread
etc.
In your case the function will just be called palletchange.
"nofp" means that the component does no floating-point calculations. Which is probably true in this case, but you can probably imit it for a component that runs in the servo thread.
Note that "addf" means that the component will be called every servo or base-thread period. More on that later.
" ;; " no idea what this is for??
It is used to split the bit of the file which is halcompile directives from the bit that is pure C-code.
Line 41: Will this code show a popup in Axis?
Yes
Line 42: How do I halt the code after an error occurred?
General errors I've made?
These are the same thing
A realtime HAL component must never stop. It has to run through to completion in a very few microseconds or the entire system will lock up.
This also means "no while loops that depend on input" too. You have to be sure that loops will complete every time.
So, the normal way to code a HAL component is as a state machine. A variable (often set up as a HAL pin, so you can see what is happening) is used to tell the component what it was doing last time it was called.
See, as an example, the carousel.comp, specifically the main "switch" statement
github.com/LinuxCNC/linuxcnc/blob/master...s/carousel.comp#L228
For example note that in state 0 (waiting) the system can move to states 1, 5 or 10. But that every state always runs straight through to completion.