Reputation: 55
Im trying to print Greek characters to a Sunmi V2sPlus device in thermal InnerPrinter, I tried everything i found so far but no luck. Instead of Greek characters i print unknoun symbols. For this im using ESCPOS_NET and System.Text.Encoding.CodePages libraries. My code is:
try
{
using BluetoothSocket _socket = device.CreateRfcommSocketToServiceRecord(UUID.FromString("00001101-0000-1000-8000-00805f9b34fb"));
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); //instance property
await _socket.ConnectAsync();
switch (input)
{
case "LF":
_socket.OutputStream.WriteByte(0x0A);
break;
default:
var isoEncoding = Encoding.GetEncoding("ISO-8859-7"); //1253
var bytes = Encoding.Unicode.GetBytes(input);
byte[] message = Encoding.Convert(Encoding.Unicode, isoEncoding, bytes); //Encoding.UTF8.GetBytes(input) // CP737 ISO-8859-7
await _socket.OutputStream.WriteAsync(message, 0, message.Length);
_socket.OutputStream.WriteByte(0x0A);
}
_socket.Close();
}
catch (Exception)
{
throw;
}
Upvotes: 0
Views: 531
Reputation: 3897
From 2 minutes reading their documentation:
- How to select and set a character set. Background: the inbuilt printers are compatible with the transmission inaformofbinary byte stream, so a character set must be selected and set for the text tobeprintedwhich is sent in a form of byte code; multi-byte, GB18030 character encodingarethedefault device settings.
And some example:
To print CP866, please send: 0x1C 0x2E ——set it as the single-byte encoding type 0x1B 0x74 0x11 ——set it as the CP866 of the
You really should be working with documentations, when writing software for specific devices. Sometimes even if you think something works, you may be missing something important.
And good luck fixing bugs, after you release it.
Upvotes: 1