alexandroputra
Posts: 2
Joined: Fri Feb 15, 2019 4:37 am

Receiving printer data from PC using serial-to-TTY

Fri Feb 15, 2019 6:25 am

hi folks,

im trying to capture what data is printed and save it to txt files, by connecting serial cable from Windows PC to raspi and print like normal. i am getting feedback from the PC when i read the serial data using python, but it unreadable and full of wierd character.

im trying to explore arround googles & forums and have try many differents encode / decode such as ASCII, UTF-8, even hex dump and still cannot read what the data is

here is my python code :

Code: Select all

import serial
    
ser = serial.Serial(
    port='/dev/ttyS0',
    baudrate=19200,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    xonxoff=0)

while True:
	x = ser.readline(8)
	print x
	
im trying to print "hello world" on notepad, and here is what i get on the python console :

Code: Select all

4P��b2{p�LWJv0�Jv0@Jv0Jv0'�����������8��8��8��8���8�`
           �s����8�`
                       ?�w������8`
                                     x�|xÀ����8a�pxx8������8c��8p8�����8s��8p�����82��8p����82��8p����86l�8p����84hppp����@84hx�p�������8?�p������?�����8�p��Jv0�Jv0@�3
here is the serial port setting on Windows PC :
Image

here is my serial-ttl pin configuration :
Image

if im switching the serial end into thermal printer, it working just fine.

i wonder if there anyone here can help me on this. thanks folks !

User avatar
topguy
Posts: 5613
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Receiving printer data from PC using serial-to-TTY

Fri Feb 15, 2019 2:32 pm

Which make/model is the printer ? What is the "driver" ?

Most of these printer has a "testprint" mode where you hold in the "feed" button while turning it on, does it print its baudrate then and confirm that its 19200 ?

Because it very much look like data you get when baudrate is wrong, I would just do a check with 9600 baud in the python program.

User avatar
OutoftheBOTS
Posts: 711
Joined: Tue Aug 01, 2017 10:06 am

Re: Receiving printer data from PC using serial-to-TTY

Fri Feb 15, 2019 9:16 pm

Normally when you get a heap of weird chars like that it means the configuration n is wrong (most common the baud rate).

Your post you show the setup on windows and the setup on RPi and they match but I suspect that maybe windows changes the baud rate when printing??? especially since your only sending "Hellow World" yet your recieveing a hell of a lot of chars at RPi end. This sort of tells me that the baud rate on the RPi is way to fast as it is reading lots of chars when only a few is being sent.

You can maybe experiment with different common used baud rates.

Andyroo
Posts: 3756
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Receiving printer data from PC using serial-to-TTY

Fri Feb 15, 2019 9:56 pm

Try using the generic / plain text printer driver.

It’s possible that what you are seeing is the printer initialisation commands.
Need Pi spray - these things are breeding in my house...

alexandroputra
Posts: 2
Joined: Fri Feb 15, 2019 4:37 am

Re: Receiving printer data from PC using serial-to-TTY

Mon Feb 18, 2019 7:17 pm

hello again folks, thank you for answering my question.

for printer, i use chinese xprinter Q200ii (http://www.xprinter.net/index.php/Produ ... 2/22/cid/1). when i press the "FEED" button continously, its ends up my paper is continously rolling as well, so i think thats not a proper way to "test print" this printer. maybe if you guys have some experience with this type of printer, share with me on how to do it pleas.. :roll:

actualy my current idea is this :
Image

so windows PC is printed "hello world", trough serial cable data into raspi -> raspi read the printer data with python (i just expecting some readable "hello world" in text / string format, or maybe even PDF) -> and somehow pass trough it to the printer. but for now, pass trough to the printer step is later to be done.

i have try different baudrate besides 19200 (because on windows PC 19200 is work well if i directly conect it to the printer), i guess from 4800 - 116000, but none of them make the "hello world" that im printing is readable.

you guys have any idea on this ? or even try something like this before
many thanks

Return to “Python”