:lang: en
:toc:

[[cha:halui-examples]]
= Halui Examples(((Halui Examples)))

// Custom lang highlight
// must come after the doc title, to work around a bug in asciidoc 8.6.6
:ini: {basebackend@docbook:'':ini}
:hal: {basebackend@docbook:'':hal}
:ngc: {basebackend@docbook:'':ngc}

For any Halui examples to work you need to add the following line to the [HAL]
section of the ini file.

[source,{ini}]
----
HALUI = halui
----

[[sec:halui-remote-start]]
== Remote Start

To connect a remote program start button to LinuxCNC you use the
`halui.program.run` pin and the `halui.mode.auto` pin.
You have to ensure that it is OK to run first by using the
`halui.mode.is-auto` pin. You do this with an `and2`
component. The following figure shows how this is done.
When the Remote Run Button is pressed it is connected to
both `halui.mode.auto` and `and2.0.in0`. If it is OK for
auto mode the pin `halui.mode.is-auto` will be on.
If both the inputs to the `and2.0` component are on the
`and2.0.out` will be on and this will start the program.

.Remote Start Example
image::images/remote-start.png["Remote Start Example"]

The hal commands needed to accomplish the above are:

[source,{hal}]
----
net program-start-btn halui.mode.auto and2.0.in0 <= <your input pin>
net program-run-ok and2.0.in1 <= halui.mode.is-auto
net remote-program-run halui.program.run <= and2.0.out
----

Notice on line one that there are two reader pins, this can also be split
up to two lines like this:

[source,{hal}]
----
net program-start-btn halui.mode.auto <= <your input pin>
net program-start-btn and2.0.in0
----

== Pause & Resume

This example was developed to allow LinuxCNC to move a
rotary axis on a signal from an external machine.
The coordination between the two systems will be
provided by two Halui components:

- `halui.program.is-paused`
- `halui.program.resume`

In your customized HAL file, add the following
two lines that will be connected to your I/O to turn
on the program pause or to resume when the external
system wants LinuxCNC to continue.

[source,{hal}]
----
net ispaused halui.program.is paused => "your output pin"
net resume halui.program.resume <= "your input pin"
----

Your input and output pins are connected to the pins
wired to the other controller. They may be parallel port
pins or any other I/O pins that you have access to.

This system works in the following way. When an M0 is
encountered in your G-code, the `halui.program.is-paused`
signal goes true. This turns on your output pin so that
the external controller knows that LinuxCNC is paused.

To resume the LinuxCNC G-code program, when the external controller
is ready it will make its output true. This will signal
LinuxCNC that it should resume executing G-code.

Difficulties in timing

- The "resume" input return signal should not be
  longer than the time required to get the G-code
  running again.
- The "is-paused" output should no longer be active
  by the time the "resume" signal ends.

These timing problems could be avoided by using
ClassicLadder to activate the "is-paused" output via a
monostable timer to deliver one narrow output pulse.
The "resume" pulse could also be received via a monostable timer.

// vim: set syntax=asciidoc:
