用pos打印机,用c#直接打印怎么做,请指教

haicsharp 2005-03-23 10:06:09
现在写一个餐馆点菜的小票打印,想直接写端口,不知从何下手,请高手指点
...全文
307 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
haicsharp 2005-03-28
  • 打赏
  • 举报
回复
谢谢 panzhu(panzhu)
panzhu 2005-03-26
  • 打赏
  • 举报
回复
调用方法:

LongRuan.POSPrinter prn = new LongRuan.POSPrinter("LPT1");
string str =prn.PrintLine("写端口测试!");
if(str !="")
MessageBox.Show(str);
panzhu 2005-03-26
  • 打赏
  • 举报
回复
我写了一个类,希望能帮到你

#region 声明

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 "";
}
}
}
}
haicsharp 2005-03-24
  • 打赏
  • 举报
回复
现在不知怎么会事,刚开始几行打印不出来,急!
corbet 2005-03-23
  • 打赏
  • 举报
回复
帮你顶上去!
lonelydreamsym 2005-03-23
  • 打赏
  • 举报
回复
up
dshj 2005-03-23
  • 打赏
  • 举报
回复
不会,帮你顶一下
nga96 2005-03-23
  • 打赏
  • 举报
回复
UP
心情解码 2005-03-23
  • 打赏
  • 举报
回复
:)







--
xxuu503 2005-03-23
  • 打赏
  • 举报
回复
搜索Justinio.cs(google)

或者是在csdn文档中心搜索串口类,有直接的串口类给你使!

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧