Click to See Complete Forum and Search --> : Accessing LPT port in Win2K


sh_roohani
December 23rd, 2002, 07:56 AM
Hi,

Accessing LPT port in Windows 2000 raises the exception Privileged instruction up. I have used an instruction _outp(0x378, 0x01) to do this. Microsoft asserts that this is a CPU privileged instruction that could not be performed in user-mode applications in NT 4.0(MSDN Library - January 2001).

Is switching to kernel-mode possible via regular Windows 2000 API or it needs DDK? Is there possibly any other way to access LPT port?

Thanks,

Shahram Roohani

stober
December 23rd, 2002, 08:19 AM
You have to use the Win32 API print functions. Look them up in MSDN.

Andreas Masur
December 23rd, 2002, 09:26 AM
Originally posted by sh_roohani
Is there possibly any other way to access LPT port?

Thanks,

Shahram Roohani
The file input and output (I/O) functions ('CreateFile()', 'CloseHandle()', 'ReadFile()', 'ReadFileEx()', 'WriteFile()' and 'WriteFileEx()') provide the basic interface for opening and closing a communications resource handle and for performing read and write operations. Depending of what you are trying to do take also a look at the following functions...

// Parallel Device Callback Routines

USHORT *DetermineIeeeModes(IN PDEVICE_EXTENSION Extension)

NTSTATUS *IeeeFwdToRevMode(IN PDEVICE_EXTENSION Extension)

NTSTATUS *IeeeRevToFwdMode(IN PDEVICE_EXTENSION Extension)

NTSTATUS *NegotiateIeeeMode(IN PDEVICE_EXTENSION Extension,
IN USHORT ModeMaskFwd,
IN USHORT ModeMaskRev,
IN PARALLEL_SAFETY ModeSafety,
IN BOOLEAN IsForward)

NTSTATUS *ParallelRead(IN PDEVICE_EXTENSION Extension,
IN PVOID Buffer,
IN ULONG NumBytesToRead,
OUT PULONG NumBytesRead,
IN UCHAR Channel)

NTSTATUS *ParallelWrite(IN PDEVICE_EXTENSION Extension,
OUT PVOID Buffer,
IN ULONG NumBytesToWrite,
OUT PULONG NumBytesWritten,
IN UCHAR Channel)

NTSTATUS *TerminateIeeeMode(IN PDEVICE_EXTENSION Extension)


// Parallel Port Callback Routines

NTSTATUS *ClearChipMode(IN PDEVICE_EXTENSION Extension, IN UCHAR ChipMode)

NTSTATUS *DeselectDevice(IN PVOID Context, IN PVOID DeselectCommand)

VOID *FreePort(IN PVOID Context)

VOID *FreePortFromInterruptLevel(IN PVOID Context)

ULONG *QueryNumWaiters(IN PVOID Extension)

BOOLEAN *TryAllocatePort(IN PVOID Context)

BOOLEAN *TryAllocatePortAtInterruptLevel(IN PVOID Context)

NTSTATUS *TrySelectDevice(IN PVOID Context, IN PVOID TrySelectCommand)

NTSTATUS *TrySetChipMode(IN PDEVICE_EXTENSION Extension, IN UCHAR ChipMode)

All functions are coming from the Windows DDK (Driver Development Kit). For further information look within the MSDN (http:// msdn.microsoft.com)...

Depending on what you are trying to accomplish you might want to take a look at the NTPort library (http://www.zealsoftstudio.com/ntport/) which allows direct I/O port access...

TheCPUWizard
December 23rd, 2002, 10:12 AM
For a decent example of accessing the LPT ports take a look at the PortMon utility on SysInternals.com

Mark Redlon
January 6th, 2003, 10:47 AM
You could also try the _inp and _outp functions.

Andreas Masur
January 6th, 2003, 05:06 PM
Originally posted by Mark Redlon
You could also try the _inp and _outp functions.
IIRC you cannot use the functions directly in newer operating systems like NT, 2000 or XP. These functions need to run within the kernel mode therefore you need to go down on driver level...

sh_roohani
January 7th, 2003, 01:59 AM
Hi,

Yes, I agree Andreas. Note that I stated in my question that I have used _outp, but I got an 'exception Privileged instruction' message. I noticed that Intel processors in the mode which OSes like Windows 2000 work, have two set of instructions which could not be invoked normally in user mode : sensitive instructions and privileged instructions. _outp is categorized as a CPU privileged instruction and should be invoked in kernel mode either via DDK functions or a kernel-mode driver.

Regards.

Shahram Roohani

Andreas Masur
January 7th, 2003, 02:58 AM
Originally posted by sh_roohani
Hi,

Yes, I agree Andreas. Note that I stated in my question that I have used _outp, but I got an 'exception Privileged instruction' message.

Whoooppsss...I did not look at your original post before answering...sorry about that...

TheCPUWizard
January 7th, 2003, 07:19 AM
Since the topic is open....

I currently have a need to emulate a printer. Using a parallel cable (ala LapLink) I need to connect to the parallel port of another computer (which can not be touched in ANY way other than connecting the cable) and capture the printer output.

About two years ago I ran across a C / C++ library that was specifically for emulating printers. It used two LPT ports on the computer. One to capture the data (and privide responses jus like and HP Laser Jet) and then re-route the data out the other port via the currently selected driver.

If any one can remember this library name, or knows of any good starting points for this project, I would greatly appreciate it.

TIA.