Skip to content

Instantly share code, notes, and snippets.

@lusentis
Created October 15, 2012 11:20
Show Gist options
  • Save lusentis/3892003 to your computer and use it in GitHub Desktop.
Save lusentis/3892003 to your computer and use it in GitHub Desktop.
Epson TM-T88 serial python
# -~- coding: utf-8 -~-
## not working write
import serial
import sys
import StringIO
def fp81_write(s, payload):
ba = bytearray()
cks = 0
ba.append('\x02')
ba.append(b'2')
ba.append(b'0')
ba.append(b'E')
for by in bytearray(payload, encoding='utf-8'):
ba.append(by)
for by in ba:
if by != '\x03' and by != '\x02':
cks = cks+by
cks_digits = str(cks % 100)
if (cks % 100) < 10:
cks_digits = '0{0}'.format(cks)
ba.append(str(cks_digits[0]))
ba.append(str(cks_digits[1]))
ba.append('\x03')
print "Writing frame:"
print ba
bc = ba
ba = bytearray()
cks = 0
for c in bc:
print r"read {0}".format(c)
if c == b'\x03':
#for by in ba:
# print r"{0} ".format(chr(by))
cks = cks - (ba[-1]) - (ba[-2]) # remove checksum from checksum
print "Checksum: ours = {0}, printer's = {1}{2}".format(str(cks % 100), chr(ba[-2]), chr(ba[-1]))
return ba
elif c == b'\x02':
continue
else:
ba.append(c)
cks = cks+c
print "Writing:{0}".format(ba)
s.write(ba)
s.flush()
print "Written"
def fp81_read(s):
ba = bytearray()
cks = 0
while True:
c = s.read()
print r"read {0}".format(c)
if c == '\x03':
#for by in ba:
# print r"{0} ".format(chr(by))
cks = cks - (ba[-1]) - (ba[-2]) # remove checksum from checksum
print "Checksum: ours = {0}, printer's = {1}{2}".format(str(cks % 100), chr(ba[-2]), chr(ba[-1]))
return ba
elif c == '\x02':
continue
else:
ba.append(c)
cks = cks+ord(c)
s = serial.Serial(port="/dev/tty.usbserial", baudrate=19200)
fp81_write(s, b'4217')
print fp81_read(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment