By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,870 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,870 IT Pros & Developers. It's quick & easy.

sending file to parallel port printer

P: n/a
Hi, i have trying to send a PCL file to a printer using the following codes,
but the printer would normally hang for a long time after i have send the
command, and i do not know what wrong with it, this are ample code i found in
msdn, and yet it could not work, pls advise

Thanks

Public Function PrintChunkParallel(ByVal lPort As Long, ByVal Chunk As
String) As Long
'currently only for LPT1 only
Dim lBytestoWrite, lBytesWritten As Long
Dim x, y As Integer
Dim Success As Boolean
Dim hParallelPort As IntPtr
Dim Buffer() As Byte
Dim lStart As Long = 0
Dim MyDCB As DCB
Dim MyCommTimeouts As COMMTIMEOUTS

' Declare variables to use for encoding.
Dim oEncoder As New System.Text.ASCIIEncoding
Dim oEnc As System.Text.Encoding = oEncoder.GetEncoding(1252)

' Convert String to Byte().
Buffer = oEnc.GetBytes(Chunk)

hParallelPort = CreateFile("LPT1", GENERIC_READ Or GENERIC_WRITE, 0,
IntPtr.Zero, _
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero)

Success = GetCommState(hParallelPort, MyDCB)
' Modify the properties of MyDCB as appropriate.
' WARNING: Make sure to modify the properties in accordance with
their supported values.
MyDCB.BaudRate = 9600
MyDCB.ByteSize = 8
MyDCB.Parity = NOPARITY
MyDCB.StopBits = ONESTOPBIT
' Reconfigure LPT1 based on the properties of MyDCB.
Success = SetCommState(hParallelPort, MyDCB)

Success = GetCommTimeouts(hParallelPort, MyCommTimeouts)
' Modify the properties of MyCommTimeouts as appropriate.
' WARNING: Make sure to modify the properties in accordance with
their supported values.
MyCommTimeouts.ReadIntervalTimeout = 0
MyCommTimeouts.ReadTotalTimeoutConstant = 0
MyCommTimeouts.ReadTotalTimeoutMultiplier = 0
MyCommTimeouts.WriteTotalTimeoutConstant = 0
MyCommTimeouts.WriteTotalTimeoutMultiplier = 0
' Reconfigure the time-out settings, based on the properties of
MyCommTimeouts.
Success = SetCommTimeouts(hParallelPort, MyCommTimeouts)

lBytestoWrite = Len(Chunk)

Success = WriteFile(hParallelPort, Buffer, lBytestoWrite,
lBytesWritten, IntPtr.Zero)
'retest this portion of the codes

Application.DoEvents()
Success = CloseHandle(hParallelPort)
Do
Success = WriteFile(hParallelPort, Buffer, lBytestoWrite,
lBytesWritten, IntPtr.Zero)

If lBytesWritten <= 0 Then
If lStart = 0 Then
lStart = Timer
ElseIf Math.Abs(lStart - Timer) >= 3600 Or CancelFlag = True
Then
PrintChunkParallel = -1
Exit Function
End If
Else
lStart = 0
End If
lBytestoWrite = lBytestoWrite - lBytesWritten
Application.DoEvents()
Loop While lBytestoWrite > 0
PrintChunkParallel = lBytesWritten

End Function
Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.