473,320 Members | 1,939 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

sending file to parallel port printer

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
0 1186

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chuck Rittersdorf | last post by:
Hi There I am having a problem using the win32 API from VB6. I am trying to send a command string to a printer(zebra TLP 2742) on LPT1 using the folowing API functions CreateFile and...
4
by: David | last post by:
I'm wondering if python is capable of fairly precise timing and also sending data out the parallel port. For example ; making a 7.5 KHz square wave come out of one of the data pins on the...
2
by: Carlos Pezzotta | last post by:
Hi guys, I have to develop an application to capture the "printed" data from another machine. I have a specialized hardware (not a computer) that has only a parallel port (Centronics-SPP)...
12
by: david.brown.0 | last post by:
I'm trying to make a Java program access a parallel port. Java's comm API does not provide me with the control I need. I need to be able to write to the data and control pins and read the status...
23
by: Marco | last post by:
Could anyone please tell me why the program has the following error? I copy the program from http://www.beyondlogic.org/parlcd/parlcd.htm ...
4
by: Hector M Banda | last post by:
Hi all, How can I send chr(7) thru VB2005 using the parallel port? BTW This is for a POS system. Thanks, -hb
2
by: hari | last post by:
Hi all, I need to automate printer command testing, prinetr supports parallel/ serial/USB.How can i send the commands from python to printer. I have got pyparallel, as am new to python, no...
0
by: Charles Crawford | last post by:
Hi, This apparently is a common problem and I've yet to read a solution that actually works for my specific situation. I have a Zebra RW220 printer that I connect to via Bluetooth connection...
0
by: =?Utf-8?B?Q2hhcmxpZQ==?= | last post by:
Hi, This apparently is a common problem and I've yet to read a solution that actually works for my specific situation. I have a Zebra RW220 printer that I connect to via Bluetooth connection...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.