CatoLynx / pyLCD

A library for controlling LCDs on various hardware backends (successor of HD44780)
Other
26 stars 14 forks source link

IOError @ ks0108.py #3

Closed nickma82 closed 9 years ago

nickma82 commented 9 years ago

Hi, after running a modified version of glcd_countdown.py for over 24hours successfully, it ran into an exception.

...
[24.08. 23:44:31] root      -DEBUG main                    :93   2.37 seconds needed to redraw
Traceback (most recent call last):
  File "glcd_countdown.py", line 97, in <module>
  File "glcd_countdown.py", line 74, in main
  File "/usr/local/lib/python2.7/dist-packages/pylcd/ks0108.py", line 378, in text
  File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 218, in truetype
  File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 134, in __init__
IOError: cannot open resource

And my glcd_countdown.py:74-97 looks like the following:

74:                draw.text(nowPlusDelta.strftime("%H:%M"), ('center', 0, 56), 34, 20, font=const_default_font)
75:                draw.text(nowPlusDelta.strftime("%d.%m.%y"), ('center', 0, 56), 52, 12, font=const_default_font)
76:
77:                # fill the right box
78:                #draw.image("/home/pi/projects/pyLCD/ef20.png", 'left', 'top')
79:                draw.text("PV real: %s W" % nutDataHub.get_specific_var("pv2.input.power"), x=('center', 58, 127), y=1, size=9, font=const_default_font)
80:                draw.text("PV inp: %s W" % nutDataHub.get_specific_var("pv1.input.power"), x=('center', 58, 127), y=10, size=9, font=const_default_font)
81:                draw.text("Output: %s W" % nutDataHub.get_specific_var("output.power"), x=('center', 58, 127), y=19, size=9, font=const_default_font)
82:                draw.text("Batt: %s %%" % nutDataHub.get_specific_var("battery.charge"), x=('center', 58, 127), y=28, size=9, font=const_default_font)
83:                draw.text("Day: %s Wh" % nutDataHub.get_specific_var("energy.day"), x=('center', 58, 127), y=40, size=9, font=const_default_font)
84:
85:
86:                draw.line(56, 0, 56, 64)
87:                draw.line(57, 0, 57, 64)
88:                draw.line(0, 31, 57, 31)
89:                draw.line(0, 32, 57, 32)
90:
91:                display.commit()
92:                time_needed = (datetime.now() - now).total_seconds()
93:                logging.debug("%.2f seconds needed to redraw" % time_needed)
94:                sleep(7)
95:
96: if __name__ == "__main__":
97:         main()

Do you have any clue? Best

CatoLynx commented 9 years ago

Hi there! From what I can see, this isn't a bug in pyLCD. It looks like PIL couldn't open the file specified by const_default_font. Did something happen to the file? Does it work if you just restart the script? Maybe try letting it run for that long once more to see if it can be reproduced.

nickma82 commented 9 years ago

Hi, that seems plausible, the question is, is it worth fetching the exception @ks0108.py:378

const_default_font is defined as following const_default_font = "/home/pi/.fonts/truetype/arial.ttf", nothing happened to that file as far as I know. Restarting worked immediately...

I'm going to log the value of nowPlusDelta just before line 74, to be able to debug further problems like that one and let's see in a couple of hours then. Best

nickma82 commented 9 years ago

Ok, happened again... but it really seems to be an PIL/Imagefont problem. They ran into the same error, and it looks like the up to date code has built in checks to avoid that problem.

Sorry for posting it here. Best

CatoLynx commented 9 years ago

Okay, thank you for your reply.