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.

80 lines
2.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Author : Alexis de Lattre <alexis.delattre@akretion.com>
  3. # The licence is in the file __manifest__.py
  4. # This is a test script, that you can use if you want to test/play
  5. # with the customer display independantly from the Odoo server
  6. # It has been tested with a Bixolon BCD-1100
  7. import sys
  8. import logging
  9. import time
  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/bixolon'
  17. DEVICE_RATE = 9600
  18. DEVICE_COLS = 20
  19. CLEAR_DISPLAY = b'\x0C'
  20. MOVE_CURSOR_TO = b'\x1B\x6C'
  21. CURSOR_OFF = b'\x1F\x43\x00'
  22. def display_text(ser, line1, line2):
  23. print(("set lines to the right length (%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(CLEAR_DISPLAY)
  32. print("clear done")
  33. print("try to position at start of 1st line")
  34. l1 = MOVE_CURSOR_TO + chr(1).encode('ascii') + chr(1).encode('ascii')
  35. ser.write(l1)
  36. print("position done")
  37. print("try to write 1st line")
  38. ser.write(unidecode(line1).encode('ascii'))
  39. print("write 1st line done")
  40. time.sleep(1)
  41. print("try to position at start of 2nd line")
  42. l2 = MOVE_CURSOR_TO + chr(1).encode('ascii') + chr(2).encode('ascii')
  43. ser.write(l2)
  44. print("position done")
  45. print("try to write 2nd line")
  46. ser.write(unidecode(line2).encode('ascii'))
  47. print("write done")
  48. def open_close_display(line1, line2):
  49. ser = False
  50. try:
  51. print("open serial port")
  52. ser = Serial(DEVICE, DEVICE_RATE, timeout=2)
  53. print(("serial port open =", ser.isOpen()))
  54. print(("serial name =", ser.name))
  55. print("try to set cursor to off")
  56. ser.write(CURSOR_OFF)
  57. print("cursor set to off")
  58. display_text(ser, line1, line2)
  59. except Exception as e:
  60. print(('EXCEPTION e={}'.format(e)))
  61. sys.exit(1)
  62. finally:
  63. if ser:
  64. print("close serial port")
  65. ser.close()
  66. if __name__ == '__main__':
  67. line1 = 'Coop IT Easy'
  68. line2 = 'Migration to 12.0'
  69. open_close_display(line1, line2)