As said, you could use m4 to do this

ifdef ('foo',
   "hall code here to do foo-stuff",

   "hal dode here to not non-foo-stuff",
)

You can use m4 to add ifdef-like processing to any kind of file.

So a more concrete example would be to make an dot.m4 file that reads as
follows.  You can use # for m4 comments

ifdef ('use_stepgen',
    # this is processed if use_stepgen is defined
    "net spindle-vel-fb-rps  <=  hm2_7i92.0.stepgen.05.velocity-fb",

    # if use_stepgen is not defined
    "net spindle-vel-fb-rps  <=  hm2_7i92.0.encoder.01.velocity")

Then at the top of the file or in the run-time argument to m4 you either
define "use_stepgen" or not.  This saves having to add and remove many #
comments.    Also m4 has of course macros you factor or repetitive test and
use it many times. So you can get even more esoteric with M4 and do this

spindleNetAssign = "net spindle-vel-fb-rps  <=  hm2_7i92.0."
ifdef ('use_stepgen',
    "$(spindleNetAssign)stepgen.05.velocity-fb",
    "$(spindleNetAssign)encoder.01.velocity")

The above can be called either "greatly simplified" or "completely
unreadable, depending in opinion and how used to macro processing you are.
 The advantage of implied form is that you will never later have to make an
identical edit in two places or type the same text twice.    But debugging
is harder as you have added one more abstraction layer.

As said before you likely already have m4 installed on your Linux system.



On Wed, Jun 16, 2021 at 9:50 PM John Dammeyer <jo...@autoartisans.com>
wrote:

> Not sure I understand.  Say for example the existing HAL file has this:
>
> net spindle-vel-fb-rps      <=  hm2_7i92.0.stepgen.05.velocity-fb
>
> But now I'm trying to get the HAL file correct so LinuxCNC starts without
> errors.
>
> net spindle-vel-fb-rps       <=   hm2_7i92.0.encoder.01.velocity
>
> Now I can go through and comment things out with a '#' on each line but my
> existing spindle has a 'near'  and 'ramped' feature to make it accelerate
> more slowly.  There are suddenly a lot of '#' comments and it gets hard to
> read.
>
> So how would I use haltcl to select one or the other of the above
> examples.  I mean I know I need to not use the stepgen velocity feedback to
> show spindle velocity because that's now the encoders job but there are a
> lot of non-starters at the moment.
>
>
> > -----Original Message-----
> > From: Phill Carter [mailto:phillcarte...@gmail.com]
> > Sent: June-16-21 9:12 PM
> > To: linuxcnc-users
> > Subject: Re: [Emc-users] #ifdef
> >
> >
> >
> > > On 17 Jun 2021, at 2:03 pm, John Dammeyer <jo...@autoartisans.com>
> wrote:
> > >
> > > Is there something like an
> > >
> > > #ifdef
> > > #else
> > > #endif
> > >
> > > in HAL files?
> > > Thanks
> > > John
> >
> > No, but it is possible to use HALTCL files.
> >
> > <http://linuxcnc.org/docs/devel/html/hal/haltcl.html <
> http://linuxcnc.org/docs/devel/html/hal/haltcl.html>>
> >
> >
> > >
> > > "ELS! Nothing else works as well for your Lathe"
> > > Automation Artisans Inc.
> > > www dot autoartisans dot com
> > >
> > >
> > > _______________________________________________
> > > Emc-users mailing list
> > > Emc-users@lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/emc-users
> >
> >
> > _______________________________________________
> > Emc-users mailing list
> > Emc-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/emc-users
>
>
>
> _______________________________________________
> Emc-users mailing list
> Emc-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/emc-users
>


-- 

Chris Albertson
Redondo Beach, California

_______________________________________________
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users

Reply via email to