124 lines
3.4 KiB
Python
124 lines
3.4 KiB
Python
from time import sleep
|
|
|
|
from pyfis.aegmis import MIS1TextDisplay
|
|
from pyfis.utils import debug_hex
|
|
|
|
|
|
def receive(display):
|
|
if display.use_rts:
|
|
display.port.setRTS(1)
|
|
display.port.write([0x04, 0x81, 0x05])
|
|
if display.use_rts:
|
|
display.port.setRTS(0)
|
|
return display.read_response(True)
|
|
|
|
def decode(display):
|
|
r = receive(display)
|
|
if r[0] != 0x02:
|
|
print("Invalid byte {r[0]:02x}, expected EOT")
|
|
d = {
|
|
'code': r[1],
|
|
'subcode': r[2],
|
|
}
|
|
m = []
|
|
esc = False
|
|
for i in range(3, len(r)-1):
|
|
if esc:
|
|
m.append(r[i])
|
|
erc = False
|
|
elif r[i] == 0x10:
|
|
esc = True
|
|
else:
|
|
if r[i] == 0x03:
|
|
# compute checksum
|
|
next
|
|
m.append(r[i])
|
|
m = m[0:-1]
|
|
print(f"m({len(m)}): {debug_hex(m)}")
|
|
return m
|
|
|
|
|
|
def reset_and_get_config(display):
|
|
display.send_command(0x31, 0x00, [])
|
|
r = decode(display)
|
|
return {
|
|
'type': r[0],
|
|
'control-units': r[1],
|
|
'digits-a': r[2] * 256 + r[3],
|
|
'lines-a': r[4],
|
|
'digits-b': r[5] * 256 + r[6],
|
|
'lines-b': r[7],
|
|
'timeout': r[8] * 128.0 + r[9] * 0.5,
|
|
}
|
|
|
|
def get_config(display):
|
|
display.send_command(0x38, 0x00, [])
|
|
r = decode(display)
|
|
return r
|
|
|
|
def text_raw(display, page, row, text):
|
|
data = [display.ALIGN_LEFT, page, row, 0] + text
|
|
return display.send_command(0x11, 0x00, data, expect_response=False)
|
|
|
|
|
|
def charset():
|
|
lines = []
|
|
for i in range(0, 256, 16):
|
|
label = f"{i:03d}: "
|
|
b = list(label.encode("CP437"))
|
|
for j in range(i, i+16):
|
|
if j == 0:
|
|
b.append(0x20)
|
|
else:
|
|
b.append(j)
|
|
lines.append(b)
|
|
|
|
display.set_page(1)
|
|
|
|
while True:
|
|
for p in range(1,16):
|
|
for l in range(0,4):
|
|
text_raw(display, 1, l, lines[(p+l-1) % len(lines)])
|
|
sleep(5)
|
|
|
|
print("Opening serial port")
|
|
display = MIS1TextDisplay("/dev/ttyUSB0")
|
|
|
|
print("Sending text")
|
|
display.debug = True
|
|
#r = display.send_command(0x31, 0x00, []) # reset
|
|
#r = display.send_command(0x32, 0x01, []) # test
|
|
#r = display.send_command(0x38, 0x01, []) # read config
|
|
#r = display.read_response()
|
|
#print(f"Response: {r}")
|
|
#r = display.send_command(0x52, 0x01, []) # read config
|
|
#display.send_raw_telegram([0xff])
|
|
#display.send_raw_data([0x04, 0x81, 0x02, 0x03, 0x00])
|
|
#print(f"response: {display.read_response()}")
|
|
#r = reset_and_get_config(display)
|
|
r = get_config(display)
|
|
print(f"reply {len(r)}: {r}")
|
|
|
|
#display.simple_text(page=1, row=0, col=0, text="MEOW MEOW MEOW MEOW MEOW MEOW MEOW MEOW", align=display.ALIGN_CENTER)
|
|
#display.simple_text(page=1, row=1, col=0, text="MEOW MEOW MEOW MEOW MEOW MEOW MEOW MEOW", align=display.ALIGN_CENTER)
|
|
#display.simple_text(page=1, row=2, col=0, text="MEOW MEOW MEOW MEOW MEOW MEOW MEOW MEOW", align=display.ALIGN_CENTER)
|
|
#display.simple_text(page=1, row=3, col=0, text="MEOW MEOW MEOW MEOW MEOW MEOW MEOW MEOW", align=display.ALIGN_CENTER)
|
|
|
|
#display.simple_text(page=0, row=3, col=0, text="MEOW MEOW MEOW MEOW MEOW MEOW", align=display.ALIGN_CENTER)
|
|
|
|
#print("page 1")
|
|
#display.set_page(1)
|
|
#sleep(10)
|
|
|
|
#for l in range(0,4):
|
|
# display.simple_text(page=0, row=l, col=0, text="")
|
|
#print("page 0")
|
|
#display.set_page(0)
|
|
#sleep(10)
|
|
|
|
#print("page 1")
|
|
#display.set_page(1)
|
|
#sleep(10)
|
|
|
|
charset()
|
|
print("Thats all, folks!")
|