📜 ⬆️ ⬇️

We program currency symbols for customer display

I offer a small guide to those who, like Squier , author of the article Automation of a Store or how to compete with supermarkets , does automation in a store using free software. As a visual example, I will tell and show you how to connect the customer’s display to the Raspberry Pi to load currency symbols onto it for subsequent withdrawal during sales.




')

Connection


Unlike Windows, where drivers are needed, everything is simple in Linux, if you have a USB display, you just need to connect it to Raspberry Pi, after which the new device will be accessible via /dev/ttyUSB0 . In this case, the customer’s display acts as a slave device, and the control protocol programmed in the controller of the display itself is used to control and display information on the display screen. There are several different information transfer protocols for controlling the customer display, but all of them are de facto based on the Epson ESC / POS command format.

To get started, initialize the customer display by clearing the memory and the display screen with the ESC @ command:
 $ echo -n -e \\x1B\\x40 > /dev/ttyUSB0 

And standard check:
 $ echo -n -e Hello, world!\\n > /dev/ttyUSB0 

If done correctly, the line will be displayed.

Display


A VFD or LCD panel, usually containing 2 lines of 20 characters each, is used to display the customer’s displays. Each character, depending on the display model, may consist of a matrix from 5 * 7 to 8 * 8 dots. For this example, a display with a character size of 5 points horizontally and 7 points vertically is used.

Characters are encoded in the display ROM and are available for output in the range from 0x20 to 0xFF bytes. And if the range from 0x20 to 0x7F is the standard ANSI code page, then the range from 0x80 to 0xFF is allocated for additional code pages, for example, Cyrillic. To switch code pages, use the ESC tn command, where n is the code page number. Example:
 $ echo -n -e \\x1B\\x74\\x07 > /dev/ttyUSB0 $ echo -n -e \\x87\\xA4\\xE0\\xA0\\xA2\\xE1\\xE2\\xA2\\xE3\\xA9\\x2C\\x20\\x95\\xA0\\xA1\\xE0\\x21\\n > /dev/ttyUSB0 



Drawing


It is good if all the characters are already programmed into the displays, but very often, having bought a display in China, you have to face the fact that the ROM is completely filled with hieroglyphs, and there is no place left for Cyrillic. Then you can use the special command ESC & snm [a (p1..pa)]*mn to load the missing characters into the display RAM. This command is also suitable for us to load currency symbols into memory for subsequent display on sales. The command for programming the characters ESC & contains arguments that can be divided into two parts, the first is constant, the second is variable.

The constant part consists of three arguments s , n and m , where: s is the number of bytes in the row of the matrix characters, in our example, the value is 1; n - byte space in the code page for programming the first character; m - byte space for programming the last character, and if one character is programmed, then n=m .

The variable part consists of blocks a p1...pa , where the number of blocks depends on the number of programmable characters. Each block starts with a value, it is the number of vertical columns in the matrix of the symbol, in our example it can be in the range from 1 to 5. After the value of a , the status values ​​of the diodes of each are byte-encoded in p1 , p2 , p3 , p4 and p5 column of the matrix symbol, where the most significant bit is the top row of the diodes, and the least significant is the bottom one

This year, the symbol of the Russian ruble was officially included in Unicode (₽, code 20BD), but 5 years before this, the symbol of Kazakhstani tenge was adopted to me since November 1993 (₸, code 20B8). So let's start programming from it. If we present the tenge symbol in the form of a 5 * 8 by-bit matrix, then it will look like the one shown in the figure below. The upper line is supplemented by the high 8th bit, but in this example it will not be displayed.

In total, to replace the dollar symbols (code 0x26 in the table of symbols of our display) with the tenge symbol with the same code, we need the ESC / POS command of the following form:
 $ echo -n -e \\x1b\\x26\\x01\\x24\\x24\\x05\\x50\\x50\\x5f\\x50\\x50 > /dev/ttyUSB0 

Include loaded characters with the command ESC % n , where the value of n one or zero depending on whether the loaded characters are included or not:
 $ echo -n -e \\x1b\\x25\\x01 > /dev/ttyUSB0 

We check the work:
 $ echo -n -e 1500$ > /dev/ttyUSB0 

Result on the screen:


Programming


Now it remains to make automatic when connecting the initialization of the Cyrillic alphabet and the loading of the tenge symbol. To do this, we need to set the udev rules for automatically launching a bash script when connecting the customer display to the Raspberry Pi. The udevadm command udevadm vendor code and model of our display.
 $ udevadm info -q all -n /dev/ttyUSB0 | grep -E -i -w '.*VENDOR_ID.*|.*MODEL_ID.*' 

 E: ID_MODEL_ID=2303 E: ID_VENDOR_ID=067b 

Create rules 90-init-vfd-display.rules :
 $ sudo nano /etc/udev/rules.d/90-init-vfd-display.rules 

, of the following content:
 ACTION=="add", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", RUN+="/usr/local/bin/init-vfd-display.sh" 

and script:
 $ sudo nano /usr/local/bin/init-vfd-display.sh 

 #!/bin/bash sleep 20 echo -n -e \\x1B\\x40 > /dev/ttyUSB0 echo -n -e \\x1B\\x74\\x07 > /dev/ttyUSB0 echo -n -e \\x1B\\x26\\x01\\x24\\x24\\x05\\x50\\x50\\x5F\\x50\\x50 > /dev/ttyUSB0 sleep 3 

Make the bash script executable and activate our rules:
 $ sudo chmod +x /usr/local/bin/init-vfd-display.sh $ sudo udevadm control --reload-rules $ sudo udevadm trigger --action=add $ sudo service udev restart 

We try to simultaneously use the dollar and tenge symbol by switching them alternately.
 $ echo -n -e 1$ =\\x1B\\x25\\x01 181,95$ \\x1B\\x25\\x00 > /dev/ttyUSB0 



Conclusion


The example given here is not necessary to perform using Raspberry Pi, all the described commands are available independently of the Linux distribution, the main thing is the presence of the udev service in it to automatically execute the script loading the characters into the customer display. As a fixing material, I propose to program the symbols of two more currencies from the Unicode table, the Russian ruble and the Ukrainian hryvnia, according to the matrices in the figures, and you can already do the euro sign yourself.

Source: https://habr.com/ru/post/235105/


All Articles