sending commands to parallel printer through python

H

hari

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
 
L

Larry Bates

hari said:
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
 
G

Gabriel Genellina

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))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top