现在在用C#做一个POS系统,涉及到小票打印部分,在网上搜了一下,资料不多,而且都是基于热敏打印的,我不知道针式打印的方法和热敏打印的程序实现是否一样,如果不一样,怎么处理呢?
解决方案 »
- C#对MAPGIS做二次开发,怎样将当前地图导出为图像文件
- PostMessage函数问题.
- winfroms 中报表绑定两个存储过程 在代码中怎么写DATASET 绑定
- 问一下cpu超频后在“我的电脑”右键能看见cpu的变化吗?
- 晕倒,两个库有没有办法做交叉查询的?
- 有没有工具可以修改编译好的.exe文件内的内容?
- 要做个网络故障管理系统,请教C#网络编程的书推荐!!!!
- 请教。如何将普通dataset赋值给强类型dataset!
- 请问C#中有没有延时函数??????????????
- 准备去北大方正面试,有知道那边情况的吗?方正的面试都考什么呢?要注意什么?
- 关于POS机打印,小票打印问题
- 关于XMPP协议
using System;
using System.Runtime.InteropServices;
using System.IO;
#endregion
namespace LongRuan
{
/// <summary>
/// POSPrinter 的摘要说明。
/// </summary>
public class POSPrinter
{
const int OPEN_EXISTING = 3;
string prnPort ="LPT1";
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
private static extern IntPtr CreateFile(string lpFileName,
int dwDesiredAccess,
int dwShareMode,
int lpSecurityAttributes,
int dwCreationDisposition ,
int dwFlagsAndAttributes ,
int hTemplateFile);
public POSPrinter()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public POSPrinter(string prnPort)
{
this.prnPort=prnPort;//打印机端口
}
public string PrintLine(string str)
{
IntPtr iHandle = CreateFile(prnPort, 0x40000000, 0, 0, OPEN_EXISTING, 0, 0);
if(iHandle.ToInt32() == -1)
{
return "没有连接打印机或者打印机端口不是LPT1";
}
else
{
FileStream fs = new FileStream(iHandle, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default); //写数据
sw.WriteLine(str);
//开钱箱
//sw.WriteLine(Chr(&H1B) & Chr(70) & Chr(0) & Chr(20) & Chr(&HA0))
sw.Close();
fs.Close();
return "";
}
}
}
}--------------------------------------------------------------------------------
调用方法:
LongRuan.POSPrinter prn = new LongRuan.POSPrinter("LPT1");
string str =prn.PrintLine("写端口测试!");
if(str !="")
MessageBox.Show(str);
using System;
using System.Runtime.InteropServices;
using System.IO;
#endregion
namespace LongRuan
{
/// <summary>
/// POSPrinter 的摘要说明。
/// </summary>
public class POSPrinter
{
const int OPEN_EXISTING = 3;
string prnPort ="LPT1";
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
private static extern IntPtr CreateFile(string lpFileName,
int dwDesiredAccess,
int dwShareMode,
int lpSecurityAttributes,
int dwCreationDisposition ,
int dwFlagsAndAttributes ,
int hTemplateFile);
public POSPrinter()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public POSPrinter(string prnPort)
{
this.prnPort=prnPort;//打印机端口
}
public string PrintLine(string str)
{
IntPtr iHandle = CreateFile(prnPort, 0x40000000, 0, 0, OPEN_EXISTING, 0, 0);
if(iHandle.ToInt32() == -1)
{
return "没有连接打印机或者打印机端口不是LPT1";
}
else
{
FileStream fs = new FileStream(iHandle, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default); //写数据
sw.WriteLine(str);
//开钱箱
//sw.WriteLine(Chr(&H1B) & Chr(70) & Chr(0) & Chr(20) & Chr(&HA0))
sw.Close();
fs.Close();
return "";
}
}
}
}--------------------------------------------------------------------------------
调用方法:
LongRuan.POSPrinter prn = new LongRuan.POSPrinter("LPT1");
string str =prn.PrintLine("写端口测试!");
if(str !="")
MessageBox.Show(str);