Tue Oct 07, 2014 7:47 pm
When you say "USB to LPT" do you mean "USB to serial" or "USB to Centronics parallel"? (Shouldn't make a difference. Just curious as to what the actual interface is.)
You should be able to send data to the device as if it is a file (that being the way unix/Linux work). You may have to change the permissions on the device node for your program to do it. You will also have to open the :"file" that is the printer, and you should close it when you're done. Be sure to send both a linefeed *and* a carriage return at the end of each line.
If you don't need to see the program output "on the fly" (that is, each line as it is generated), you could write the data to a file and then issue an lp command to print it (assuming you have installed the printer through CUPS).
FYI...I have done direct printing on both serial and parallel printers attached to a unix system, and the "write a file and invoke lp" method using a network attached printer. Granted...I did it in C, not Python, but the OS doesn't care about that distinction.
For a "drop a file and print" to a laser printer, here is the code:
sprintf(cmd, "lp -oraw -d hp2055dn %s", ptr_file_name);
system(cmd);