Hello! Need your help

4 days already as I try to print the text in Russian but everything is even. The printer uses the ESC / POS protocol. Works through the comport. With a grief in half, I found a wrapper class for the comport and learned how to send commands. And everything would be fine, but as soon as it came to the Russian language - the work got up. After rereading the protocol, I came across the "Set charecter code table" command, which makes it possible to choose encodings in the printer itself for the correct display of languages. One of the parameters was the PC866 encoding, which points to the Cyrillic alphabet. When this coding was connected, the Russian should have earned it, but krakozabliki appeared again on the print. Having opened the table CP866 I saw that these cracks are part of the table. Taking the codes of letters from this table and sending them to print, I still got the Russian language. And if we take and compare the codes, for example, the letters' A ', then the difference between them will be - 64. (code' A 'C ++ = 192,' A'CP866 = 128). Interestingly, when using CP866 encoding for the console (setConsoleCP, setConsoleCPOut), normal Russian text is displayed, and when outputting to the printer, we get short-curved text.

Tell me, maybe you need to somehow process the text? Why don't the encodings match?

    2 answers 2

    The code table used "in C ++" is determined by the encoding of the source files. Most likely, Visual Studio saves these files using Windows 1251 . Consequently:

    • or tell Visual Studio to use CP866 encoding,
    • or tell the printer to use Windows 1251.
    • I did some tests and it turned out that the console still displays 866, not 1251. From this it follows that the supplied text is still encoded in 1251. Unfortunately, the printer has only 866. Therefore, the task now is to convect 1251 to 866. Already created a topic for this. if you can help, connect. ru.stackoverflow.com/questions/534821/c-utf-8-%D0%B2-cp866 - Madisson

    Just after main () write setlocale (LC_ALL, "Russian");