473,239 Members | 1,586 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,239 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 4349
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: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.