我正在编写C应用程序,需要使用rawprinterhelper将数据打印到pos star打印机。
我的印刷效果很好,除了我发送像_½___这样的字符。
然后我得到错误的数据打印出来。
到目前为止,我的研究给了我以下的结果。
如果我在PowerShell中打开良好的旧编辑并在TXT文件中写入我的字符(_½_)
把它送到打印机,我就可以随心所欲地打印出来。
我不能重复使用记事本
我如何用C编码我的刺,使其看起来像来自命令提示符(eidtor)的刺。所以
当我将数据发送到打印机时,它会像在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;
}
}
}