would anyone know how to tell through vb whether LPT1 is connected to
a printer. I am really after some code that would check the port's
connection rather than use the printers object -- the printers object
can include a shared printer that is not connected to LPT1 and that is
why it's not a good indicationo whether LPT1 is in use.
Any assistance willbe appreciated
Thank you in adavance
Avi
Just a guess, but perhaps just attempting to open the LPT1 port via normal
VB I/O statements (namely, the Open statement) would work. You might have
to send a printer code or something and possibly (probably) trap for an
error. There might be an API way to detect whether a printer is actually
connected to a specific port (I'd imagine the printer would have to be
online; otherwise, it probably wouldn't be considered connected), but I
don't know what it is.
You might try searching www.google.com. I'd be willing to bet this question
has been asked a number of times. I just don't happen to remember it being
asked, or else I'd point you to a definitive answer.
Mike
Then, make these modifications:
ADD:
'new printer level UDT and const:
Public Const PRINTER_LEVEL5 = &H5
Public Type PRINTER_INFO_5
pPrinterName As Long
pPortName As Long
Attributes As Long
DeviceNotSelectedTimeout As Long
TransmissionRetryTimeout As Long
End Type
CHANGE:
- Dim ptr() as PRINTER_INFO_4 to PRINTER_INFO_5
- Two occurances of const PRINTER_LEVEL4 to PRINTER_LEVEL5 in the API calls
- One occurance of GetStrFromPtrA(.pServerName) to
GetStrFromPtrA(.pPortName)
Your output will now look like:
PDFCreator PDFCreator: local
HP LaserJet 5Si MX LPT1: local
CutePDF Printer CUTEPT1: local
Canon i950 USB001 bidirectional local offline
--
Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Avi" <avis...@optonline.net> wrote in message
news:ab052923.04032...@posting.google.com...
: hi,
Now I think I should provide more informatuion about the context of
the need to be able to determine what printers are connected to what
port and whether ther are switched off : I'm very near to the end of a
VB application that is actually a point of sale application. One
printer, the receipt printer, is assumed to be connected to LPT1;
another printer can be connected to the USB or it can be connected to
another computer and uused as shared computer by all computers in the
WORKGROUP setup. One thing that happnes is that whenever a receipt is
printed, a cash drawer, that is connected through a line (similar to
telephone line) to the receipt printer, is opened. There are some
cases when the printer is off (e.g, application user did not make sure
the printer is connected) In such cases the application will freeze,
since the code responsible for opening the cash drawer -- and I'm
not sure about my terminology -- by printing 'something' to the
receipt printer, which, in turn recognizes that 'something' as a sign
to cause the cash drawer to open, is assuming the cash drawer is
there. Whereas I can use error handling technics (i.e., on error
goto...) to handle the case of printing a receipt with a printer that
is switched off or is unplugged, I can not apply this error handling
technique with respect to the drawer. I NEED to know if it's there
before I try to open it. Since the drawer is connected to the receipt
printer, the only way I can tell, as far as know, wheteher it's
connected is to check the connection with the printer. Idealy, I
would be able to determine if the drawer is connected, but that, I
believe is hard becuase there is no direct connection between the
drawer and the register. Here is the code to open the drawer that is
connected to a printer on LPT1:
Open "LPT1" For Output As #1
Print #1, Chr(27) & Chr(112) & Chr(0) & Chr(25) & Chr(250)
Close #1
This snippet of code bring about 'application freezing' if the drawer
is not connected.
if you are still with me, then I hope something comes into your mind
with respect to the report and th problem in general, and i would
definitely like to hear what you have to say, Mike and Randy.
once again thanks you all for the time and effort. I really
appreciate that.
regards
Avi