Python Forum
Control a dot matrix printer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Control a dot matrix printer
#1
Hello,
I've recently got two of these amazing dot matrix printers. They support text data and ASCII commands control them.
So, I'd like to make a GUI to control it using... eh... Python of course Big Grin !
The point is that I know how to send text data to the printer, using :
variableOfYourChoice = open("LPT1", "w")
variableOfYourChoice.write("Your text")
variableOfYourChoice.close
but now I'd like to send ASCII or decimal commands to them so I can change the print quality, text size, font, text format, control paper, etc... For you to understand what I'm explaining, here is the list of the compatible commands (I have the ML320E and ML390E printers), they are in the tables starting at page 12 : OKI Microline printers compatible commands list
How am I supposed to do that ?

Thank you in advance for your replies,
Clément.
Reply
#2
use chr(): https://docs.python.org/2/library/functions.html#chr
and ord(): https://docs.python.org/2/library/functions.html#ord
or encoded string (this one in hex for 'ABC') "\x41\x42\x43"
Reply
#3
I'm a bit confused,
I want for example to send 27 120 0 to set it in Utility mode.
When I do :
printer = open("LPT1", "w")
printer.write("\x27\x120\x0")
printer.close
It says I can't use more that two numbers:
Error:
File "C:\Documents and Settings\Administrateur\Bureau\test.py", line 2 printer.write("\x27\x120\x0") ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 9-11: truncated \xXX escape
And when I do :
printer = open("LPT1", "w")
printer.write(chr(27), chr(120), chr(0))
printer.close
It obviously tells me that printer.write takes only one argument and that I gave 3 of them.
Reply
#4
Quote:I want for example to send 27 120 0 to set it in Utility mode.
I assume 27, 120, and 0 are decimal, if so:
printer.write("\x27\x120\x0")
is wrong because the x indicates hex.
you need:
printer.write("\x1b\x78\x00")
witch is the hex equivalent.

download an ASCII conversion chart from google images
Reply
#5
THANK YOU !
It works !!
I'm so happy, thank you !
I'll finally be able to do what I wanted to do !
Thank you ! Clap
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Check if two matrix are equal and of not add the matrix to the list quest 3 820 Jul-10-2023, 02:41 AM
Last Post: deanhystad
  Trying to send file to printer with no results. chob_thomas 2 3,362 Dec-21-2022, 07:12 AM
Last Post: Pedroski55
  How do you marshal the default printer setup to print? hammer 0 1,277 May-29-2022, 02:54 PM
Last Post: hammer
  Can you print a string variable to printer hammer 2 1,937 Apr-30-2022, 11:48 PM
Last Post: hammer
  How to multiply a matrix with herself, until the zero matrix results peanutbutterandjelly 3 3,352 May-03-2021, 06:30 AM
Last Post: Gribouillis
  Printing to a printer connected to pi 4 alan 2 2,434 Oct-04-2020, 10:08 PM
Last Post: alan
  python-printer-escpos 0.0.3 ERROR neethuvp 1 3,684 Nov-12-2019, 12:20 PM
Last Post: Larz60+
  Is this possible in Python? Auto-Send-to-printer on script run? pcsailor 8 16,860 Jul-19-2019, 09:33 AM
Last Post: perfringo
  print a persian file by thermal printer and python-escpos mnodule gray 12 12,575 Nov-03-2017, 11:15 PM
Last Post: Larz60+
  printing a text file by python and thermal printer gray 6 20,584 Jul-30-2017, 05:56 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020