473,395 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

sending commands to parallel printer through python

Hi all,
I need to automate printer command testing, prinetr supports
parallel/
serial/USB.How can i send the commands from python to printer.

I have got pyparallel, as am new to python, no idea how to work on
it.
Please give some tips,The comamnd to be sent to the printer is hex
data "1B 40".please give a example,it will be grateful.
Thank you. postedthe same in it.comp.lang.python
Regards
-Hari
Dec 5 '07 #1
2 4382
hari wrote:
Hi all,
I need to automate printer command testing, prinetr supports
parallel/
serial/USB.How can i send the commands from python to printer.

I have got pyparallel, as am new to python, no idea how to work on
it.
Please give some tips,The comamnd to be sent to the printer is hex
data "1B 40".please give a example,it will be grateful.
Thank you. postedthe same in it.comp.lang.python
Regards
-Hari

If the printer is connected to the computer running the program you can open the
printer in binary mode and write to it directly. If it is a networked printer
you will need to write to the spooler.

printer=open("LPT1", "wb")
printer.write(int('01b', 16), int('40', 16)

printer.close()

-Larry
Dec 5 '07 #2
En Wed, 05 Dec 2007 10:19:51 -0300, hari <ha********@gmail.comescribi�:
Hi all,
I need to automate printer command testing, prinetr supports
parallel/
serial/USB.How can i send the commands from python to printer.

I have got pyparallel, as am new to python, no idea how to work on
it.
Please give some tips,The comamnd to be sent to the printer is hex
data "1B 40".please give a example,it will be grateful.
a) how to control the printer port:
You should look for some info on the protocol and timings. I vaguely
remember that you should write the desired data onto the eight data lines,
then set the STROBE control signal for some time, then reset the signal.
Something like this:

import parallel

port = parallel.Parallel()

def send_to_printer(bytes):
for byte in bytes:
port.setData(ord(byte))
port.setDataStrobe(1)
sleep(...)
port.setDataStrobe(0)
sleep(...)

send_to_printer("Hello world\r\n")

You'll have to look for the right values to sleep in each case. Those 1/0
may be reversed too.

b) how to convert hex data:

The easiest way would be: send_to_printer("\x1B\x40")

If you have the string "1B 40" already built:

def hex_to_raw(hex):
return ''.join([chr(int(num,16)) for num in hex.split()])

data = "1B 40"
send_to_printer(hex_to_raw(data))

--
Gabriel Genellina

Dec 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chuck Rittersdorf | last post by:
Hi There I am having a problem using the win32 API from VB6. I am trying to send a command string to a printer(zebra TLP 2742) on LPT1 using the folowing API functions CreateFile and...
4
by: David | last post by:
I'm wondering if python is capable of fairly precise timing and also sending data out the parallel port. For example ; making a 7.5 KHz square wave come out of one of the data pins on the...
3
by: Vlki | last post by:
Hello, I can't find a way to send printer specific language codes to printer. Part of my code : String sString = "B50,0,0,3,1,2,50,B," + "12345678901234567890"; Font fFont = new Font("Arial",...
2
by: Carlos Pezzotta | last post by:
Hi guys, I have to develop an application to capture the "printed" data from another machine. I have a specialized hardware (not a computer) that has only a parallel port (Centronics-SPP)...
2
by: notregister | last post by:
Hi i have a printer that is connected to my PC using a t100base lan cable instead of the usual usb or parallel port cable. how do i send a printjob directly to the printer using VB.Net??
0
by: notregister | last post by:
Hi, i have trying to send a PCL file to a printer using the following codes, but the printer would normally hang for a long time after i have send the command, and i do not know what wrong with it,...
12
by: david.brown.0 | last post by:
I'm trying to make a Java program access a parallel port. Java's comm API does not provide me with the control I need. I need to be able to write to the data and control pins and read the status...
4
by: Hector M Banda | last post by:
Hi all, How can I send chr(7) thru VB2005 using the parallel port? BTW This is for a POS system. Thanks, -hb
1
by: deric | last post by:
Hi! I'm new to VB.net programming on printing a page to a thermal printer (Epson T88IV). I really had a hard time figuring out how to code the printing of a bitmap image and some text, while sending...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.