Cyrillic
denis660 opened this issue · comments
Thanks for the nice library.
There is one question.
How to send Russian characters for printing?
If you write a text in Russian, incomprehensible characters come out, apparently a conversion is needed.
Thats a good question. Could you check if its enough to set the character code table to cyrillic?
To do that execute the following command before you call p.Write():
p.WriteRaw([]byte{0x1B, 0x74, 0x11})
If it does not work, could you provide me with an example code snippet and your printer model number?
At the same time, this printer correctly prints Cyrillic from other programs
Sam4S ELLIX50D printer model
Test code
package main
import (
"github.com/hennedo/escpos"
"net"
)
func main() {
socket, err := net.Dial("tcp", "10.10.4.31:6001")
if err != nil {
println(err.Error())
}
defer socket.Close()
p := escpos.New(socket)
p.Size(2, 2).Write("TEST ROW 1")
p.LineFeed()
p.Size(2, 2).WriteRaw([]byte{0x1B, 0x74, 0x11})
p.LineFeed()
p.Size(2, 2).Write("TEST ROW 3")
p.LineFeed()
p.Size(2, 2).Write("TEST ROW 4")
p.LineFeed()
p.Size(2, 2).Write("TEST ROW 5")
p.LineFeed()
p.LineFeed()
p.LineFeed()
p.LineFeed()
p.LineFeed()
// You need to use either p.Print() or p.PrintAndCut() at the end to send the data to the printer.
p.PrintAndCut()
}
Any other suggestions on how to use the Russian text?
I will have time to dig deeper into this at the weekend.. Could you clarify one more thing, cause I am not that familiar with cyrillic.. In your example you used latin alphabet characters, do you expect them to get printed in cyrillic, or is it supposed to be cyrillic letters in the code -> cyrillic letters out of the printer?
I will have time to dig deeper into this at the weekend.. Could you clarify one more thing, cause I am not that familiar with cyrillic.. In your example you used latin alphabet characters, do you expect them to get printed in cyrillic, or is it supposed to be cyrillic letters in the code -> cyrillic letters out of the printer?
I inserted English words in the lines as an example, so that you could see exactly where the Cyrillic should be
I found another code like this on github
https://github.com/bamarni/escpos/blob/master/charset.go
Page 17 [PC866: Cyrillic #2]
Page 34 [PC855: Cyrillic]
Page 46 [WPC1251: Cyrillic]
Perhaps there is an answer to the application of the desired encoding, only the question of how to apply
As I found on the Internet, it is necessary to send in 866 encoding, but I could not check it
based on the link, I build a working solution, I will need to think about how to integrate it elegantly in the library but you could use this code for now:
package main
import (
"github.com/hennedo/escpos"
"golang.org/x/text/encoding/charmap"
"net"
)
func main() {
socket, err := net.Dial("tcp", "192.168.8.41:9100")
if err != nil {
println(err.Error())
}
defer socket.Close()
p := escpos.New(socket)
p.Size(2, 2).WriteRaw([]byte{0x1B, 0x74, 0x11})
p.LineFeed()
enc := charmap.CodePage866.NewEncoder()
a, e := enc.String("ТЕСТОВЫЙ РЯД 3") // thanks google translate
if e != nil {
println(e)
}
p.Size(2, 2).Write(a)
p.LineFeed()
// You need to use either p.Print() or p.PrintAndCut() at the end to send the data to the printer.
p.PrintAndCut()
}
This works at least for my EPSON TM 20II
This is just wonderful! Everything works and is displayed correctly. You may need to add this to your README.
Thank you very much!