Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reading/Writing PJL command to a USB/parallel printer via VB

744 views
Skip to first unread message

akaTwoSheds

unread,
Oct 2, 2006, 2:57:09 PM10/2/06
to
Greetings all, sorry if I over do with the cross posts...

I've prowled around in all the places I can think of trying to find a
way to send and receive (that's the tricky part) PJL commands and
responses to printers connected direcly to a computer via USB or
parallel port.

I had no trouble dealing with network printers - simply use WINSOCK to
open a telnet connection and send the string, then wait for a response:

Private Sub Command1_Click()
Winsock1.Protocol = sckTCPProtocol
Winsock1.RemotePort = 9100
Winsock1.RemoteHost = Text1.Text
Winsock1.Connect
Pause (100)
While Winsock1.State <> 7
DoEvents
Wend
Winsock1.SendData "@PJL INFO PAGECOUNT" & vbCrLf
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Text2.Text = Winsock1.GetData results
End Sub

I just haven't a clue how to do this with non-network printers. I
think that I've found some promising things using the WritePrinter API,
but the corresponding ReadPrinter API seems to be something of a
mystery (or a well kept secret). Without the ReadPrinter I can't even
tell if I'm using WritePrinter correctly.

If anyone has any ideas, suggestions, or even fully debuged and ready
to compile source code <g> I'd really appreciate it.

Thanks...

MikeD

unread,
Oct 2, 2006, 3:02:03 PM10/2/06
to

"akaTwoSheds" <akaTw...@gmail.com> wrote in message
news:1159815429....@c28g2000cwb.googlegroups.com...

> Greetings all, sorry if I over do with the cross posts...


Being that there's only one newsgroup listed, you didn't crosspost. What
you did was multipost and this is frowned upon very much.

--
Mike
Microsoft MVP Visual Basic


Thorsten Albers

unread,
Oct 2, 2006, 6:10:21 PM10/2/06
to
akaTwoSheds <akaTw...@gmail.com> schrieb im Beitrag
<1159815429....@c28g2000cwb.googlegroups.com>...

> I just haven't a clue how to do this with non-network printers. I
> think that I've found some promising things using the WritePrinter API,
> but the corresponding ReadPrinter API seems to be something of a
> mystery (or a well kept secret). Without the ReadPrinter I can't even
> tell if I'm using WritePrinter correctly.

What is the mystery? The API function is documented in the MSDN.
Note that the printer/port has to be installed for bidirectional support.
The bidirectional support has to be enabled both in the printer driver
properties and in the machine's BIOS setup.

--
----------------------------------------------------------------------
THORSTEN ALBERS Universität Freiburg
albers@
uni-freiburg.de
----------------------------------------------------------------------

akaTwoSheds

unread,
Oct 3, 2006, 3:45:24 PM10/3/06
to
Hi Thorsten,

The mystery is how can a so so programmer such as myself manage to do
it I guess <g>. In my poking around I found several examples of the
WritePrinter function which seem to work, but so far I've found no
examples of the ReadPrinter function that I can make function. I found
the MSDN page on it
(http://windowssdk.msdn.microsoft.com/en-us/library/ms535782.aspx) but
sadly it's kind of over my head. I was hoping that someone out there
might have some experience with it or have a link to somewhere that has
a sample I can play with.

Thanks for responding...

Thorsten Albers

unread,
Oct 3, 2006, 4:21:13 PM10/3/06
to
akaTwoSheds <akaTw...@gmail.com> schrieb im Beitrag
<1159904724.6...@e3g2000cwe.googlegroups.com>...

> The mystery is how can a so so programmer such as myself manage to do
> it I guess <g>. In my poking around I found several examples of the
> WritePrinter function which seem to work, but so far I've found no
> examples of the ReadPrinter function that I can make function. I found
> the MSDN page on it
> (http://windowssdk.msdn.microsoft.com/en-us/library/ms535782.aspx) but
> sadly it's kind of over my head. I was hoping that someone out there
> might have some experience with it or have a link to somewhere that has
> a sample I can play with.

'On the fly':

Private Declare Function ReadPrinter _
Lib "winspool" _
( _
ByVal hPrinter As Long, _
pBuffer As Any, _
ByVal lBufferSize As Long, _
lNoBytesRead As Long _
) As Long

Const DATASIZE_INITIAL As Long = 100

Dim abData() As Byte
Dim lSizeData As Long, lResult As Long

lSizeData = DATASIZE_INITIAL
ReDim abData(0 To (lSizeData - 1)) As Byte

Err.Clear
lResult = ReadPrinter(hPrinter, abData(), lSizeData, lSizeData)
If lResult = 0 Then
MsgBox "ReadPrinter() failed with error code " _
& Err.LastDLLError
Exit Sub
ElseIf lSizeData > DATASIZE_INITIAL Then
ReDim abData(0 To (lSizeData - 1)) As Byte
lResult = ReadPrinter(hPrinter, abData(), lSizeData, lSizeData)
If lResult = 0 Then
MsgBox "ReadPrinter() failed with error code " _
& Err.LastDLLError
Exit Sub
End If
ElseIf lSizeData < DATASIZE_INITIAL
If lSizeData = 0 Then
Erase abData
Else
ReDim Preserve abData(0 To (lSizeData - 1)) As Byte
End If
End If

MsgBox "Bytes read: " & lSizeData

0 new messages