c# 调用条码打印机

mister55 2009-07-07 06:03:36
加精
c# 怎样调用条码打印机进行打印条码?
...全文
3576 94 打赏 收藏 转发到动态 举报
写回复
用AI写文章
94 条回复
切换为时间正序
请发表友善的回复…
发表回复
fenglong_wang 2011-07-08
  • 打赏
  • 举报
回复
mark 学习了 谢谢
努力学飞的鸟 2011-07-07
  • 打赏
  • 举报
回复
看来打印这块不容易啊!
CraxyMouse 2011-05-14
  • 打赏
  • 举报
回复
我写的E-LABEL 装上驱动,通杀所有打印机
http://www.ync-tech.com
NageQD 2011-03-31
  • 打赏
  • 举报
回复
好好好,正在使试用中
JN1234A 2011-02-17
  • 打赏
  • 举报
回复
请问我用的是TEC条码打印机.B-452-HS 但我向厂商要打印接口API时.给了我一个什么指令集!没有介绍接口方法的.
sxmonsy 2010-11-29
  • 打赏
  • 举报
回复
嗯,这个不错。
trilcc 2010-09-07
  • 打赏
  • 举报
回复
谢了,最近有个项目正需要这东东,、
gaara777 2010-08-17
  • 打赏
  • 举报
回复
using System.Linq;
youyoulyy11 2010-08-04
  • 打赏
  • 举报
回复
学习了
zkcharge 2010-05-25
  • 打赏
  • 举报
回复
学习学习 太好了 三个例子呢
蹊跷路人 2010-04-25
  • 打赏
  • 举报
回复
学习,马上要用到的~!!
wellforever 2010-02-02
  • 打赏
  • 举报
回复
需要对应打印机的指令来排版和生成条码
flcat2003 2010-01-30
  • 打赏
  • 举报
回复
这个是高科技啊!
lianyi68 2010-01-29
  • 打赏
  • 举报
回复
learning
messi_yang 2009-12-31
  • 打赏
  • 举报
回复
來學習哈。
wddpxqq 2009-12-01
  • 打赏
  • 举报
回复
要是条码打印机不安装驱动的话就是所谓的命令打印是吧?
我现在就是要这样啊!往lpt1口灌数据过去就行了吗?
怎么灌

#region 引用 WindowsAPI

//引用API声明
[StructLayout(LayoutKind.Sequential)]
private struct OVERLAPPED
{
int Internal;
int InternalHigh;
int Offset;
int OffSetHigh;
int hEvent;
}

[DllImport("Kernel32.dll")]
static extern IntPtr CreateFile
(
string filename,
[MarshalAs(UnmanagedType.U4)]FileAccess fileaccess,
[MarshalAs(UnmanagedType.U4)]FileShare fileshare,
int securityattributes,
[MarshalAs(UnmanagedType.U4)]FileMode creationdisposition,
int flags,
IntPtr templat
);


[DllImport("kernel32.dll",SetLastError=true)]
private static extern bool WriteFile
(
int hFile,
byte[] lpBuffer,
int nNumberOfBytesToWrite,
out int lpNumberOfBytesWritten,
out OVERLAPPED lpOverlapped
);

[DllImport("Kernel32.dll")]
static extern bool CloseHandle(IntPtr hObject);
#endregion
//C#LPT端口打印类的操作
public IntPtr iHandle;


public string WritetoLpt(string prnPort, string BarCode)
{
SafeFileHandle sfh = null;

IntPtr iHandle = CreateFile(prnPort, FileAccess.ReadWrite, FileShare.ReadWrite, 0, FileMode.OpenOrCreate, 0, IntPtr.Zero);

if (iHandle.ToInt32() == -1)
{
return "Faile To printer";
}
else
{
//OVERLAPPED x = new OVERLAPPED();
//int i = 0;
//byte[] mystring = System.Text.Encoding.Default.GetBytes(BarCode);
//WriteFile(iHandle, mystring, mystring.Length, ref i, ref x);

sfh = new SafeFileHandle(iHandle, true);
FileStream fs = new FileStream(sfh, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);
sw.Write(BarCode);
sw.Flush();//运行到这里的时候就卡住很长一段时间,然后会有个“设备未连接”的错误
fs.Flush();
sw.Close();
fs.Close();
CloseHandle(iHandle);
return "";
}
}
paul9137 2009-11-21
  • 打赏
  • 举报
回复
顶起来,标记学习
snake_h 2009-09-18
  • 打赏
  • 举报
回复
关注中。。。
l13873666736 2009-07-13
  • 打赏
  • 举报
回复
你先下个BARONE5看看再说
kingmax54212008 2009-07-12
  • 打赏
  • 举报
回复
Mark
加载更多回复(66)

110,545

社区成员

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

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

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