The hal_parport component is a driver for the traditional PC parallel port. The port has a total of 17 physical pins. The original parallel port divided those pins into three groups: data, control, and status. The data group consists of 8 output pins, the control group consists of 4 pins, and the status group consists of 5 input pins.
In the early 1990s, the bidirectional parallel port was introduced, which allows the data group to be used for output or input. The HAL driver supports the bidirectional port, and allows the user to set the data group as either input or output. If configured as out, a port provides a total of 12 outputs and 5 inputs. If configured as in, it provides 4 outputs and 13 inputs.
In some parallel ports, the control group pins are open collectors, which may also be driven low by an external gate. On a board with open collector control pins. If configured as x, it provides 8 outputs, and 9 inputs.
Bei einigen parallelen Anschlüssen verfügt die Steuergruppe über Push-Pull-Treiber und kann nicht als Eingang verwendet werden.
Anmerkung
|
HAL und Open Collectors
HAL cannot automatically determine if the x mode bidirectional pins are actually open collectors (OC). If they are not, they cannot be used as inputs, and attempting to drive them LOW from an external source can damage the hardware. To determine whether your port has open collector pins, load hal_parport in x mode. With no device attached, HAL should read the pin as TRUE. Next, insert a 470 Ω resistor from one of the control pins to GND. If the resulting voltage on the control pin is close to 0 V, and HAL now reads the pin as FALSE, then you have an OC port. If the resulting voltage is far from 0 V, or HAL does not read the pin as FALSE, then your port cannot be used in x mode. The external hardware that drives the control pins should also use open collector gates, e.g. 74LS05. Bei einigen Computern können die BIOS-Einstellungen beeinflussen, ob der x-Modus verwendet werden kann. Der SPP-Modus funktioniert am ehesten. |
Andere Kombinationen werden nicht unterstützt, und ein Anschluss kann nach der Installation des Treibers nicht mehr von Eingang auf Ausgang umgestellt werden.
Der parport-Treiber kann bis zu 8 Ports steuern (definiert durch MAX_PORTS in hal_parport.c). Die Ports werden bei Null beginnend nummeriert.
1. Laden
The hal_parport driver is a real time component so it must be loaded into the real time thread with loadrt. The configuration string describes the parallel ports to be used, and (optionally) their types. If the configuration string does not describe at least one port, it is an error.
loadrt hal_parport cfg="Anschluss [Typ] [Anschluss [Typ] ...]"
Numbers below 16 refer to parallel ports detected by the system. This is the simplest way to configure the hal_parport
driver and cooperates with the Linux parport_pc driver if it is loaded. A port of 0 is the first parallel port detected on the system, 1 is the next and so on.
Dies wird den ersten parallelen Port verwenden, den Linux erkennt:
loadrt hal_parport cfg="0"
Stattdessen kann die Anschlussadresse in Hexadezimalschreibweise mit dem Präfix "0x" angegeben werden.
The config string represents the hexadecimal address of the port, optionally followed by a direction, all repeated for each port. The directions are in, out, or x, and determine the direction of the physical pins 2 to 9 of the D-Sub 25 connector. If the direction is not specified, the data group will by default be configured as outputs. For example:
loadrt hal_parport cfg="0x278 0x378 in 0x20A0 out"
This example installs the drivers for a port 0x0278, with pins 2 to 9 as outputs (by default, since neither in nor out is specified), a port 0x0378, with pins 2 to 9 as inputs and a 0x20A0 port, with pins 2 to 9 explicitly specified as outputs. Note that you must know the base address of the parallel ports to configure the drivers correctly. For ISA bus ports, this is usually not a problem, since the ports are almost always at a well-known address, such as 0x278 or 0x378 which are typically configured in the BIOS. The addresses of PCI bus cards are usually found with lspci -v
in an I/O ports line, or in a kernel message after running sudo modprobe -a parport_pc
. There is no default address, so if <config-string>
does not contain at least one address, it is an error.

Für jede parallele Schnittstelle, die vom hal_parport Treiber verwaltet wird, kann optional ein Typ angegeben werden. Der Typ ist einer von in, out, epp oder x.
Pin | in | out/epp | x |
---|---|---|---|
1 |
out |
out |
in |
2 |
in |
out |
out |
3 |
in |
out |
out |
4 |
in |
out |
out |
5 |
in |
out |
out |
6 |
in |
out |
out |
7 |
in |
out |
out |
8 |
in |
out |
out |
9 |
in |
out |
out |
10 |
in |
in |
in |
11 |
in |
in |
in |
12 |
in |
in |
in |
13 |
in |
in |
in |
14 |
out |
out |
in |
15 |
in |
in |
in |
16 |
out |
out |
in |
17 |
out |
out |
in |
Wenn der Typ nicht angegeben wird, ist der Standardwert "out".
Ein Typ epp ist derselbe wie out, aber der hal_parport Treiber fordert den Port auf, in den EPP-Modus zu wechseln. Der hal_parport-Treiber benutzt nicht das EPP-Busprotokoll, aber auf einigen Systemen ändert der EPP-Modus die elektrischen Eigenschaften des Ports auf eine Weise, die einige marginale Hardware besser funktionieren lässt. Es ist bekannt, dass die Ladungspumpe des Gecko G540 dies bei einigen parallelen Anschlüssen erfordert.
Siehe den obigen Hinweis zum Modus x.
Dadurch werden zwei vom System erkannte parallele Schnittstellen aktiviert, die erste im Ausgabemodus und die zweite im Eingabemodus:
loadrt hal_parport cfg="0 out 1 in"
Sie müssen LinuxCNC auch anweisen, die Funktionen Lesen und Schreiben auszuführen.
addf parport.0.read base-thread addf parport.0.write base-thread
2. PCI-Port-Adresse
One good PCI parport card is made with the Netmos 9815 chipset. It has good +5 V signals, and can come in a single or dual ports.
Um die E/A-Adressen für PCI-Karten zu finden, öffnen Sie ein Terminalfenster und verwenden Sie den Befehl list pci:
lspci -v
Suchen Sie nach dem Eintrag mit "Netmos". Beispiel einer 2-Port-Karte:
0000:01:0a.0 Communication controller: \
Netmos Technology PCI 9815 Multi-I/O Controller (rev 01)
Subsystem: LSI Logic / Symbios Logic 2POS (2 port parallel adapter)
Flags: medium devsel, IRQ 5
I/O ports at b800 [size=8]
I/O ports at bc00 [size=8]
I/O ports at c000 [size=8]
I/O ports at c400 [size=8]
I/O ports at c800 [size=8]
I/O ports at cc00 [size=16]
From experimentation, I’ve found the first port (the on-card port) uses the third address listed (c000), and the second port (the one that attaches with a ribbon cable) uses the first address listed (b800). The following example shows the onboard parallel port and a PCI parallel port using the default out direction.
loadrt hal_parport cfg="0x378 0xc000"
Please note that your values will differ. The Netmos cards are Plug-N-Play, and might change their settings depending on which slot you put them into, so if you like to get under the hood and re-arrange things, be sure to check these values before you start LinuxCNC.
3. Pins
-
parport.<p>.pin-`__<n>__
-out` (bit) Drives a physical output pin. -
parport.<p>.pin-`__<n>__
-in` (bit) Tracks a physical input pin. -
parport.<p>.pin-`__<n>__
-in-not` (bit) Tracks a physical input pin, but inverted.
For each pin, <p> is the port number, and <n> is the physical pin number in the 25 pin D-shell connector.
For each physical output pin, the driver creates a single HAL pin, for example: parport.0.pin-14-out
.
For each physical input pin, the driver creates two HAL pins, for example: parport.0.pin-12-in
and parport.0.pin-12-in-not
.
The -in
HAL pin is TRUE if the physical pin is high, and FALSE if the physical pin is low. The -in-not
HAL pin is inverted and is FALSE if the physical pin is high.
4. Parameter
-
parport.`__<p>__
.pin-__<n>__
-out-invert` (bit) Inverts an output pin. -
parport.`__<p>__
.pin-__<n>__
-out-reset` (bit) (only for-out
pins) TRUE if this pin should be reset when the-reset
function is executed. -
parport.`__<p>__
.reset-time` (U32) The time (in nanoseconds) between a pin is set by-write
and reset by the-reset
function if it is enabled.
The -invert
parameter determines whether an output pin is active high or active low. If -invert
is FALSE, setting the HAL -out
pin TRUE drives the physical pin high, and FALSE drives it low. If -invert
is TRUE, then setting the HAL -out
pin TRUE will drive the physical pin low.
5. Funktionen
-
parport.`__<p>__
.read` (funct) Reads physical input pins of port number <p> and updates HAL-in
and-in-not
pins. -
parport.read-all
(funct) Reads physical input pins of all ports and updates HAL-in
and-in-not
pins. -
parport.`__<p>__
.write` (funct) Reads HAL-out
pins of port number <p> and updates that port’s physical output pins. -
parport.write-all
(funct) Reads HAL-out
pins of all ports and updates all physical output pins. -
parport.`__<p>__
.reset` (funct) Waits untilreset-time
has elapsed since the associatedwrite
, then resets pins to values indicated by-out-invert
and-out-invert
settings.reset
must be later in the same thread aswrite
. If-reset
is TRUE, then thereset
function will set the pin to the value of-out-invert
. This can be used in conjunction with stepgen’s doublefreq to produce one step per period. The stepgen stepspace for that pin must be set to 0 to enable doublefreq.
The individual functions are provided for situations where one port needs to be updated in a very fast thread, but other ports can be updated in a slower thread to save CPU time. It is probably not a good idea to use both an -all
function and an individual function at the same time.
6. Häufige Probleme
Wenn das Laden des Moduls berichtet
insmod: error inserting '/home/jepler/emc2/rtlib/hal_parport.ko':
-1 Device or resource busy
dann stellen Sie sicher, dass das Standard-Kernelmodul parport_pc nicht geladen ist Fußnote:[In den LinuxCNC-Paketen für Ubuntu verhindert die Datei /etc/modprobe.d/emc2 im Allgemeinen, dass parport_pc automatisch geladen wird.] und dass kein anderes Gerät im System die I/O-Ports beansprucht hat.
Wenn das Modul geladen wird, aber nicht zu funktionieren scheint, ist die Anschlussadresse falsch.
7. DoubleStep verwenden
To setup DoubleStep on the parallel port you must add the function parport.n.reset after parport.n.write and configure stepspace to 0 and the reset time wanted. So that step can be asserted on every period in HAL and then toggled off by parport after being asserted for time specified by parport.`__n__
.reset-time`.
Zum Beispiel:
loadrt hal_parport cfg="0x378 out" setp parport.0.reset-time 5000 loadrt stepgen step_type=0,0,0 addf parport.0.read base-thread addf stepgen.make-pulses base-thread addf parport.0.write base-thread addf parport.0.reset base-thread addf stepgen.capture-position servo-thread ... setp stepgen.0.steplen 1 setp stepgen.0.stepspace 0
More information on DoubleStep can be found on the wiki.
8. probe_parport
In today’s PCs, parallel ports may require a plug and play (PNP) configuration before they can be used. The kernel module probe_parport configures all PNP ports present. It must be loaded before hal_parport. On machines without a PNP port, it can be loaded but will have no effect.
8.1. Installation von probe_parport
Wenn das Kernelmodul parport_pc
mit dem Befehl geladen wird:
sudo modprobe -a parport_pc; sudo rmmod parport_pc
Der Linux-Kernel gibt eine Meldung ähnlich der folgenden aus:
parport: PnPBIOS parport erkannt.
Dann wird die Verwendung dieses Moduls wahrscheinlich notwendig sein.
Schließlich sollten die HAL-Parport-Komponenten geladen werden:
loadrt probe_parport loadrt hal_parport ...