Inconsistent printing with CUPS on Raspberry Pi - bash

I am printing an image with a thermal printer off of a raspberry pi. This works fine most of the time but I have an issue where the job never completes.
The command is just a simple: lp <filename> and I have the thermal printer as my default. This works but occasionally, it won't print in that terminal. Then just opening a new terminal and sending the same exact command works. I've had to just have a handful of terminals open and jump between them until one of them prints it.
Does anyone have any insight to why this would be happening and what a possible solution might be?
I am running this from:
Raspbian Stretch
CUPS v2.2.1
Zebra ZD410
Here is the end of the output of an unsuccessful job (Job 118) and successful job (Job 119) from /var/logs/cups/error_log

I ran into a very similar issue to the one you are describing with Zebra ZD410 printers and cups printing from RaspberryPi.
By default, between each print job cups will reattach the usb printer. The ZD410 printer does not like when cups does that and the next print job will appear to go to the printer, but it won't print and there will be nothing in the logs that show any errors. This happens intermittently but frequently enough to make the printer unusable.
I was able to fix this problem by deleting the ZD410 printer from cups and adding it back using lpadmin and putting this configuration flag at the end of the lpadmin -p command:
-o usb-no-reattach-default=true
Try my suggestion and please let me know if it resolves your issue. Hopefully, this will help others with this problem as well.

You do not even name the exact Linux distro you are running, and which version of CUPS this involves.
No idea what your problem is...
But here is an idea how to start narrowing it down:
Enable LogLevel debug in /etc/cups/cupsd.conf and re-start the CUPS daemon.
Now you can follow whatever CUPS does with your print jobs:
less /var/log/cups/error_log
This may give you a hint. Note, that all lines in the log starting with E denote an message with log level 'error'. (I denotes log level 'info', W is 'warning' and N is 'notice'.)
There's one more thing you could do:
Determine, if it happens that exactly the same job file prints sometimes or doesn't print at other times. If so, it seems a "random" failure of the print device, or the transfer path from CUPS to the printer where some bit flip introduces an error. If not (the same file never prints), then this gives you another hint to narrow down the real problem.

Related

Yes/No Dialog on every page the printer will print

I'm doing this in a printer server. I am trying to make a program that will show up a Yes/No dialog box before proceeding to print a page printed by any application or from the network.
So far, it was easy to pause and resume a job. But haven't found a solution to pause and resume a page to be printed.
For reference, here's more about controlling the printer on Windows
https://msdn.microsoft.com/en-us/library/windows/desktop/ff686805(v=vs.85).aspx
I am using Windows 10 64bit. Any language will do.
Thanks.
I'm prepared to be proven wrong, but I don't believe this is trivially possible. The print spooler doesn't have a notion of where pages begin and end in a spooled print session.
The location of each page is language dependent, and the print spooler can hardly be expected to parse the stream to find the start and end of each page, it would be very slow for one thing.
The alternative would be for the print processor to note the beginning and end of each page and the offset of the spool file at that moment, and then pass that information separately to the spooler.
But there are problems with that too. the 'RAW print' capability allows the printing application to inject 'stuff' straight into the print stream, bypassing the print processor altogether. This is common with page layout applications when printing to a PostScript printer for example, particularly on Windows as supporting CMYK isn't really possible when printing on Windows, and spot colours are even harder.
The injected code can contain any number of pages and the print spooler has no way to know where each page is.
So in the general case, I don't think this is possible, at least not in the print spooler.

Zebra-printer LP 2824 not printing

I have Zebra LP2824 printer. It is working properly on Windows XP, but It is not working properly on Windows 7. On windows 7 it prints the Test page on printer properties, but it is not printing in my application. It seems, that it can't find the port, the printer is using. On the same application, but on Windows XP it is printing. I am connecting the printer with USB.
Does anyone knows what seems to be the problem?
Thanks for help in advance. :)
I usually have to share the printer in order to get it to accept a print job. Sharing in Win 7 is a little different I think - there might more than one step. Open the printer queue and pause it, then send a print job to it - see if it shows up (then un-pause) If it doesn't show up in the queue, there might be a share/permissions problem.
I just managed it today to print on another zebra USB printer.
use this article : http://support.microsoft.com/kb/322091/nl
Notice dough that the sample has a small error, so go to this function
public static bool SendFileToPrinter( string szPrinterName, string szFileName )
...
..
overthere go to then end of that function and add the line i mention below
Marshal.FreeCoTaskMem(pBytes);
fs.close(); // <-- add that or it will crash with locked files errors.
return true;
How Zebra printers behave depends a lot on what you try to print, and how the program works
For example notepad and edlin and wordpad and dos PRINT can all work different.
Some programs print RAW directly (as the url code does), others pay some respect to the printer preferences > still dough a TXT file raw printed containing ZPL commands will overrule printer settings..
ZPL is a little nightmare in itself
If you need paper to be cut
You will need
^MMC
you wont find it explained like that in their manuals.
(because they sell their own label printing design software i think..)

Emacs: some programs only work in ansi-term, some programs only work in shell

Relative Emacs newbie here, just trying to adapt my programming workflow to fit with emacs. So far I've discovered shell-pop and I'm quite enjoying on-demand terminals that pop up when needed for banging out the odd commands.
What I understand so far about Emacs is that shell is a "dumb" terminal that doesn't support any ansi control codes, and that makes it incompatible with things like ncurses that attempt to draw complex UI's on a terminal emulator. This is why you can't use less or top or similar in shell-mode.
However, I seem to be having trouble with ansi-term, it's not the be-all, end-all that it's cracked up to be. Sure, it has no problems running less or git log or even nano, but there are a few things that can't quite seem to display properly when they're running in an ansi-term, such as apt-get and nosetests. I'm not sure quite what the name is for it, but apt-get's output is characterised by live-updating what is displayed on the very last line, and then having unchanging lines of text scroll out above that line. It seems to be halfway between something like less and something dumber, like cat. Somehow ansi-term doesn't like this at all, and I get very garbled output, where it seems to output everything on one line only or just generally lose it's place and output things all over, randomly. In the case of nosetests, it starts off ok, but if any libraries spew out any STDERR, the output all goes to hell in a similar way.
With some fiddling it seems possible to fix this by mashing C-l and RET, but it's not always reliable.
Does anybody know what's going on here? Is there some way to fix ansi-term so that it can display everything properly? Or is there perhaps some other mode that I don't know about that is way better? Ideally I'd like something that "just works" as effortlessly as, eg, Gnome Terminal, which can run all of the above mentioned programs without a single hiccup.
Thanks!
I resolved this issue by commenting out my entire .emacs.el and then uncommenting and restarting emacs for every single line in the file. I discovered that the following line alone was responsible for the issue:
'(fringe-mode 0 nil (fringe))
(this line disables the fringes from inside custom-set-variables).
I guess this is a bug in Emacs, that disabling the fringe causes term-mode to garble it's output really badly whenever any output line exceeds $COLUMN columns.
Anyway, I don't really like the fringes much at all, and it seems I was able to at least disable the left fringe without triggering this issue:
(set-fringe-mode (cons 0 8))
Maybe apt-get does different things based on the $TERM environment variable. What happens if you set TERM=dumb? If that makes things work, then you can experiment with different values until you find one that supports enough features but still works.
Note that git 2.0.1 (June 25th, 2014) now better detects dumb terminal when displaying verbose messages.
That might help Emacs better display some of the messages received from git, but the fringe-mode bug reported above is certainly the main cause.
See commit 38de156 by Michael Naumov (mnaoumov)
sideband.c: do not use ANSI control sequence on non-terminal
Diagnostic messages received on the sideband #2 from the server side are sent to the standard error with ANSI terminal control sequence "\033[K" that erases to the end of line appended at the end of each line.
However, some programs (e.g. GitExtensions for Windows) read and interpret and/or show the message without understanding the terminal control sequences, resulting them to be shown to their end users.
To help these programs, squelch the control sequence when the standard error stream is not being sent to a tty.

Run a script on files sent to a CUPS print queue?

I am trying to configure a Mac OS X print queue so that a script can do some processing on each file printed before forwarding it on to another CUPS printer (on the same host).
I have been reading up on CUPS and have found an article describing how to use lpadmin to configure a queue with a "System V style interface script", but the caveat is that such a queue is seen as a "Generic Printer". I presume that means the user looses all ability to choose paper trays, etc. when submitting a job from the Print dialog. Is that correct?
[That makes this approach undesirable for my purposes, because the final destination is a POS receipt printer with non-standard paper sizes and print job options for cutting the paper roll, opening the cash drawer, etc.]
Is there a better way to accomplish my goal, which is simply to run a script on each receipt printed through a particular CUPS print queue?
I believe you need to configure a cups filter, which I believe can be created for just about any printer. It basically works as an input/output filter - where you modify the job in flight.
anyway, here is a link I found that explains an approach to do so (although it is for a slightly different use case). hope it helps.
Programming a Filter/Backend to 'Print to PDF' with CUPS from any Mac OS X application
be well.

how would i write a kernel module that runs program b whenever program a is called

I'm pretty new to linux, and I have a few questions about kernel module programming. I'm using ubuntu and C to make my .ko files. I'm trying to make a module that will execute program /b instead of /a whenever program /a is called. any tips?
also, even with printk (KERN_EMERG...), it won't print to the terminal. is there a setting i'm missing, or does ubuntu not do that?
Thanks a lot!
You may need to fiddle with the settings in /proc/sys/kernel/printk, which controls which levels are printed to the console. From proc(5):
/proc/sys/kernel/printk
The four values in this file are console_loglevel,
default_message_loglevel, minimum_console_level, and
default_console_loglevel. These values influence
printk() behavior when printing or logging error
messages. See syslog(2) for more info on the
different loglevels. Messages with a higher priority
than console_loglevel will be printed to the console.
Messages without an explicit priority will be printed
with priority default_message_level.
minimum_console_loglevel is the minimum (highest)
value to which console_loglevel can be set.
default_console_loglevel is the default value for
console_loglevel.
Note that, like nice(2) values, the lower values have higher priorities.
The easiest way to make an execve() for path /foo/a to execute /foo/b is to bind-mount /foo/b on top of /foo/a:
mount -obind /foo/b /foo/a
No kernel module is required.
Doing this same task with a kernel module would be significantly more work; the LSM interface may provide you with some assistance in figuring out when exactly your target is being executed. If you're looking for a starting point, do_execve() in fs/exec.c is where to start reading. Be sure to have ctags installed, run, and know how to use your editor's ctags integration, to make reading the code significantly easier.
Answer about printk:
It prints to the console, not the terminal. But what's the console?
You can find its TTY in /proc/cmdline. Normally it's tty0, which means the screen connected to the computer.
If you connect via SSH/TELNET, surely you won't see this.
If you're working in a graphical environment (Gnome/KDE), you may need something like alt-F1/F2 to switch to a text mode TTY.
You can also use the dmesg command to see the messages.

Resources