我在写C#应用程序,需要使用RawPrinterHelper将数据打印到POS STAR打印机。如何在C#中编辑类似编辑的字符串?
我的打印效果很好,除非我发送像ŽĆČĐŠ这样的字符。 然后我得到打印出来的错误数据。
直到现在我的研究给了我以下结果。
如果我在PowerShell中开好老编辑和TXT文件写我的文字(ŽĆČĐŠ) 并发送至打印机,我得到打印出来,因为我想
我不能使用记事本
是重复我如何在C#中编写我的sting从命令提示符(EIDTor)看起来像那样。因此,当我发送数据到打印机时,它打印Desire字体,就像它在Windows环境中看起来一样。
我也尝试使用Star驱动程序及其C#示例将数据直接发送到打印机,但没有成功。
编辑:
我做到了,和其他人在一般的麻烦,直接使用C# 星打印机进行打印这里是示例应用程序代码Star IO Programming Tool使用他们的司机。
using System;
using System.Text;
using StarMicronics.StarIO; // added as a reference from the "Dependencies" directory
// requires StarIOPort.dll, which is copied to the output directory by the Post-Build event
namespace TestEnkodera
{
class Program
{
static void Main(string[] args)
{
string portName = "LPT1";
string portSettings = string.Empty;
string print = string.Empty;
//Select code page
//Decimal 27 29 116 n
print += string.Format("{0}{1}{2}{3}{4}", (char)27, (char)29, (char)116, (char)5, Environment.NewLine);
print += "Đ Š Ž Ć Č ž ć č ć \n";
IPort port = null;
port = StarMicronics.StarIO.Factory.I.GetPort(portName, portSettings, 10 * 1000);
//byte[] command = ASCIIEncoding.ASCII.GetBytes(print); //This was orginal code provided by STAR
Encoding ec = Encoding.GetEncoding(852); //Here is way to set CODEPAGE to match with printer CODE PAGE
byte[] command = ec.GetBytes(print);
uint totalSizeCommunicated = WritePortHelper(port, command);
StarMicronics.StarIO.Factory.I.ReleasePort(port);
Console.ReadKey();
}
private static uint WritePortHelper(IPort port, byte[] writeBuffer)
{
uint zeroProgressOccurances = 0;
uint totalSizeCommunicated = 0;
while ((totalSizeCommunicated < writeBuffer.Length) && (zeroProgressOccurances < 2)) // adjust zeroProgressOccurances as needed
{
uint sizeCommunicated = port.WritePort(writeBuffer, totalSizeCommunicated, (uint)writeBuffer.Length - totalSizeCommunicated);
if (sizeCommunicated == 0)
{
zeroProgressOccurances++;
}
else
{
totalSizeCommunicated += sizeCommunicated;
zeroProgressOccurances = 0;
}
}
return totalSizeCommunicated;
}
}
}
这听起来像编码的文本编辑器采用的是与打印机使用的相同。您的编辑器是否指示正在使用哪种编码? – Kurt 2010-06-24 08:17:47
@Kurt我在命令提示符中使用编辑器,因为它在MS DOS中。蓝色的一个没有鼠标,我认为我不知道它使用哪种编码 – adopilot 2010-06-24 08:22:22
尝试在记事本中打开该文件。做一个“另存为”,看看它保存了什么编码?我猜测它会是ASCII码,你的C#代码试图用Unicode编码(UTF-8/16)。 – shahkalpesh 2010-06-24 08:36:22