Problem with printing to industrial printer

snoopy123123

Member
Joined
Jun 24, 2013
Messages
6
Programming Experience
5-10
Hello I am using the following code that was used in a different application in VS 2005 to print to a Printer via LPT1 port.

I am using VS2010 and the application completely locks up at the fsPrint.Write command. No exception, nothing. Does anyone see what I am doing wrong ?


VB.NET:
[COLOR=#000000][FONT=Consolas][SIZE=2]Dim hParallelPort As Microsoft.Win32.SafeHandles.SafeFileHandle
hParallelPort = CreateFile("LPT1", GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero)
[/SIZE][/FONT][/COLOR][FONT=Consolas][SIZE=2][COLOR=#000000]Dim bBuffer() As Byte = System.Text.Encoding.ASCII.GetBytes(Buffer)[/COLOR]
[COLOR=#000000]Dim fsPrint As New FileStream(hParallelPort, FileAccess.Write, bBuffer.Length, False)[/COLOR]
[COLOR=#000000]
fsPrint.Write(bBuffer, 0, bBuffer.Length)
fsPrint.Close()[/COLOR]
[COLOR=#000000]hParallelPort.Close()[/COLOR]
[/SIZE][/FONT] 
[FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]


 
If there are drivers installed for this printer (or any other printer that might have been setup on LPT1 on this machine), Windows Vista/7/8 won't let you address the port directly. You must first uninstall any and all driver that might take possession of LPT1. In Windows XP this is not a problem.
 
If there are drivers installed for this printer (or any other printer that might have been setup on LPT1 on this machine), Windows Vista/7/8 won't let you address the port directly. You must first uninstall any and all driver that might take possession of LPT1. In Windows XP this is not a problem.

I am using Win7 and I just tried to remove all Printers in the control panel. The Application still locks up at the write command. Anything else I could try ?
 
Did you remove the port driver? You cannot access managed hardware resources directly from user mode.

In any case it would probably help to have the printer model number... I am ready to bet there is a driver you can use somewhere without having to push raw data to it.

On the other hand, I have had good luck with InpOut32 a couple of years ago... www.highrez.co.uk/Downloads/InpOut32/
 
Last edited:
Did you remove the port driver? You cannot access managed hardware resources directly from user mode.

In any case it would probably help to have the printer model number... I am ready to bet there is a driver you can use somewhere without having to push raw data to it.

On the other hand, I have had good luck with InpOut32 a couple of years ago... www.highrez.co.uk/Downloads/InpOut32/

Well if I remove the port driver there is an exception at: Dim fsPrint As New FileStream(hParallelPort, FileAccess.Write, bBuffer.Length, False)


I removed all installed printers so far. I know that using the raw data isn't the best but it's in use here this way for many years now and It would be a big mess to convert all the production lines.

Any help is appreciated as I am completely lost right now.
 
I have just checked an older VB6 application which is running fine on Win7 and it uses
Dim fsPrint As New FileStream(hParallelPort, FileAccess.Write, bBuffer.Length, False)

to print raw data to the Parallel port. I don't know anything about VB6 but know I am wondering if this is more of a .net issue then a Win7 issue. Do you know ?
 
Back
Top