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...
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
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
----------------------------------------------------------------------
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...
'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