Enabling and Configuring Parallel (LPTx) Ports

Everything which doesn't fit into the other sections.
Post Reply
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Enabling and Configuring Parallel (LPTx) Ports

Post by mpack »

Introduction

On several occasions the mods have been asked for instructions on how to enable and configure LPT (parallel port) passthrough in a guest. LPT passthrough is a feature which has been requested for years, and was finally implemented with very little fanfare in VirtualBox v4.2.0 (*). The release logs and documentation make only passing mention of it, which possibly reflects a low level of confidence the devs have in this new feature. Basically, it's an (almost) undocumented feature, so if you can't get it to work... well just don't expect too much.

(*) In fact parallel ports were usable on Linux hosts only since the Innotek days, but this was never officially documented. From v4.2.0, Windows host support was added, and support was documented in the user manual albeit briefly.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Enabling and Configuring Parallel (LPTx) Ports

Post by mpack »

Caveats

One problem with writing this advice note is that, while I do know enough to write the tutorial, none of my current PCs any longer has a parallel port, so I am unable to fully test the advice. I suspect the same will be true of other mods. So, we'll just have to make do for now, and if you find some error in the instructions then let me know and I'll amend it.

It so happens that I am most familiar with this stuff on Windows hosts. Linux hosts will be similar except for the device names. I will add Linux notes where I can, and I'm open to corrections. As far as I know, no Intel based Mac host ever had parallel ports, so I will be ignoring MacOS hosts in these instructions.

One final thing worth mentioning is that most people don't need to add a virtual LPT port to their VM. If all you want is to be able to print from inside a VM, and the printer already works on your host, then an infinitely better solution is to share the printer on the virtual network. Host-only networking mode is perfect for this, or if the guest is already using Bridged networking then that is equally good, provided of course that host and guest are configured to be on the same workgroup or domain.
 Edit:  Additional note. Don't bother trying to redirect the output of a guest's LPTx to a host file. That will not work. The feature provides a passthrough to the host port at a low level in order to allow GPIO type bidirectional control. It is not a file stream. 
Last edited by mpack on 26. Aug 2020, 10:02, edited 2 times in total.
Reason: Added additional note
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Enabling and Configuring Parallel (LPTx) Ports

Post by mpack »

Step 1: Understanding

Configuring an LPT port requires that you supply the host device name, plus I/O base address and IRQ (Interrupt ReQuest) selections for the guest.

The first step in solving a problem is understanding it. One of the main things new users often do not understand is the precise relevance of the base address and IRQ settings. The most common mistake is to believe that it should be the same as on the host, which is quite wrong.

VirtualBox is just another application running on your host. Do any of your other host applications need to be told what base address and IRQ to use for some device? No? The application just talks to the host OS? Well guess what, VirtualBox is no different. Just because the application simulates hardware doesn't make its own hardware requirements anything special. Hence the base address and IRQ settings for your host LPTx port is totally irrelevant, all you need to know is the device name, e.g. "LPT1" ("/dev/parport0" on Linux I think).

As mentioned, the purpose of VirtualBox is to simulate hardware, and when you are doing a hardware simulation you do need to know which part of IO memory space you are supposed to pretend to be located in, and which simulated IRQ signal it should pretend to be connected to. Since there is no reason to use anything other than defaults for these values, you should stick to the defaults: base address 0x378, IRQ7, which a Windows guest will typically detect as "LPT1".

So a final reiteration: if the parallel port you want to use on your host is called LPT4, then the correct guest configuration is: base address = 0x378, IRQ7, name="LPT4", which will be detected inside the guest as LPT1 (or whatever name your particular guest OS usually gives to the first parallel port).

By the way, similar logic applies to the base address and IRQ settings for a serial port (UART).
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Enabling and Configuring Parallel (LPTx) Ports

Post by mpack »

Step 2: Configuring the VirtualBox VM on the Host

At the time of writing, the current version of VirtualBox (v6.1.12) does not have GUI support for configuring the LPT settings of the VM, you must instead use the VBoxManage command in a terminal window (command console). Users of Windows hosts often have difficulty understanding how to use a command line: just open the command console (cmd.exe), change to the VBoxManage folder by typing cd "c:\Program Files\Oracle\VirtualBox" (note the double quotes around the path string, since it contains a space), and then you can type the additional commands shown below :-

General command syntax (fields in < > brackets are placeholders, the brackets are not literal):

Code: Select all

VBoxManage modifyvm <VMname> --lptmode1 <host LPT device name>
VBoxManage modifyvm <VMname> --lpt1 0x378 7
Windows Host Example (where the host port I want to use is called "LPT4"):

Code: Select all

VBoxManage modifyvm "My VM Name" --lptmode1 "LPT4"
VBoxManage modifyvm "My VM Name" --lpt1 0x378 7
Linux Host Example equivalent to above:

Code: Select all

VBoxManage modifyvm "My VM Name" --lptmode1 "/dev/parport3"
VBoxManage modifyvm "My VM Name" --lpt1 0x378 7
All of the above examples configure a virtual LPT1 inside the guest. Of course you could configure another guest port instead, but there isn't much point in doing so hence I have ignored that possibility in the instructions.

The above also tells VirtualBox which host port you want to use. VirtualBox does not check at this point that the host port actually exists. Nor does it guarantee that your host OS will allow VirtualBox to use that port. In particular, if you install a parallel port printer driver on the host, and if that driver opens the parallel port when the host starts up, then that port may not be available for the guest to use (it depends on the driver). Parallel ports are legacy devices which were never designed to be shared, only one application (or driver) at a time can "own" the port.

Step 2a: Additional Notes for Linux Hosts
VirtualBox may be blocked from accessing the parallel port due to permission issues. Make sure that your user name is in the lp and lpadmin group on the host. Remember to log out and in again for permission changes to "take".

You may find that you still can't access the printer because the kernel is already using it. You'll get a message to the effect "could not claim parallel port". I'm told that the solution is to unload the "lp" module from the kernel, e.g. using "sudo modprobe -r lp".
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Enabling and Configuring Parallel (LPTx) Ports

Post by mpack »

Step 3a: Configuring a Windows Guest OS

In some cases, even though you have configured the VM recipe correctly, a Windows guest will fail to detect the parallel port. Usually this is because a parallel port is not regarded as "plug and play". You need to manually force a scan for new hardware, by going into the guests Control Panel and selecting "Add new Hardware". If you followed the instruction above then a Windows guest will always detect the hardware as "LPT1", which you can check by viewing the "Ports" branch in Device Manager. Applications running in the guest should be configured to use LPT1.

Edit: It has come to my attention that VirtualBox does not currently (v4.2.6) support parallel port interrupts, hence these should be disabled inside the guest.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Enabling and Configuring Parallel (LPTx) Ports

Post by mpack »

Step 3b: Configuring a Linux Guest OS

To be filled in by someone who knows Linux better than me.

Edit: It has come to my attention that VirtualBox does not currently (v4.2.6) support parallel port interrupts, hence these should be disabled inside the guest.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Enabling and Configuring Parallel (LPTx) Ports

Post by mpack »

Step 4: Manage Expectations

At the time of writing this feature is not well tested. Also, it is true that extra latency (i.e. slower response) is an inevitable feature of VMs, so if your parallel device is very fussy about timing then it probably will not work in a VM, and nothing can be done about it.

If, at the end of your experiment, you decide you don't need a parallel port in the guest after all, then it can be disabled again thusly (same on Windows or Linux hosts):

Code: Select all

VBoxManage modifyvm "My VM Name" --lpt1 off
Post Reply