将阿拉伯语字母发送到串口

时间:2015-04-12 09:34:20

标签: c#

我使用datamax打印机,我通过c#软件发送到串口,在标签上打印阿拉伯语

代码

    serialPort1.PortName = "COM1";
    serialPort1.BaudRate = 9600;
    serialPort1.Open();
    //serialPort1.Encoding = Encoding.GetEncoding("windows-1256");
    serialPort1.Encoding = Encoding.ASCII;
    serialPort1.Write("\x02" + "L" + "\x0D");
    serialPort1.Write("D12" + "\x0D");

    serialPort1.Write("H20" + "\x0D");
    string test_arab = "الحملله";
    serialPort1.Write("190000202600010  " + test_arab + "\x0D");//text
    //serialPort1.Write("B" + test_arab + "\x0D");
    serialPort1.Write("Q" + ' ' + test_arab + "\x0D");
    serialPort1.Write("E" + "\x0D");
    serialPort1.Close();

这样的标签结果“???????”

如何打印阿拉伯文,如“الحمدلله”

1 个答案:

答案 0 :(得分:-3)

您正在使用ASCII编码

serialPort1.Encoding = Encoding.ASCII;

C#文件的源代码是UTF-8。

因此,尝试将字符串转换为ascii,然后写入端口:

byte[] pass_byte = Encoding.ASCII.GetBytes("الحمد لله");