0

Firstly, I would like to know how to tell on which port my serial POS printer is connected? When I do dmesg | grep tty I get:

[    0.000000] console [tty0] enabled
[    1.255791] 00:04: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A

I guess, it is connected to /dev/ttyS0? After that I did chmod 777 /dev/ttyS0

crwxrwxrwx 1 root dialout 4, 64 May 25 09:49 /dev/ttyS0

Then I tried to write like this echo -ne '\033[2J' > /dev/ttyS0 from here

I know the hardware is fine because it works when connected to parallel port. What did I missed?

Hrvoje T
  • 1,031
  • if it works when connected to your parallel port, why switch it to serial? BTW, assuming /dev/ttyS0 is the correct device, you probably forgot to set the baud rate, start and stop bits, and parity settings. You can do that with stty...but first you need to know what the printer expects those settings to be (i.e. consult its manual). – cas May 25 '16 at 08:36
  • Parallel port is already taken by another printer which has only parallel port. This POS printer for receipts has both. – Hrvoje T May 25 '16 at 08:38
  • 1
    also, you can use statserial /dev/ttyS0 to see the hw line signals on that serial port. you can use that to find out which is the correct port. it's been a long time since i did much with serial ports, but IIRC you probably should have CTS=0 and DSR=1 if there's an active device on the port. – cas May 25 '16 at 08:39
  • Good point. statserial works on port ttyS0 and not on ttyS1, so it is ttyS0. Now I know the port. – Hrvoje T May 25 '16 at 08:44
  • so now all you need to do is find out what settings the printer expects. google the printer model if you don't have the manual handy. or find by trial and error - 9600,N,8,1 is a good starting guess (i.e. stty -F /dev/ttyS0 9600 cs8 -cstopb -parenb) – cas May 25 '16 at 08:47
  • How to input 9600,N,8,1? – Hrvoje T May 25 '16 at 08:50
  • FYI: http://unix.stackexchange.com/questions/242778/what-is-the-easiest-way-to-configure-serial-port-on-linux also click on the /serial-port tag in your question to see other questions with the same tag. – cas May 25 '16 at 08:53
  • Ok, I did that. Now stty -F /dev/ttyS0 -a says speed 9600 baud; rows 0; columns 0; line = 0; I think this is it. How to send data now? Is it with echo -ne 'some_text' > /dev/ttyS0. Still not working. I will try different speeds – Hrvoje T May 25 '16 at 08:58
  • 2
    also, check that you use correct cable. Normally, the DTE, Data Terminal Equipment (your printer) must have female D-SUB, while DCE, Data Control Equipment (your PC) must have male D-SUB. Anyway, check with specs on PC and printer that they have correct pin-outs, check that the cable is wired correctly as well, and check that you have synchronized flow-control settings between DTE and DCE – Serge May 25 '16 at 11:31
  • @cas @Serge Ok, it works like expected cat test.txt > /dev/ttyS0. Can I read in other terminal what is sent to ttyS0? – Hrvoje T Oct 04 '16 at 08:40

0 Answers0