[cups.development] How are the command filters supposed to return data?
Michael Sweet
msweet at apple.com
Fri Aug 20 08:39:39 PDT 2010
On Aug 20, 2010, at 8:33 AM, Reinhold Kainhofer wrote:
> Am Freitag, 20. August 2010, um 14:45:52 schrieben Sie:
>> On Wed, 2010-07-14 at 01:43 +0200, Reinhold Kainhofer wrote:
>>> To get the response of the printer, I have to call cupsBackChannelRead,
>>> right? Is the data written by the command filter sent to the printer
>>> immediately by the backend, or do I need to select some non-zero
>>> timeout?
>>
>> I would have thought it would be sent directly to the printer if
>> possible, although I don't see anything in the documentation requiring
>> this explicitly. (IMHO it ought to be required...)
>
> Actually, no. You have to do a cupsSideChannelDoRequest to send the data to
> the printer. After that, one can do a cupsBackChannelRead...
Actually, this isn't 100% true. Basically the side channel call makes sure that the backend has flushed your printer data to the device. The correct sequence of operations (and this is something I am working on documentation for... :) is:
call cupsSideChannelDoRequest with CUPS_SC_CMD_GET_BIDI
if backend supports bidirectional communications then
write printer commands to stdout
flush stdout as needed
call cupsSideChannelDoRequest with CUPS_SC_CMD_DRAIN_OUTPUT
call cupsBackChannelRead with an appropriate timeout
process the back channel data and send ATTR:, STATE:, or other messages to stderr
endif
> In particular, I have now finished the ReportLevels target for my magicolor
> 1690MF. The core commands are:
>
> pwrite("\033%-12345X at PJL INFO DSTATUS\015\012", 28);
> pwrite("\033%-12345X", 9);
> fflush(stdout);
>
> // RER: 07/20/10 - Sleep for a bit!
> sleep(5);
>
> // Ask the backend to send all data NOW:
> datalen = 0;
> cupsSideChannelDoRequest(CUPS_SC_CMD_DRAIN_OUTPUT, buffer, &datalen, 5.0);
>
> // Read back the data from the printer
> bytes = cupsBackChannelRead(buffer, sizeof(buffer) - 1, 5.0);
> buffer[bytes] = '\0';
>
> Now, bytes contains the response by the printer, which must then be propertly
> parsed by the filter...
> See the file command2foo2lava-pjl.c in the latest foo2zjs driver package...
>
>> Even so, you may still need a non-zero timeout -- the printer may be
>> busy and unable to respond at the time
>
> Yes, I decided to use 5.0, which is used by some other filters, too.
>
> Cheers,
> Reinhold
>
>
> --
> ------------------------------------------------------------------
> Reinhold Kainhofer, reinhold at kainhofer.com, http://reinhold.kainhofer.com/
> * Financial & Actuarial Math., Vienna Univ. of Technology, Austria
> * http://www.fam.tuwien.ac.at/, DVR: 0005886
> * LilyPond, Music typesetting, http://www.lilypond.org
>
> _______________________________________________
> cups-dev mailing list
> cups-dev at easysw.com
> http://lists.easysw.com/mailman/listinfo/cups-dev
________________________________________________________________________
Michael Sweet, Senior Printing System Engineer, PWG Chair
More information about the cups-devel
mailing list