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.

68 lines
2.0 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. from serial import Serial
  9. from unidecode import unidecode
  10. import sys
  11. DEVICE = '/dev/ttyUSB0'
  12. DEVICE_RATE = 9600
  13. DEVICE_COLS = 20
  14. def display_text(ser, line1, line2):
  15. print "convert to ascii"
  16. line1 = unidecode(line1)
  17. line2 = unidecode(line2)
  18. print "set lines to the right lenght (%s)" % DEVICE_COLS
  19. for line in [line1, line2]:
  20. if len(line) < DEVICE_COLS:
  21. line += ' ' * (DEVICE_COLS - len(line))
  22. elif len(line) > DEVICE_COLS:
  23. line = line[0:DEVICE_COLS]
  24. assert len(line) == DEVICE_COLS, 'Wrong length'
  25. print "try to clear display"
  26. ser.write('\x0C')
  27. print "clear done"
  28. print "try to position at start of 1st line"
  29. ser.write('\x1B\x6C' + chr(1) + chr(1))
  30. print "position done"
  31. print "try to write 1st line"
  32. ser.write(line1)
  33. print "write 1st line done"
  34. print "try to position at start of 2nd line"
  35. ser.write('\x1B\x6C' + chr(1) + chr(2))
  36. print "position done"
  37. print "try to write 2nd line"
  38. ser.write(line2)
  39. print "write done"
  40. def open_close_display(line1, line2):
  41. ser = False
  42. try:
  43. print "open serial port"
  44. ser = Serial(DEVICE, DEVICE_RATE, timeout=2)
  45. print "serial port open =", ser.isOpen()
  46. print "try to set cursor to off"
  47. ser.write('\x1F\x43\x00')
  48. print "cursor set to off"
  49. display_text(ser, line1, line2)
  50. except Exception, e:
  51. print "EXCEPTION e=", e
  52. sys.exit(1)
  53. finally:
  54. if ser:
  55. print "close serial port"
  56. ser.close()
  57. if __name__ == '__main__':
  58. line1 = u'POS Code Sprint'
  59. line2 = u'@ Akretion 2014/07'
  60. open_close_display(line1, line2)