08-07-2015 12:20 PM
Hello All,
I am doing some research. We wrote a program using CVI to print to an Epson Printer.
In the real world, the printer may run out of ink, jammed, or may be turned off, etc, that otherwise prevents it from printing.
What we are seeing is that we can successfully issue a print command, but the printer cannot execute it.
As a result our print queue just keeps building. Once the printer is "fixed" we end up getting a large backlog of print tickets being processed.
We would rather not print at all.
What I would like to do is determine if there is a way to programatically determine if a printer can even print.
I have contacted the developer of the printer, but I wonder if there is also something in Windows we can refer to.
These kinds of features would be useful for any brand of printer going forward.
Is there a known function to get a printer status, queue size, and ink status, through windows or CVI?
Thank you for any advice.
08-09-2015 11:36 PM
You might start at How to get the status of a printer and a print job
08-10-2015 03:20 PM
I am looking at this and it looks like it might work well.
The IsPrinterError looks too good to be true 🙂
But, to test it I wrote a small program. It compiles with no errors, but when I try to run the program it gives me a linking issue saying
error: Undefined symbol '_ClosePrinter@4' referenced in "c:\..\Print.obj".
error: Undefined symbol '_OpenPrinterA@12' referenced in "c:\..\Print.obj".
I wrote this callback in my program.
int CVICALLBACK CheckJobs (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
HANDLE hPrinter = 0;
switch (event)
{
case EVENT_COMMIT:
//Get the Printer Handle
OpenPrinter("printer name", hPrinter, 0);
//Determine if Jobs are in the queue
//GetJobs(HANDLE hPrinter, JOB_INFO_2 **ppJobInfo, int *pcJobs, DWORD *pStatus);
//Close the printer
ClosePrinter(hPrinter);
break;
}
return 0;
}
My includes are:
#include <windows.h>
#include <Winspool.h>
#include <cvidef.h>
#include <cvirte.h>
#include <userint.h>
#include "toolbox.h"
#include <ansi_c.h>
#include <utility.h>
#include <mmsystem.h>
#include <formatio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
Is the Winspool only available in Full Development? All I have is Base.
08-10-2015 03:39 PM
Hello,
You should be to use the SDK Winspool.h functions in FDS and Base.
Your program is not able to build because it cannot find the Winspool.lib import library. In order to link against those functions, you have to add the Winspool.lib import library to your Project Tree. Just drag and drop the import library in your Project Tree and the project should be able to compile successfully. The library is located in <CVI Install Directory>\sdk\lib\msvc or <CVI Install Directory>\sdk\lib\msvc64.
By default LabWindows/CVI only links against to most used Windows SDK libraries (kernel32.lib, user32.lib, uuid.lib, winmm.lib, advapi32.lib, and gdi32.lib) in order to keep the size of your CVI application binaries smaller, so you have to add the other ones manually.
Regards!
- Johannes
08-10-2015 03:47 PM
Thanks for the reply.
When I add the Winspool.lib to my project tree I get this message:
'WinSpool.Lib' is available only in the Full Development System.
I suppose I have to upgrade?
08-10-2015 04:11 PM
Hello Veni,
I am very sorry for the incorrect assumption I made. Winspool functions are only available in Full Development System and not in Base.
You can read more about SDK functions that are supported in Base or FDS in this help topic: http://zone.ni.com/reference/en-XX/help/370051Y-01/cvi/programmerref/availability_win32_functions/
With regards,
- Johannes
08-10-2015 04:13 PM
That's alright.
I'll see what I can do about it. Maybe I can get a trial and test it and see if will even work and go from there.