Page 1 sur 1

[Résolu] Comment savoir si l'imprimante est allumée

Publié : mer. 27/juin/2018 17:26
par Micoute
Bonjour à tous,

pour un projet, j'aimerais savoir s'il existe une méthode pour savoir si l'imprimante est en ligne.

Je vous remercie de l'aide que vous allez m'apporter.

Re: Comment savaoir si l'imprimante est allumée

Publié : jeu. 28/juin/2018 12:55
par Marc56
Quel modèle d'imprimante ?

À l'époque du DOS, une astuce simple consistait à envoyer CTRL+P vers imprimante

Code : Tout sélectionner

C:>^P > prn
Control + P étant la commande d'éjection de page, l'imprimante se contentait d'éjecter une page blanche. Pour les imprimantes en continu, elle avançait d'une page aussi

Maintenant avec les imprimantes, réseau, USB, WiFi, NFC etc c'est plus compliqué.

Avec une imprimante réseau IP, c'est facile, il suffit de lui faire un ping ou d'accéder par http à son interface de gestion.

Sinon, il faut lui causer par commandes SNMP si elle en dispose et que le dialogue est activé.

Enfin, en utilisant les api on doit pouvoir savoir si une imprimantes est présente, et si elle est en ou hors connexion.

:wink:

Re: Comment savaoir si l'imprimante est allumée

Publié : jeu. 28/juin/2018 13:25
par El Papounet
Si c'est sous Windows, en passant par l'API.
A voir si ça fonctionne:

Code : Tout sélectionner

Prototype.l pGetPrinter(hPrinter.l, Level.l, buffer.l, pbSizel, pbSizeNeeded.l)
Prototype.l pOpenPrinter(pPrinterName.s, phPrinter.l, *pDefault.PRINTER_DEFAULTS)
Prototype.l pClosePrinter(hPrinter.l)

Define.pGetPrinter GetPrinter
Define.pOpenPrinter OpenPrinter
Define.pClosePrinter ClosePrinter

Define.l dwBufsize = 0
Define.PRINTER_INFO_2 pinfo
Define.s printerName, msg

OpenLibrary(0, "winspool.drv")
GetPrinter = GetFunction(0, "GetPrinterW")
OpenPrinter = GetFunction(0, "OpenPrinterW")
ClosePrinter = GetFunction(0, "ClosePrinter")

printerName = "Microsoft Print to PDF"
;printerName = "HPOfficejet (HP Officejet Pro 8600)"

If OpenPrinter(printerName, @hPrinter, #Null)
    dwBufsize = 0
    GetPrinter(hPrinter, 2, #NUL, dwBufsize, @dwBufsize)
    *pinfo2.PRINTER_INFO_2 = AllocateMemory(dwBufsize)
    GetPrinter(hPrinter, 2, *pinfo2, dwBufsize, @dwBufsize)
    Debug "Status    : " + *pinfo2\Status
    Select *pinfo2\Status
        Case 0									: msg = "The printer is ready."; ???
        Case #PRINTER_STATUS_BUSY				: msg = "The printer is busy."
        Case #PRINTER_STATUS_DOOR_OPEN			: msg = "The printer door is open."
        Case #PRINTER_STATUS_ERROR				: msg = "Not used."
        Case #PRINTER_STATUS_INITIALIZING		: msg = "The printer is initializing."
        Case #PRINTER_STATUS_IO_ACTIVE			: msg = "The printer is in an active input/output state."
        Case #PRINTER_STATUS_MANUAL_FEED		: msg = "The printer is in a manual feed state."
        Case #PRINTER_STATUS_NO_TONER			: msg = "The printer is out of toner."
        Case #PRINTER_STATUS_NOT_AVAILABLE		: msg = "The printer is not available for printing."
        Case #PRINTER_STATUS_OFFLINE			: msg = " The printer is offline."
        Case #PRINTER_STATUS_OUT_OF_MEMORY		: msg = "The printer has run out of memory."
        Case #PRINTER_STATUS_OUTPUT_BIN_FULL	: msg = "The printer's output bin is full."
        Case #PRINTER_STATUS_PAGE_PUNT			: msg = "The printer cannot print the current page."
        Case #PRINTER_STATUS_PAPER_JAM			: msg = "Paper is jammed in the printer."
        Case #PRINTER_STATUS_PAPER_OUT			: msg = "The printer is out of paper."
        Case #PRINTER_STATUS_PAPER_PROBLEM		: msg = "The printer has a paper problem."
        Case #PRINTER_STATUS_PAUSED				: msg = "The printer is paused."
        Case #PRINTER_STATUS_PENDING_DELETION	: msg = "The printer is pending deletion as a result of a call to the DeletePrinter function."
        Case #PRINTER_STATUS_POWER_SAVE			: msg = "The printer is in power save mode."
        Case #PRINTER_STATUS_PRINTING			: msg = "The printer is printing."
        Case #PRINTER_STATUS_PROCESSING			: msg = "The printer is processing a command from the SetPrinter function."
        Case #PRINTER_STATUS_SERVER_UNKNOWN		: msg = "The printer status is unknown."
        Case #PRINTER_STATUS_TONER_LOW			: msg = "The printer is low on toner."
        Case #PRINTER_STATUS_USER_INTERVENTION	: msg = "The printer has an error that requires the user to do something."
        Case #PRINTER_STATUS_WAITING			: msg = "The printer is waiting."
        Case #PRINTER_STATUS_WARMING_UP			: msg = "The printer is warming up."
            
    EndSelect
    MessageRequester("", msg, #MB_ICONINFORMATION)
    FreeMemory(*pinfo2)
    ClosePrinter(hPrinter)
    
EndIf

CloseLibrary(0)	

Re: Comment savaoir si l'imprimante est allumée

Publié : jeu. 28/juin/2018 14:07
par Ar-S
Ne serait-ce pas plus simple d'appeler PrintRequester() ?
Ainsi non seulement tu choisis ton imprimante mais tu sais aussi si elle est en ligne.

[Résolu] Comment savoir si l'imprimante est allumée

Publié : jeu. 28/juin/2018 14:18
par Micoute
Merci à vous tous pour l'entraide qui m'a beaucoup aidé.

Re: [Résolu] Comment savoir si l'imprimante est allumée

Publié : jeu. 28/juin/2018 16:21
par falsam
Trés bien ce code El Papounet. Merci :)