Author Topic: Configuring printer to use default character set  (Read 11895 times)

polymorpher

  • Newbie
  • *
  • Posts: 17
Configuring printer to use default character set
« on: June 10, 2012, 04:07:30 am »
My friend has a Chinese restaurant, so all tickets needs to be printed in Chinese (for internal use). The POS printer can print Chinese characters flawlessly on notepad, but on SambaPOS it prints unreadable scribbles no matter what character set I use (tried 936, 850, 852, 0, 65001 and other character sets related to GB2312). Is it possible to let SambaPOS just use the default character set as used in notepad?

polymorpher

  • Newbie
  • *
  • Posts: 17
Re: Configuring printer to use default character set
« Reply #1 on: June 10, 2012, 06:08:30 am »
So I briefly looked into the source code. The default character set used in SambaPOS is 857 (Turkish). C# .Net Printing API is invoked in SerialPortService.cs (Samba.Services.SerialPortService) by

Code: [Select]
        public static void WritePort(string portName, string data)
        {
            WritePort(portName, Encoding.ASCII.GetBytes(data));
        }
and
Code: [Select]
        public static void WritePort(string portName, string data, int codePage)
        {
            WritePort(portName, Encoding.GetEncoding(codePage).GetBytes(data));
        }

The first one calls for ASCII encoding while the second one use specific code page. Since by default notepad saves everything in ANSI, I guess modifying the second function as follows will solve the problem:
Code: [Select]
        public static void WritePort(string portName, string data, int codePage)
        {
            WritePort(portName, codePage==0?Encoding.Default.GetBytes(data): Encoding.GetEncoding(codePage).GetBytes(data));
        }

Then set character set to 0 if one wants to use system default encoding. I will test it tomorrow.
« Last Edit: June 10, 2012, 06:10:45 am by polymorpher »

emre

  • SambaPOS Developer
  • Samba Team
  • Hero Member
  • *****
  • Posts: 1564
Re: Configuring printer to use default character set
« Reply #2 on: June 11, 2012, 06:18:34 am »
Hey Polymorpher, The part you are checking is used for sending data to ports so modifying it will make no change on printing. For printer we use similar implementation. If you search for LinePrinter class you'll find it. I'll be happy if you can help me on understanding if using default encoding will solve it or not..

Thanks

polymorpher

  • Newbie
  • *
  • Posts: 17
Re: Configuring printer to use default character set
« Reply #3 on: June 12, 2012, 05:52:17 am »
Thanks Emre. Here is the test result:

It looks like setting encoding to default does not help much in this situation. The problem is resolved by changing printer type to "Text" from "Ticket Printer". I suspect the problematic printer we had does not conform with some standard, because our kitchen printer works perfectly with its printer type set to "Tick Printer".

The same solution might apply to people who run into similar problems (i.e another language, special symbols, etc.).

However, providing an option to use default encoding does save people a lot of trouble to look for the correct character set.

emre

  • SambaPOS Developer
  • Samba Team
  • Hero Member
  • *****
  • Posts: 1564
Re: Configuring printer to use default character set
« Reply #4 on: June 12, 2012, 06:38:22 am »
polymorpher, thank you very much for the feedback. I'll try to simplify that as you suggested.