You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.1 KiB

  1. #! /usr/bin/python
  2. # -*- encoding: utf-8 -*-
  3. # Author : Alexis de Lattre <alexis.delattre@akretion.com>
  4. # The licence is in the file __openerp__.py
  5. # This is a test script, that you can use if you want to test/play
  6. # with the customer display independantly from the Odoo server
  7. # It has been tested with a Bixolon BCD-1100
  8. import sys
  9. import logging
  10. _logger = logging.getLogger(__name__)
  11. try:
  12. from serial import Serial
  13. from unidecode import unidecode
  14. except (ImportError, IOError) as err:
  15. _logger.debug(err)
  16. DEVICE = '/dev/ttyUSB0'
  17. DEVICE_RATE = 9600
  18. DEVICE_COLS = 20
  19. def display_text(ser, line1, line2):
  20. print "convert to ascii"
  21. line1 = unidecode(line1)
  22. line2 = unidecode(line2)
  23. print "set lines to the right lenght (%s)" % DEVICE_COLS
  24. for line in [line1, line2]:
  25. if len(line) < DEVICE_COLS:
  26. line += ' ' * (DEVICE_COLS - len(line))
  27. elif len(line) > DEVICE_COLS:
  28. line = line[0:DEVICE_COLS]
  29. assert len(line) == DEVICE_COLS, 'Wrong length'
  30. print "try to clear display"
  31. ser.write('\x0C')
  32. print "clear done"
  33. print "try to position at start of 1st line"
  34. ser.write('\x1B\x6C' + chr(1) + chr(1))
  35. print "position done"
  36. print "try to write 1st line"
  37. ser.write(line1)
  38. print "write 1st line done"
  39. print "try to position at start of 2nd line"
  40. ser.write('\x1B\x6C' + chr(1) + chr(2))
  41. print "position done"
  42. print "try to write 2nd line"
  43. ser.write(line2)
  44. print "write done"
  45. def open_close_display(line1, line2):
  46. ser = False
  47. try:
  48. print "open serial port"
  49. ser = Serial(DEVICE, DEVICE_RATE, timeout=2)
  50. print "serial port open =", ser.isOpen()
  51. print "try to set cursor to off"
  52. ser.write('\x1F\x43\x00')
  53. print "cursor set to off"
  54. display_text(ser, line1, line2)
  55. except Exception, e:
  56. print "EXCEPTION e=", e
  57. sys.exit(1)
  58. finally:
  59. if ser:
  60. print "close serial port"
  61. ser.close()
  62. if __name__ == '__main__':
  63. line1 = u'POS Code Sprint'
  64. line2 = u'@ Akretion 2014/07'
  65. open_close_display(line1, line2)